Skip to content

Commit 9ea0e02

Browse files
committed
⚡ Shorten output of get_ps1()
1 parent 02794af commit 9ea0e02

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

inst/get_ps1.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
%% @example
99
%% @group
1010
%% get_ps1('$ ', '%s', @{'black', 'white', 'a'@}, '', ' %s', @{'white', 'blue', 'b'@}, '', ' %s ', @{'green', 'red', 'c'@}, '')
11-
%% @result{} ans = \e[30;47ma\e[37;44m\e[37;44m b\e[34;41m\e[32;41m c \e[0;31m\e[0m$
11+
%% @result{} ans = \e[30;47ma\e[37;44m\e[37m b\e[34;41m\e[32m c \e[0;31m\e[0m$
1212
%% @end group
1313
%% @end example
1414
%%
@@ -51,10 +51,11 @@
5151
fg = convert_ansi_color(section{1});
5252
bg = convert_ansi_color(section{2});
5353
txt = sprintf(format, section{3});
54-
if ~strcmp(last_bg, '')
55-
ps = [ps, tput('setaf', last_bg, 'setab', bg), sep];
54+
if strcmp(last_bg, '')
55+
ps = [ps, tput('setaf', fg, 'setab', bg), txt];
56+
else
57+
ps = [ps, tput('setaf', last_bg, 'setab', bg), sep, tput('setaf', fg), txt];
5658
end
57-
ps = [ps, tput('setaf', fg, 'setab', bg), txt];
5859
last_bg = bg;
5960
end
6061
ps = [ps, tput('reset', 'setaf', last_bg), sep, tput('reset'), prompt_string];
@@ -63,4 +64,4 @@
6364

6465
%!test
6566
%! get_ps1('$ ', '%s', {'black', 'white', 'a'}, '', ' %s', {'white', 'blue', 'b'}, '', ' %s ', {'green', 'red', 'c'}, '');
66-
%! assert(ans, '\e[30;47ma\e[37;44m\e[37;44m b\e[34;41m\e[32;41m c \e[0;31m\e[0m$ ')
67+
%! assert(ans, '\e[30;47ma\e[37;44m\e[37m b\e[34;41m\e[32m c \e[0;31m\e[0m$ ')

0 commit comments

Comments
 (0)