cmdr
Check-in [1a8a4b4d23]
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 tclconference@googlegroups.com
or submit via the online form by Sep 9.

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

Overview
Comment:Fixed color testing. Plus tweaked color command to always validate codes, even when use is disabled.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1a8a4b4d232ee4b9440b577acbfe8aa0c0b8d27c
User & Date: aku 2015-05-08 20:27:50
Context
2015-05-08
21:04
Testsuite fixes, help output. Not fully fixed, only mostly. check-in: 6e5381c43c user: aku tags: trunk
20:27
Fixed color testing. Plus tweaked color command to always validate codes, even when use is disabled. check-in: 1a8a4b4d23 user: aku tags: trunk
20:27
Fix officer tests, new -- option. check-in: 00a6db24bb user: aku tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to color.tcl.

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
    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]
    }








>






|
|
|
<
<
<







>
>
>
>
>
>
>
>
>
>







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
243
244
    dict set char $name $spec
    return
}

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

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

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

    # Check codes first. Even if not active! IOW do not stop catching
    # the use of bad/unknown codes just because we switched off the
    # colorization.



    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\""
	}
    }

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

    # Apply chosen colors. Validation happend already.
    foreach c $codes {
	append r [dict get $char $c]
    }
    if {$text ne {}} {
	append r $text
	append r [dict get $char reset]
    }

Changes to tests/color.test.

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
156
157
158
159
160
161
162




















163
164
165
166
167
168
169
    hidden	{\033[8m}
    italic	{\033[3m}
    magenta	{\033[35m}
    name	{\033[34m}
    neutral	{\033[34m}
    no		{\033[31m}
    no-blink	{\033[25m}
    no-bold	{\033[22m}
    no-dim	{\033[__m}
    no-hidden	{\033[28m}
    no-italic	{\033[23m}
    no-revers	{\033[27m}
    no-strike	{\033[29m}
    no-underline {\033[24m}
    note	{\033[34m}
    number	{\033[32m}
................................................................................
    yellow	{\033[33m}
    yes		{\033[32m}
}

set thedefs {
    advisory	=yellow
    bad		=red
    bg-black	{\033[40m}
    bg-blue	{\033[44m}
    bg-cyan	{\033[46m}
    bg-default	{\033[49m}
    bg-green	{\033[42m}
    bg-magenta	{\033[45m}
    bg-red	{\033[41m}
    bg-white	{\033[47m}
    bg-yellow	{\033[43m}
    black	{\033[30m}
    blink	{\033[5m}
    blue	{\033[34m}
    bold	{\033[1m}
    confirm	=red
    cyan	{\033[36m}
    default	{\033[39m}
    dim		{\033[2m}
    error	=magenta
    good	=green
    green	{\033[32m}
    hidden	{\033[8m}
    italic	{\033[3m}
    magenta	{\033[35m}
    name	=blue
    neutral	=blue
    no		=red
    no-blink	{\033[25m}
    no-bold	{\033[22m}
    no-dim	{\033[__m}
    no-hidden	{\033[28m}
    no-italic	{\033[23m}
    no-revers	{\033[27m}
    no-strike	{\033[29m}
    no-underline {\033[24m}
    note	=blue
    number	=green
    prompt	=blue
    red		{\033[31m}
    reset	{\033[0m}
    revers	{\033[7m}
    strike	{\033[9m}
    underline	{\033[4m}
    unknown	=cyan
    warning	=yellow
    white	{\033[37m}
    yellow	{\033[33m}
    yes		=green
}

# # ## ### ##### ######## ############# #####################
## Basic wrong#args checks.

test cmdr-color-1.0 {color, wrong num args, not enough} -body {
    cmdr color
} -returnCodes error \
    -result {wrong # args: should be "cmdr color subcommand ?argument ...?"}

test cmdr-color-1.1 {color, bogus sub-command, not enough args} -body {
    cmdr color foo
} -returnCodes error \
    -result {wrong # args: should be "::cmdr::color::Unknown cmd codes text"}

test cmdr-color-1.2 {color, bogus sub-command, bogus color name} -setup {
    set save [cmdr color active]
    cmdr color activate 1
} -body {
    cmdr color foo text
} -cleanup {
    cmdr color activate $save
    unset save
} -returnCodes error -result {Expected a color name, got "foo"}

test cmdr-color-2.0 {color, formatting, single code} -setup {
    set save [cmdr color active]
    cmdr color activate 1
} -body {
    cmdr color red text
} -cleanup {
................................................................................
    cmdr color activate 1
} -body {
    cmdr color {bold red} text
} -cleanup {
    cmdr color activate $save
    unset save
} -result "\033\[1m\033\[31mtext\033\[0m"





















# # ## ### ##### ######## ############# #####################
## Go through the API commands.
## active, activate, names, get, get-def, define, exists

# # ## ### ##### ######## ############# #####################
## active







|
|







 







|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|


|
|
|
|



|
|
|
|
|
|
|
|



|
|
|
|
|


|
|











|
|
|
|
|
|
|
|
|
|
|
|
|
|







 







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







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
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
181
182
183
184
185
186
187
188
189
    hidden	{\033[8m}
    italic	{\033[3m}
    magenta	{\033[35m}
    name	{\033[34m}
    neutral	{\033[34m}
    no		{\033[31m}
    no-blink	{\033[25m}
    no-bold	{\033[21m}
    no-dim	{\033[22m}
    no-hidden	{\033[28m}
    no-italic	{\033[23m}
    no-revers	{\033[27m}
    no-strike	{\033[29m}
    no-underline {\033[24m}
    note	{\033[34m}
    number	{\033[32m}
................................................................................
    yellow	{\033[33m}
    yes		{\033[32m}
}

set thedefs {
    advisory	=yellow
    bad		=red
    bg-black	e40
    bg-blue	e44
    bg-cyan	e46
    bg-default	e49
    bg-green	e42
    bg-magenta	e45
    bg-red	e41
    bg-white	e47
    bg-yellow	e43
    black	e30
    blink	e5
    blue	e34
    bold	e1
    confirm	=red
    cyan	e36
    default	e39
    dim		e2
    error	=magenta
    good	=green
    green	e32
    hidden	e8
    italic	e3
    magenta	e35
    name	=blue
    neutral	=blue
    no		=red
    no-blink	e25
    no-bold	e21
    no-dim	e22
    no-hidden	e28
    no-italic	e23
    no-revers	e27
    no-strike	e29
    no-underline e24
    note	=blue
    number	=green
    prompt	=blue
    red		e31
    reset	e0
    revers	e7
    strike	e9
    underline	e4
    unknown	=cyan
    warning	=yellow
    white	e37
    yellow	e33
    yes		=green
}

# # ## ### ##### ######## ############# #####################
## Basic wrong#args checks.

test cmdr-color-1.0 {color, wrong num args, not enough} -body {
    cmdr color
} -returnCodes error \
    -result {wrong # args: should be "cmdr color subcommand ?argument ...?"}

test cmdr-color-1.1 {color, wrong num args, too many} -body {
    cmdr color red text X
} -returnCodes error \
    -result {wrong # args: should be "::cmdr::color::Unknown cmd codes ?text?"}

test cmdr-color-1.2 {color, bogus sub-command, bogus color name, no text} -body {
    cmdr color foo
} -returnCodes error -result {Expected a color name, got "foo"}

test cmdr-color-1.3 {color, bogus sub-command, bogus color name, with text} -body {
    cmdr color foo text
} -returnCodes error -result {Expected a color name, got "foo"}

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

test cmdr-color-2.0 {color, formatting, single code} -setup {
    set save [cmdr color active]
    cmdr color activate 1
} -body {
    cmdr color red text
} -cleanup {
................................................................................
    cmdr color activate 1
} -body {
    cmdr color {bold red} text
} -cleanup {
    cmdr color activate $save
    unset save
} -result "\033\[1m\033\[31mtext\033\[0m"

test cmdr-color-2.2 {color, formatting, single code, no text} -setup {
    set save [cmdr color active]
    cmdr color activate 1
} -body {
    cmdr color red
} -cleanup {
    cmdr color activate $save
    unset save
} -result "\033\[31m"

test cmdr-color-2.3 {color, formatting, multi-code, no text} -setup {
    set save [cmdr color active]
    cmdr color activate 1
} -body {
    cmdr color {bold red}
} -cleanup {
    cmdr color activate $save
    unset save
} -result "\033\[1m\033\[31m"

# # ## ### ##### ######## ############# #####################
## Go through the API commands.
## active, activate, names, get, get-def, define, exists

# # ## ### ##### ######## ############# #####################
## active