Styles
By the end of this chapter you can name
the styles that exist, say what auto
actually does to choose one, and make
a small style of your own from a JSON
file.
The styles that exist
A style is chosen with -s (or
--style), or in the configuration
file. Glow 3.0.0 ships these names.
The lab ran each against the same
small document — an eleven-line
packing list — into a pipe, and
counted bytes:
| Style | Bytes | What it is |
|---|---|---|
auto |
798 | chooses — in a pipe, this is notty |
notty |
798 | the plain reading: no colour, ASCII rules |
ascii |
798 | plain like notty; identical on this document |
pink |
914 | nearly plain, a whisper of colour |
dark |
9,212 | the full colour reading, for dark terminals |
light |
9,212 | the full colour reading, for light terminals |
dracula |
13,940 | a named theme from the wider editor world |
tokyo-night |
13,940 | another named theme |
(transcript
glow-lab/transcripts/t04-styles.txt).
Names you might reach for that do
not exist in this version —
solarized-dark, solarized-light,
gruvbox, catppuccino — are refused
flatly, exit code 1:
$ glow -s nosuchstyle packing-list.md
Error: specified style does not exist: nosuchstyle
pink deserves its sentence: at 914
bytes against notty's 798, it is
plain text with a touch of colour
rather than a full repaint — the
gentle option when colour codes would
be unwelcome but a little emphasis
would not.
Dark and light are one layout in two lights
dark and light produce the same
page — same bytes count, same layout —
differing in palette. The lab read
the difference out of the escapes: the
body text is colour 252 (near
white) under dark, and 234 (near
black) under light, 594 times each
in the specimen. Even the top
heading's band is identical in both —
228 on 63. A style, in other
words, is mostly one decision (what
colour is ordinary text?) applied
everywhere, which is why chapter 5
could describe a whole page from a
handful of codes.
Auto asks the terminal — give it time
Left on auto at a terminal, Glow
must decide dark or light itself. It
asks the terminal: the lab
captured the raw first bytes of a
terminal run, and they are questions
in escape form — OSC 10 ? ("your
foreground colour?"), a cursor-position
report request used as a synchronising
marker, and OSC 11 ? ("your
background colour?"). A real terminal
answers in milliseconds and the page
appears.
Two proved facts and one honest gap:
- A terminal that never answers
costs about ten seconds. The
lab's muted pretend terminal took
10.04 seconds to produce the same
page an answering one produced in
0.07. Glow waits, then renders
anyway, in
dark. If Glow seems to hang at startup in an old terminal emulator, a script, or an embedded console, this wait is the first suspect (chapter 15, and transcriptglow-lab/transcripts/t90-terminal.txt). - The fallback is dark. Every unanswered or unclear run the lab made came out dark.
- The gap: the lab's pretend
terminal could not be persuaded to
report a light background in a way
Glow accepted — answering runs came
out dark whether the pretended
background was dark or light. That
autochooseslighton a genuinely light terminal is the project's documented behaviour, and this guide labels it documented-only rather than pretend the lab saw it.
If the choice matters to you, do not
leave it to the questions: say
-s dark or -s light and be done.
A style of your own: the JSON file
A style is data: a JSON document
naming colours and habits for each
element — h1, link, task, code,
and friends. Passing a path to a
JSON file as the style
(glow -s my-style.json file.md)
renders with it. The lab's survey of
the craft went like this: take the
stock dark style's JSON (it is part
of the glamour library Glow is built
on, published in that project's
repository), change one entry — the
top heading to colour 226 on
background 196 — and render. The
heading's escape changed to exactly
38;5;226;48;5;196;1, as ordered.
The full vocabulary of entries is the
glamour project's documentation;
survey level is the honest depth
here, because designing a readable
palette is a craft of its own.
Two errors guard the door. A JSON
file that is not valid JSON stops the
run: Error: unable to create
renderer: invalid character …. And a
path that does not exist gets the
same message as an unknown style
name — specified style does not
exist — so when that error names a
path, check the path before doubting
the style.
Check: render your packing-list-sized
document under -s dark, -s light
and -s pink, pipe each to wc -c,
and see the table above reproduced in
your own numbers. Then copy a stock
style, change one colour, and watch
exactly one element obey. If both
work, you have this chapter.