Commit 58cb5db
Add colour to the CLI on a terminal, and nothing at all when piped
Human-mode output gains a Claude-Code-style colour hierarchy: dim labels,
accented names and paths, semantic status colour (goal_met and admitted
green, rejected and REFUSED red), and aligned key/value blocks.
The whole design rests on one constraint: styling is decided at print time
from the stream's own isatty(), so piped, redirected and captured output is
byte-identical to before. That is what lets this land without touching a
single expected block — tests/test_readme.py and tests/test_cookbook_models.py
byte-compare CLI output against README.md and docs/cookbook/02-models.md, and
both harnesses present a non-tty stdout. Padding is emitted outside the
escape sequences, so a column is the same character count either way.
Verified: 50/36/32/18 escapes on a pty for plan/models/models --check/demo,
zero escapes on every piped stream, and ANSI-stripped tty output identical to
piped output. NO_COLOR, TERM=dumb, --no-color and --json each yield zero
escapes. The contracts that matter are unchanged — --json is one parseable
document on stdout with zero-byte stderr, a text-mode failure leaves stdout
empty with "error: ..." on stderr, viz stays raw pasteable Mermaid, and
replay/diff still emit only the engine formatter's text.
New grapharc/cli/style.py is stdlib only. No dependency was added: rich is
not in the lock, and the README markets a four-package runtime dep list.
Deliberately no glyphs, boxes or rules, even on a terminal. README and two
cookbook pages print these blocks verbatim, so tty-only decoration would
make what a user sees diverge from what the docs show — drift in the one
direction the byte-comparison tests cannot catch.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 21bc764 commit 58cb5db
9 files changed
Lines changed: 610 additions & 84 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
244 | 255 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
250 | 269 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
255 | 283 | | |
256 | 284 | | |
257 | | - | |
258 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
259 | 293 | | |
260 | | - | |
261 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
262 | 300 | | |
263 | 301 | | |
264 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
183 | 184 | | |
184 | 185 | | |
185 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
186 | 197 | | |
187 | 198 | | |
188 | | - | |
189 | | - | |
| 199 | + | |
190 | 200 | | |
191 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
192 | 211 | | |
193 | | - | |
194 | | - | |
| 212 | + | |
195 | 213 | | |
196 | 214 | | |
197 | 215 | | |
| |||
210 | 228 | | |
211 | 229 | | |
212 | 230 | | |
213 | | - | |
214 | | - | |
| 231 | + | |
215 | 232 | | |
216 | | - | |
| 233 | + | |
217 | 234 | | |
218 | 235 | | |
219 | | - | |
| 236 | + | |
220 | 237 | | |
221 | 238 | | |
222 | 239 | | |
| |||
227 | 244 | | |
228 | 245 | | |
229 | 246 | | |
230 | | - | |
231 | | - | |
232 | | - | |
| 247 | + | |
| 248 | + | |
233 | 249 | | |
234 | | - | |
235 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
236 | 254 | | |
237 | 255 | | |
238 | 256 | | |
| |||
245 | 263 | | |
246 | 264 | | |
247 | 265 | | |
248 | | - | |
249 | | - | |
250 | | - | |
| 266 | + | |
| 267 | + | |
251 | 268 | | |
252 | | - | |
253 | | - | |
254 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
255 | 272 | | |
256 | 273 | | |
257 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
| |||
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
58 | | - | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
65 | | - | |
| 70 | + | |
66 | 71 | | |
67 | 72 | | |
| 73 | + | |
68 | 74 | | |
69 | | - | |
70 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
71 | 79 | | |
72 | 80 | | |
73 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
74 | 89 | | |
75 | 90 | | |
76 | 91 | | |
| |||
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
93 | | - | |
| 108 | + | |
94 | 109 | | |
95 | 110 | | |
96 | 111 | | |
| |||
99 | 114 | | |
100 | 115 | | |
101 | 116 | | |
102 | | - | |
| 117 | + | |
| 118 | + | |
103 | 119 | | |
104 | 120 | | |
105 | 121 | | |
106 | | - | |
107 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
108 | 127 | | |
109 | | - | |
| 128 | + | |
110 | 129 | | |
111 | 130 | | |
112 | 131 | | |
| |||
0 commit comments