From 147cf3c2746af811a1434afa2e7336b1de5d4f93 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Tue, 18 Sep 2012 12:27:25 +0200 Subject: [PATCH] feature #1353: Add colours to the state columns --- src/cli/cli_helper.rb | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/cli/cli_helper.rb b/src/cli/cli_helper.rb index 67b40ce6fc..d13cf04112 100644 --- a/src/cli/cli_helper.rb +++ b/src/cli/cli_helper.rb @@ -82,6 +82,32 @@ module CLIHelper print "\33[#{x};#{y}H" end + def CLIHelper.scr_red + print "\33[31m" + end + + def CLIHelper.scr_green + print "\33[32m" + end + + ANSI_RED="\33[31m" + ANSI_GREEN="\33[32m" + ANSI_RESET="\33[0m" + + OK_STATES=%w{runn rdy on} + BAD_STATES=%w{fail err err} + + def CLIHelper.color_state(stat) + case stat.strip + when *OK_STATES + ANSI_GREEN+stat+ANSI_RESET + when *BAD_STATES + ANSI_RED+stat+ANSI_RESET + else + stat + end + end + # Print header def CLIHelper.print_header(str, underline=true) if $stdout.tty? @@ -177,12 +203,21 @@ module CLIHelper ncolumns=@default_columns.length res_data=data_array(data, options) + if options[:stat_column] + stat_column=@default_columns.index( + options[:stat_column].upcase.to_sym) + else + stat_column=@default_columns.index(:STAT) + end + begin print res_data.collect{|l| (0..ncolumns-1).collect{ |i| dat=l[i] col=@default_columns[i] - format_str(col, dat) + + str=format_str(col, dat) + CLIHelper.color_state(str) if i=stat_column }.join(' ') }.join("\n") rescue Errno::EPIPE