cmdr
Check-in [509f2d765f]
Not logged in

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.774
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
Unified Diff Ignore Whitespace Patch
Changes to color.tcl.
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
	    return
	}
    }

    if {[regexp {^[eE](.*)$} $spec -> codes]} {
	if {![regexp {^(\d+)(,\d+)*$} $codes]} {
	    return -code error \
		-errorcode [list CMDR COLOR BAD-ESCAPE SYNTAX $rgb] \
		"Expected a comma-separated list of codes, got \"$spec\""
	}
	set codes [Code {*}[split $codes ,]]
	debug.cmdr/color {ESC encoded => [Quote $codes]}
	dict set def  $name $spec
	dict set char $name $codes
	return







|







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
	    return
	}
    }

    if {[regexp {^[eE](.*)$} $spec -> codes]} {
	if {![regexp {^(\d+)(,\d+)*$} $codes]} {
	    return -code error \
		-errorcode [list CMDR COLOR BAD-ESCAPE SYNTAX $spec] \
		"Expected a comma-separated list of codes, got \"$spec\""
	}
	set codes [Code {*}[split $codes ,]]
	debug.cmdr/color {ESC encoded => [Quote $codes]}
	dict set def  $name $spec
	dict set char $name $codes
	return
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

232
233

234
235
236
237
238
239
240
    dict set def  $name $spec
    dict set char $name $spec
    return
}

# # ## ### ##### ######## ############# #####################

proc ::cmdr::color::Unknown {cmd codes text} {
    list [namespace current]::Apply $codes
}

proc ::cmdr::color::Apply {codes text} {
    debug.cmdr/color {}

    variable active
    if {!$active} {
	debug.cmdr/color {not active}
	return $text
    }

    variable char
    foreach c $codes {
	if {![dict exists $char $c]} {
	    return -code error \
		-errorcode [list CMDR COLOR UNKNOWN $c] \
		"Expected a color name, got \"$c\""
	}
	append r [dict get $char $c]
    }

    append r $text
    append r [dict get $char reset]


    debug.cmdr/color {/done}
    return $r
}

proc ::cmdr::color::Quote {text} {
    # quote all non-printable characters (< space, > ~)







|



|

















>
|
|
>







203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
    dict set def  $name $spec
    dict set char $name $spec
    return
}

# # ## ### ##### ######## ############# #####################

proc ::cmdr::color::Unknown {cmd codes {text {}}} {
    list [namespace current]::Apply $codes
}

proc ::cmdr::color::Apply {codes {text {}}} {
    debug.cmdr/color {}

    variable active
    if {!$active} {
	debug.cmdr/color {not active}
	return $text
    }

    variable char
    foreach c $codes {
	if {![dict exists $char $c]} {
	    return -code error \
		-errorcode [list CMDR COLOR UNKNOWN $c] \
		"Expected a color name, got \"$c\""
	}
	append r [dict get $char $c]
    }
    if {$text ne {}} {
	append r $text
	append r [dict get $char reset]
    }

    debug.cmdr/color {/done}
    return $r
}

proc ::cmdr::color::Quote {text} {
    # quote all non-printable characters (< space, > ~)