5.0

5.0 | 2 ratings Rate this file 22 Downloads (last 30 days) File Size: 161 KB File ID: #38252
image thumbnail

tcprintf : ANSI colored output in terminal

by

 

tcprintf provides colored output when using MATLAB from a terminal using ANSI escape codes.

| Watch this File

File Information
Description

Uses ANSI escape codes to print colored output when using MATLAB
from a terminal. If not running in a terminal, or if called by MATLAB's
datatipinfo function, tcprintf reverts to standard printf. The latter is
desirable if tcprintf is used within an object's disp() method to avoid
seeing the ANSI characters here.

The first argument is an style description that consists of space-separated
words. These words may include:

    one of the following colors:
    black, red, green, yellow, blue, purple, cyan, darkGray, lightGray, white

one of the following background colors:
    onBlack, onRed, onGreen, onYellow, onBlue, onPurple, onCyan, onWhite

and any of the following modifiers:
    bright : use the bright (or bold) form of the color, not applicable for
        black, darkGray, lightGray, or white
    underline : draw an underline under each character
    blink : This is a mistake. Please don't use this ever.

Example:
    tcprintf('lightGray onRed underline', 'Message: %20s\n', msg);

Author: Dan O'Shea (http://djoshea.com) (c) 2012

Released under the open source BSD license
http://opensource.org/licenses/bsd-license.php

Acknowledgements

Cprintf Display Formatted Colored Text In The Command Window inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
23 Jan 2013 Vincent

perfect! exactly what I was looking for.

20 Sep 2012 Yair Altman

Very nice idea and implementation. I liked the blink [counter-]suggestion :-)

A few ideas for improvement:
- make the inputs case-insensitive
- revert to cprintf (if available) in case of usejava('desktop') and not datatip
- use the full 256 color indices use by xterm for fg,bg colors (ANSI codes 38,48 respectively); KDE's Konsole even supports full RGB here
- codes 35,45 are often called magenta, not purple; I suggest that you accept both of these as synonyms to this code
- similarly, 33,43 are displayed as brown on VGA monitors, so I suggest accepting "brown" as a synonym

20 Sep 2012 Yair Altman  

Contact us