cmdr
Check-in [4d0064e1b1]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

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

Overview
Comment:Extended color definition code with recognition of symbolic escape code sequences.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4d0064e1b186f75ba6e752fecce5beb715b751b1
User & Date: aku 2014-08-15 17:52:57
Context
2014-08-15
17:55
Fix left-over oops. check-in: 6e34f0dec4 user: aku tags: trunk
17:52
Extended color definition code with recognition of symbolic escape code sequences. check-in: 4d0064e1b1 user: aku tags: trunk
2014-06-17
18:27
cmdr::config - Fix long-standing bug in forced parameter value calculation (method 'Force'). Any error in the calculations left the flag 'myinforce' set, causing a future invokation to believe to be in a recursive call and do nothing. While this had no effect on regular operation, i.e. where the using application exits after the command, in interactive mode this disabled checks and validations for the command in question, and also retained old parameter values. Fixed by putting a try/finally around the section, resetting the flag even in the presence of errors thrown by it. cmdr::config version bumped to 1.1.1. check-in: f74095b252 user: andreask tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to color.tcl.

134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
...
153
154
155
156
157
158
159













160
161
162
163
164
165
166
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    # (1) A reference to other color name.
    # (2) An RGB spec.
    # (3) A raw control sequence.

    # Syntax:
    # (1) ref := =<name>
    # (2) rgb := %<r>,<g>,<b>

    # (3) raw := anything else

    if {[regexp {^=(.*)$} $spec -> ref]} {
	if {$ref eq $name} {
	    return -code error \
		-errorcode [list CMDR COLOR CIRCLE $name] \
		"Rejected self-referential definition of \"$name\""
	} elseif {![dict exists $def $ref]} {
................................................................................
	    set raw [dict get $char $ref]
	    debug.cmdr/color {reference, resolved => [Quote $raw]}
	    dict set def  $name $spec
	    dict set char $name $raw
	    return
	}
    }














    if {[regexp {^%(.*)$} $spec -> rgb]} {
	if {![regexp {^(\d+),(\d+),(\d+)$} $rgb -> r g b]} {
	    return -code error \
		-errorcode [list CMDR COLOR BAD-RGB SYNTAX $rgb] \
		"Expected an RGB tuple, got \"$rgb\""
	} {
................................................................................
    # dictionaries hold the user-level specification and the
    # full-resolved character sequence.

    variable def  {}
    variable char {}

    # Colors. Foreground/Text.
    define  black        [Code 30]  ; # Black  
    define  red          [Code 31]  ; # Red    
    define  green        [Code 32]  ; # Green  
    define  yellow       [Code 33]  ; # Yellow 
    define  blue         [Code 34]  ; # Blue   
    define  magenta      [Code 35]  ; # Magenta
    define  cyan         [Code 36]  ; # Cyan   
    define  white        [Code 37]  ; # White  
    define  default      [Code 39]  ; # Default (Black)

    # Colors. Background.
    define  bg-black     [Code 40]  ; # Black  
    define  bg-red       [Code 41]  ; # Red    
    define  bg-green     [Code 42]  ; # Green  
    define  bg-yellow    [Code 43]  ; # Yellow 
    define  bg-blue      [Code 44]  ; # Blue   
    define  bg-magenta   [Code 45]  ; # Magenta
    define  bg-cyan      [Code 46]  ; # Cyan   
    define  bg-white     [Code 47]  ; # White  
    define  bg-default   [Code 49]  ; # Default (Transparent)

    # Non-color attributes. Activation.
    define  bold         [Code  1]  ; # Bold  
    define  dim          [Code  2]  ; # Dim
    define  italic       [Code  3]  ; # Italics      
    define  underline    [Code  4]  ; # Underscore   
    define  blink        [Code  5]  ; # Blink
    define  revers       [Code  7]  ; # Reverse      
    define  hidden       [Code  8]  ; # Hidden
    define  strike       [Code  9]  ; # StrikeThrough

    # Non-color attributes. Deactivation.
    define  no-bold      [Code 22]  ; # Bold  
    define  no-dim       [Code __]  ; # Dim
    define  no-italic    [Code 23]  ; # Italics      
    define  no-underline [Code 24]  ; # Underscore   
    define  no-blink     [Code 25]  ; # Blink
    define  no-revers    [Code 27]  ; # Reverse      
    define  no-hidden    [Code 28]  ; # Hidden
    define  no-strike    [Code 29]  ; # StrikeThrough

    # Remainder
    define  reset        [Code  0]  ; # Reset

    # And now the standard symbolic names
    define  advisory =yellow
    define  bad      =red
    define  confirm  =red
    define  error    =magenta
    define  good     =green






>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
|
|
|
|
|
|


|
|
|
|
|
|
|
|
|


|
|
|
|
|
|
|
|


|
|
|
|
|
|
|
|


|







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
    # (1) A reference to other color name.
    # (2) An RGB spec.
    # (3) A raw control sequence.

    # Syntax:
    # (1) ref := =<name>
    # (2) rgb := %<r>,<g>,<b>
    # (3) esc := [Ee]<code>(,...)?
    # (4) raw := anything else

    if {[regexp {^=(.*)$} $spec -> ref]} {
	if {$ref eq $name} {
	    return -code error \
		-errorcode [list CMDR COLOR CIRCLE $name] \
		"Rejected self-referential definition of \"$name\""
	} elseif {![dict exists $def $ref]} {
................................................................................
	    set raw [dict get $char $ref]
	    debug.cmdr/color {reference, resolved => [Quote $raw]}
	    dict set def  $name $spec
	    dict set char $name $raw
	    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
    }

    if {[regexp {^%(.*)$} $spec -> rgb]} {
	if {![regexp {^(\d+),(\d+),(\d+)$} $rgb -> r g b]} {
	    return -code error \
		-errorcode [list CMDR COLOR BAD-RGB SYNTAX $rgb] \
		"Expected an RGB tuple, got \"$rgb\""
	} {
................................................................................
    # dictionaries hold the user-level specification and the
    # full-resolved character sequence.

    variable def  {}
    variable char {}

    # Colors. Foreground/Text.
    define  black        e30  ; # Black  
    define  red          e31  ; # Red    
    define  green        e32  ; # Green  
    define  yellow       e33  ; # Yellow 
    define  blue         e34  ; # Blue   
    define  magenta      e35  ; # Magenta
    define  cyan         e36  ; # Cyan   
    define  white        e37  ; # White  
    define  default      e39  ; # Default (Black)

    # Colors. Background.
    define  bg-black     e40  ; # Black  
    define  bg-red       e41  ; # Red    
    define  bg-green     e42  ; # Green  
    define  bg-yellow    e43  ; # Yellow 
    define  bg-blue      e44  ; # Blue   
    define  bg-magenta   e45  ; # Magenta
    define  bg-cyan      e46  ; # Cyan   
    define  bg-white     e47  ; # White  
    define  bg-default   e49  ; # Default (Transparent)

    # Non-color attributes. Activation.
    define  bold         e1   ; # Bold  
    define  dim          e2   ; # Dim
    define  italic       e3   ; # Italics      
    define  underline    e4   ; # Underscore   
    define  blink        e5   ; # Blink
    define  revers       e7   ; # Reverse      
    define  hidden       e8   ; # Hidden
    define  strike       e9   ; # StrikeThrough

    # Non-color attributes. Deactivation.
    define  no-bold      e21  ; # Bold  
    define  no-dim       e22  ; # Dim
    define  no-italic    e23  ; # Italics      
    define  no-underline e24  ; # Underscore   
    define  no-blink     e25  ; # Blink
    define  no-revers    e27  ; # Reverse      
    define  no-hidden    e28  ; # Hidden
    define  no-strike    e29  ; # StrikeThrough

    # Remainder
    define  reset        e 0  ; # Reset

    # And now the standard symbolic names
    define  advisory =yellow
    define  bad      =red
    define  confirm  =red
    define  error    =magenta
    define  good     =green