cmdr
Check-in [509f2d765f]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed varname typo in the error handling for escape code definitions. Plus extension of the general colorization command to allow use without a text. This simply returns the control characters.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 509f2d765fb5e84130813739a57bb717c44468ae
User & Date: andreask 2014-08-15 23:58:08
Context
2014-08-21
01:49
Fix handling of *all*. Ignoring a missing definition is ok. Ignoring all other specification errors it may generate is not. check-in: 9159f68bc3 user: andreask tags: trunk
01:29
Started implementation of "global" options (and state) associated with officers and inherited to subordinates. Another way of sharing common options (like --debug, --trace, and the like) without cluttering command definitions via *all*. This commit has the specification changes done. Not yet done are recognition during cmdline processing, nor the needed changes to get uncluttered help output, nor the extended help output for officers. check-in: d1d45c1de3 user: andreask tags: global-options
2014-08-15
23:58
Fixed varname typo in the error handling for escape code definitions. Plus extension of the general colorization command to allow use without a text. This simply returns the control characters. check-in: 509f2d765f user: andreask tags: trunk
17:55
Fix left-over oops. check-in: 6e34f0dec4 user: aku tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to color.tcl.

   158    158   	    return
   159    159   	}
   160    160       }
   161    161   
   162    162       if {[regexp {^[eE](.*)$} $spec -> codes]} {
   163    163   	if {![regexp {^(\d+)(,\d+)*$} $codes]} {
   164    164   	    return -code error \
   165         -		-errorcode [list CMDR COLOR BAD-ESCAPE SYNTAX $rgb] \
          165  +		-errorcode [list CMDR COLOR BAD-ESCAPE SYNTAX $spec] \
   166    166   		"Expected a comma-separated list of codes, got \"$spec\""
   167    167   	}
   168    168   	set codes [Code {*}[split $codes ,]]
   169    169   	debug.cmdr/color {ESC encoded => [Quote $codes]}
   170    170   	dict set def  $name $spec
   171    171   	dict set char $name $codes
   172    172   	return
................................................................................
   203    203       dict set def  $name $spec
   204    204       dict set char $name $spec
   205    205       return
   206    206   }
   207    207   
   208    208   # # ## ### ##### ######## ############# #####################
   209    209   
   210         -proc ::cmdr::color::Unknown {cmd codes text} {
          210  +proc ::cmdr::color::Unknown {cmd codes {text {}}} {
   211    211       list [namespace current]::Apply $codes
   212    212   }
   213    213   
   214         -proc ::cmdr::color::Apply {codes text} {
          214  +proc ::cmdr::color::Apply {codes {text {}}} {
   215    215       debug.cmdr/color {}
   216    216   
   217    217       variable active
   218    218       if {!$active} {
   219    219   	debug.cmdr/color {not active}
   220    220   	return $text
   221    221       }
................................................................................
   225    225   	if {![dict exists $char $c]} {
   226    226   	    return -code error \
   227    227   		-errorcode [list CMDR COLOR UNKNOWN $c] \
   228    228   		"Expected a color name, got \"$c\""
   229    229   	}
   230    230   	append r [dict get $char $c]
   231    231       }
   232         -    append r $text
   233         -    append r [dict get $char reset]
          232  +    if {$text ne {}} {
          233  +	append r $text
          234  +	append r [dict get $char reset]
          235  +    }
   234    236   
   235    237       debug.cmdr/color {/done}
   236    238       return $r
   237    239   }
   238    240   
   239    241   proc ::cmdr::color::Quote {text} {
   240    242       # quote all non-printable characters (< space, > ~)