1% Display a message in a color (without a newline).
2%
3% colormsg(msg,color)
4%
5% The message msg in printed on the terminal the specified color. Acceptable
6% values color color are:
7%   black
8%   red
9%   green
10%   yellow
11%   blue
12%   magenta
13%   cyan
14%   white
15%
16% In Matlab the message is displayed in black (due to the lack of ANSI escape
17% code support).
18%
19% See also
20%   colordisp
21
22function colormsg (msg,color)
23
24%getenv('TERM')
25%if strcmp(getenv('TERM'),'xterm') % && exist('puts') > 1
26% only in octave
27if exist('puts') > 1
28  esc = char(27);
29
30  % ANSI escape codes
31  colors.black   = [esc, '[40m'];
32  colors.red     = [esc, '[41m'];
33  colors.green   = [esc, '[42m'];
34  colors.yellow  = [esc, '[43m'];
35  colors.blue    = [esc, '[44m'];
36  colors.magenta = [esc, '[45m'];
37  colors.cyan    = [esc, '[46m'];
38  colors.white   = [esc, '[47m'];
39
40  reset = [esc, '[0m'];
41
42  c = getfield(colors,color);
43
44  %oldpso = page_screen_output (0);
45
46  try
47    fprintf([c, msg, reset]);
48    %puts (reset); % reset terminal
49  catch
50    %page_screen_output (oldpso);
51  end
52else
53  fprintf(msg);
54end
55
56
57
58% Copyright (C) 2004 Alexander Barth <a.barth@ulg.ac.be>
59%
60% This program is free software; you can redistribute it and/or modify it under
61% the terms of the GNU General Public License as published by the Free Software
62% Foundation; either version 2 of the License, or (at your option) any later
63% version.
64%
65% This program is distributed in the hope that it will be useful, but WITHOUT
66% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
68% details.
69%
70% You should have received a copy of the GNU General Public License along with
71% this program; if not, see <http://www.gnu.org/licenses/>.
72