-- Leo's gemini proxy

-- Connecting to gemini.omarpolo.com:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;lang=en

↩ back to the index


Customize tty colors


Written while listening to “Tema del soldato eterno e degli aironi” by Roberto Vecchioni.

Published: 2021-02-23

Tagged with:

#linux


Last week I spent a couple of days at my relative house. The only thing I took with me was a raspberry, plugged to the TV.


The raspberry was running void linux, with only a small selection of software installed on it (Emacs, git, a C toolchain and nothing more, neither X11), and it was refreshing! Most of the time the system was offline so I could focus on writing code, with only some occasional trips to man.openbsd.org with w3m to read some decent manpages.


(w3m is quite a fine browser, maybe I’ll try to create something akin to it for Gemini.)


The thing is, I am one of those strange people who doesn’t like dark colorschemes. “Black print on white paper, as God and Gutenberg intended.” Unfortunately the linux ttys are white text on a black background. Let’s fix that!


I found (and forgot the link) that linux allows one to customize the colors via ANSI escape codes and also set the default foreground and background.


The “template” for these codes are:


\033 ] P <index> <html-hex-color>

(spaces only for readability)


where ‘\033’ is the escape character, index is a one hex digit (0-F) and ‘html-hex-color’ is the familiar “HTML-style” six hexadecimal digit color.


I’m using the following colors, but you can customize them to match your preferred scheme:


printf "\033]P0000000" #black
printf "\033]P1803232" #darkred
printf "\033]P25b762f" #darkgreen
printf "\033]P3aa9943" #brown
printf "\033]P4324c80" #darkblue
printf "\033]P5706c9a" #darkmagenta
printf "\033]P692b19e" #darkcyan
printf "\033]P7ffffff" #lightgrey
printf "\033]P8222222" #darkgrey
printf "\033]P9982b2b" #red
printf "\033]PA89b83f" #green
printf "\033]PBefef60" #yellow
printf "\033]PC2b4f98" #blue
printf "\033]PD826ab1" #magenta
printf "\033]PEa1cdcd" #cyan
printf "\033]PFdedede" #white

Then, it’s possible to change the foreground and background as usual, but there’s an extra escape code to “persist” the combination:


# set the default background color (47, aka white) and the default
# foreground color (30, aka black), then store it (aka [8])
printf '\033[47;1;30m\033[8]'

Here’s the outcome:


Bright tty, screenshot (282K)





-- text: CC-BY-SA-4.0; code: public domain unless specified otherwise

For comments, write at < blog at omarpolo dot com > or @yumh@pleroma.libretux.com in the fediverse.

Capsule proudly assembled with Clojure

-- Response ended

-- Page fetched on Tue Oct 19 14:55:13 2021