From 34c404e069644336325fb568860cb8248d054089 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 17 Feb 2014 17:36:50 +0100 Subject: [PATCH] Test: colorstr moved to util.tcl. --- tests/support/test.tcl | 30 ------------------------------ tests/support/util.tcl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/support/test.tcl b/tests/support/test.tcl index 480c674e0..96b529d7a 100644 --- a/tests/support/test.tcl +++ b/tests/support/test.tcl @@ -61,36 +61,6 @@ proc wait_for_condition {maxtries delay e _else_ elsescript} { } } -# Test if TERM looks like to support colors -proc color_term {} { - expr {[info exists ::env(TERM)] && [string match *xterm* $::env(TERM)]} -} - -proc colorstr {color str} { - if {[color_term]} { - set b 0 - if {[string range $color 0 4] eq {bold-}} { - set b 1 - set color [string range $color 5 end] - } - switch $color { - red {set colorcode {31}} - green {set colorcode {32}} - yellow {set colorcode {33}} - blue {set colorcode {34}} - magenta {set colorcode {35}} - cyan {set colorcode {36}} - white {set colorcode {37}} - default {set colorcode {37}} - } - if {$colorcode ne {}} { - return "\033\[$b;${colorcode};40m$str\033\[0m" - } - } else { - return $str - } -} - proc test {name code {okpattern undefined}} { # abort if tagged with a tag to deny foreach tag $::denytags { diff --git a/tests/support/util.tcl b/tests/support/util.tcl index 3804f253b..e49ea229c 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -327,3 +327,33 @@ proc find_available_port start { error "Can't find a non busy port in the $start-[expr {$start+1023}] range." } } + +# Test if TERM looks like to support colors +proc color_term {} { + expr {[info exists ::env(TERM)] && [string match *xterm* $::env(TERM)]} +} + +proc colorstr {color str} { + if {[color_term]} { + set b 0 + if {[string range $color 0 4] eq {bold-}} { + set b 1 + set color [string range $color 5 end] + } + switch $color { + red {set colorcode {31}} + green {set colorcode {32}} + yellow {set colorcode {33}} + blue {set colorcode {34}} + magenta {set colorcode {35}} + cyan {set colorcode {36}} + white {set colorcode {37}} + default {set colorcode {37}} + } + if {$colorcode ne {}} { + return "\033\[$b;${colorcode};40m$str\033\[0m" + } + } else { + return $str + } +}