File Exchange

image thumbnail

tcprintf : ANSI colored output in terminal

version 1.0 (161 KB) by

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

3 Downloads

Updated

View License

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

Comments and Ratings (3)

Vincent

perfect! exactly what I was looking for.

Yair Altman

Yair Altman (view profile)

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

Yair Altman

Yair Altman (view profile)

MATLAB Release
MATLAB 7.13 (R2011b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today