Table of Contents
- Themes
- 1. The theme file
- 2. [theme]
- 3. [terminal]: the colors of the view
- 4. [palette]: the 16 colors programs name
- 5. [attributes]: text a program marks
- 6. [rules]: a style for text a pattern finds
- 7. [terminal-widget]: the settings of the display
- 8. The built-in themes
- 9. An editor theme is a terminal theme too
- 10. The functions
Themes
A terminal theme gives a color to each thing a host draws, a style to each text attribute and to text a pattern finds, and the settings of the display. This page describes the theme file and each of its keys with its fallback, the four built-in themes, editor themes, and the functions of hosho_theme.h.
1. The theme file
A theme file is a text file in the form of Unryu's editor themes: sections in square brackets, and key = value lines in them. A line that starts with ; is a comment; spaces and tabs at the two ends of a line, and around the =, do not count, and a line can end with a carriage return. A theme can leave out any key: each one it leaves out takes a fallback, so a theme of three lines works, and the fallbacks are made from the colors the theme does give (a dark background gets light text, a selection and a palette made for a dark background).
[theme]
name = My Theme
[terminal]
background = #14110F
text = #E6DFD3
cursor = #C8553D
; the background of each line with a prompt
prompt-line = #1D1916
[palette]
red = #E06C75
[attributes]
; bold text with no color of its own: white, in the regular face
bold = #FFFFFF -
; italic text: its own color, drawn italic
italic = - - italic
[rules]
; the words error, failed and fatal in red and bold, in upper or lower case
error = #FF5555 - bold /error|failed|fatal/i
; "warning:" on a dark yellow background
warning = #FFD700 #3A3000 /warning:/
[terminal-widget]
font-family = DejaVu Sans Mono
font-size = 15
cursor-shape = bar
cursor-blink = 1
line-spacing = 2
- A color is
#rrggbbor#rgb(#fa0is#ffaa00).-ornonein place of a color means "no color of its own": for a text key, each character's own color; forprompt-lineandoutput-failure, nothing is drawn. (syntax, which an editor theme can have, means the same.) A key such asbackground,selectionorgutterhas no "own color" to fall back on: for it,-is the same as leaving the key out, and it gets its default color. - A style is
foreground background [bold] [italic]: two colors, each of which can be-, then the wordsboldanditalicwhen the face is to be bold or italic. A style can be only a foreground. In a style only-means "no color";nonethere makes the value not correct. - A number is written in digits, at most 7 of them; for a setting that is on or off,
0is off and any other number is on. - A value that is not correct is not read: the key keeps its fallback. When a key comes two times, the second wins. Sections and keys Hosho does not know are left alone, so one file can also hold an editor's theme.
- A comment is a whole line. A
;after a value is part of the value, which is then not a correct color. - A file larger than 256 KiB is read only to that size.
hosho_theme_write() writes a theme with every key, each with a line of words above it that says what it is, so a theme file can show all a user can change. It writes the theme's rules too, or an example rule as a comment when the theme has none. demo/hosho_demo -t NAME -W writes such a file for any theme, and the four files in themes/ are the built-in themes written that way.
2. [theme]
| Key | What it is | Fallback |
|---|---|---|
name |
The theme's name, at most 63 bytes. | Terminal |
description |
A line that says what the theme is like, at most 255 bytes. | none |
3. [terminal]: the colors of the view
Each key is a color. Each key for a background has a key for the text on it (selection and selection-text); - for such a text key keeps each character's own color.
| Key | What it colors | Fallback |
|---|---|---|
background |
The view's background. | The editor theme's background, or #1B1D21. |
text |
Text with no other color. | The editor theme's text, or #D7DAE0 on a dark background and #2A2C33 on a light one. |
selection |
The selection's background. | The editor theme's selection, or a quarter of the way from the background to the text. |
selection-text |
Text in the selection. | When the selection comes from the editor theme: the editor theme's selection text, or the text color when it has none. Otherwise -. |
cursor |
The cursor. The widget also draws the outline of the keyboard selection and the frame of the visual bell in the cursor's color. | The editor theme's caret, or the text color. |
cursor-text |
The character under a block cursor. | -: the cell's background color. |
link |
The dotted underline of a hyperlink a program made (OSC 8), and the text of any link (also an address or a file name) under the pointer while Control is held; that link is then underlined with a single line. | The editor theme's link color, or bright-blue on a dark background and blue on a light one. |
gutter |
The margin where the shell's marks are drawn, and the inside of a hollow mark (a prompt whose output is hidden). | The background. |
prompt-mark |
The mark of a prompt whose command still runs or gave no result. | The editor theme's line numbers, or halfway from the background to the text. |
prompt-success |
The mark of a prompt whose command ended with status 0. | The editor theme's compiler success color, or green. |
prompt-failure |
The mark of a prompt whose command ended with another status. | The editor theme's compiler error color, or red. |
prompt-line, prompt-line-text |
The background of each line with a prompt, and its text. They color only the cells a program gave no color of their own. | none: not drawn; -. |
output-failure, output-failure-text |
The background of the output of a command that failed, and its text, again only in cells with no color of their own. | none: not drawn; -. |
fold |
The words in place of a command's hidden output (... 12 lines). |
The prompt-mark color. |
search-match, search-match-text |
Each match of a search, and its text. | Halfway from the background to yellow; -. |
search-current, search-current-text |
The match the search is at, and its text. The letters on links (Control+Shift+O) have these colors too. | yellow; the background on a dark background and the text on a light one. |
The widget also uses three of these colors for the bar at the top of the view that shows a job's progress (OSC 9;4): prompt-failure for an error, prompt-mark for a job that waits, and prompt-success otherwise. A program can change the text, background, cursor and selection colors while it runs (OSC 10, 11, 12, 17 and 19); the theme gives the colors it starts with.
The colors of the background, selection and cell backgrounds are drawn as they are; the colors of text can be changed by minimum-contrast (below). A color is dark when its brightness (red, green and blue weighted 0.299, 0.587 and 0.114) is less than 128 of 255.
4. [palette]: the 16 colors programs name
The keys are black, red, green, yellow, blue, magenta, cyan, white (colors 0 to 7) and bright-black to bright-white (colors 8 to 15). Each that the theme leaves out comes from one of two sets, by whether the background is dark or light; each color keeps its hue and is readable on that ground. A theme does not set the colors 16 to 255: they start as xterm's, a 6 by 6 by 6 color cube and 24 greys, and only a program changes them (OSC 4).
| Key | Dark | Light | Key | Dark | Light |
|---|---|---|---|---|---|
black |
#21252B |
#383A42 |
bright-black |
#5C6370 |
#696C77 |
red |
#E06C75 |
#CA1243 |
bright-red |
#FF7B86 |
#E4365F |
green |
#98C379 |
#2F8A3C |
bright-green |
#B1E18B |
#3FA34D |
yellow |
#E5C07B |
#A6730A |
bright-yellow |
#F5D08B |
#C18401 |
blue |
#61AFEF |
#2C6FD1 |
bright-blue |
#79C0FF |
#4078F2 |
magenta |
#C678DD |
#A626A4 |
bright-magenta |
#D8A0F0 |
#C24FC0 |
cyan |
#56B6C2 |
#0B7F8C |
bright-cyan |
#6FD3E0 |
#0997B3 |
white |
#ABB2BF |
#C9CCD3 |
bright-white |
#FFFFFF |
#FAFAFA |
5. [attributes]: text a program marks
Each key is a style for text a program marks with an attribute: bold, faint, italic, underline and blink. A color of the style is for text with no color of its own, and its background for a cell with no background of its own: a program that gives the text a color keeps it. When a cell has more than one of these attributes, the colors of the last one in the order of the table win. The words bold and italic choose the face it is drawn in; the face is bold when any of the cell's styles says bold, and the same for italic.
| Key | Fallback | Notes |
|---|---|---|
bold |
- - bold |
Without the word bold, bold text keeps the regular face (only its color shows it). |
faint |
- - |
With no color, faint text is drawn halfway from its color to its background. |
italic |
- - italic |
Without the word italic, italic text stays upright. |
underline |
- - |
The line itself is always drawn, in the text's color or in the color the program gave the underline (SGR 58). |
blink |
- - |
Blinking text blinks in each theme: it is hidden and shown again every 0.6 seconds. |
6. [rules]: a style for text a pattern finds
A rule gives a style to text in a program's output that a pattern finds, so errors and warnings stand out even when the program writes them with no color:
name = foreground background [bold] [italic] /pattern/
The key is the rule's name, at most 31 bytes (a rule with a longer name is not read); a rule with the name of one before it replaces that one. The style comes before the pattern and needs at least its foreground (- will do). The pattern is a POSIX extended regular expression between the first and the last slash, so it can hold slashes; a pattern longer than 159 bytes, or an empty one, makes the rule not correct. An i right after the last slash makes it ignore case. A rule's color is for text with no color of its own, and its background for a cell with no background of its own; its bold and italic choose the face. A theme has at most 32 rules, and more are not read; a pattern that is not correct finds nothing. The widget tests the rules in their order on each row of the screen as it is drawn, in at most the first 2048 bytes of the row, so a later rule's colors win over an earlier one's where both find text; the faces add up (text that a bold rule and an italic rule find is bold italic). A match cannot go over the end of a row.
7. [terminal-widget]: the settings of the display
These are the display's settings. The widget follows each of them; a host of its own reads them from HoshoTheme.settings, and hosho_theme_apply() gives the terminal the ones marked "terminal".
| Key | What it does | Fallback |
|---|---|---|
font-family |
The font, as fontconfig names it, at most 127 bytes. A monospace font: the cell is as wide as its letter M. The widget opens its bold, italic and bold italic faces by the same name. | monospace |
font-size |
The font's size in pixels; 0 counts as not given. |
14 |
cursor-shape |
block, underline or bar (terminal). |
block |
cursor-blink |
1: the cursor blinks (terminal). |
0 |
padding |
Pixels between the window's edge and the text. | 4 |
gutter-width |
Pixels of the margin for the shell's marks, left of the text; 0: no margin. |
6 |
line-spacing |
More pixels between lines, half above the text and half below. | 0 |
scrollback-lines |
The lines of scrollback to keep; 0: no scrollback. When a new theme changes it while the program runs, the newest lines stay. |
10000 |
bold-bright |
1: bold text in colors 0 to 7 is drawn in colors 8 to 15. |
0 |
clipboard-read |
1: a program can read the clipboard (OSC 52) (terminal). Permit this only when you trust each program you run. |
0 |
clipboard-write |
1: a program can set the clipboard (OSC 52) (terminal). |
0 |
keyboard |
pc: Home, End and the keypad's digits as programs expect. vt220: Home and End are Find and Select, and the keypad sends its own codes in application mode. sun, hp, sco, rxvt, linux: the function and editing keys send that keyboard's or that terminal's codes (terminal), and programs the widget starts get the TERM of that keyboard when the system has its terminal description. See Keyboard, Mouse and Paste. |
pc |
answerback |
What the terminal sends when a program sends ENQ, and the widget sends for Control+Break; empty: nothing (terminal). At most 63 bytes. | empty |
paste-confirm |
1: a paste of more than one line, to a program that does not mark pastes, asks first. |
1 |
ligatures |
1: the font's ligatures and contextual forms are drawn when the font has them (-> as an arrow). |
1 |
bell |
sound (the X server's bell), visual (a frame at the view's edge, in the cursor's color, for 0.15 seconds), both, or none. The widget's bell callback is called in each case. |
sound |
minimum-contrast |
The least contrast of text and its background, 1 to 21 (as WCAG counts it; 4.5 is easy to read). Text with less is made lighter or darker until it has enough. It can have decimals; a value outside 1 to 21 is not read. 1: colors stay as they are. |
1 |
notify-command-seconds |
A command of the shell that ran this many seconds or more gives a notification when it ends while the terminal does not have the keyboard; 0: never. It needs the shell integration, which tells when a command ends, and the host's notification callback, which shows it. |
10 |
log-file |
A file that gets the text programs show, from the first, added at its end: each character as UTF-8 and a line end for each line feed, without the control functions. ~/ at its start is your home folder. Empty: no log. At most 255 bytes. |
empty |
background-image |
A picture file drawn behind the text, at most 255 bytes; ~/ at its start is your home folder; empty: none. The widget reads PNG, JPEG, GIF (its first frame), BMP and XPM, in its jailed worker. The picture covers the view and keeps its shape: what does not fit is cut off equally at the left and right, or at the top and bottom. The file is read again when a theme names another file, and when the file changes (the widget looks at most once a second, while it paints). |
empty |
background-opacity |
With a background picture: how much of the background color covers it, 0 to 100; a larger number counts as 100. | 85 |
window-ops |
1: a program can show, iconify, move, size, raise, lower, maximize and make full screen the window, ask whether it is an icon, where it is and how large the screen is, and read its title and icon name (terminal). and change the number of lines and columns (CSI 8 t, DECSLPP, DECSCPP, DECSNLS). Without it, a program can still ask the sizes of the text and the cell, and save and restore the title. See The Host Functions. |
0 |
print-command |
The shell command (run by /bin/sh) that gets what a program prints on its standard input, for example lpr. The widget gathers what a print job sends and gives it to the command when the job ends. Empty: the terminal has no printer. At most 255 bytes. |
empty |
The widget opens the log file when it gets a theme with hosho_widget_set_terminal_theme(), when the Xtk theme changes for a widget with no theme of its own, and when the user changes the font's size; the theme given to hosho_widget_create() does not open it by itself. A program that wants the log from the start gives the theme again with hosho_widget_set_terminal_theme() after it creates the widget.
8. The built-in themes
Four themes are part of the library, each a few lines that the fallbacks complete. hosho_theme_builtin_names lists them, and themes/ has each written with every key.
| Name | What it is | Its own keys |
|---|---|---|
Hosho Dark |
Dark grey with clear colors. | background #1B1D21, text #D7DAE0, selection #3A4455, cursor #D7DAE0 |
Hosho Light |
Near white with dark text. | background #FAFAF7, text #2A2C33, selection #CFDDF5, cursor #2A2C33 |
Sumi |
Ink: warm black, text the color of old paper, a red seal for the cursor. | background #14110F, text #E6DFD3, selection #5A4636, cursor #C8553D, cursor-text #14110F, prompt-line #1D1916; black #1D1916, white #BDB4A6, bright-black #6E6457, bright-white #FFF8EC |
Washi |
Paper: warm white, ink for the text, a red seal for the cursor. | background #F4EFE4, text #3B3228, selection #D2BF9C, cursor #A63D2A, cursor-text #F4EFE4, prompt-line #ECE5D6; black #3B3228, white #C9BFAE, bright-black #7A6E60, bright-white #FFFBF2 |
9. An editor theme is a terminal theme too
A theme file of Unryu's editor themes can be given as a terminal theme, so the terminal looks as the editor does. Hosho reads the keys of its [editor] section that a terminal has a use for (background, text, selection, selection-text, caret, line-numbers, compiler-error, compiler-success) and link of its [syntax] section. They are fallbacks only: each [terminal] key the file has wins over them, as the table of section 3 shows. An editor key is taken only when it is a color (an editor's syntax or - is left for the fallback), and an editor theme's selection text is taken only together with its selection. These colors are not written back as editor keys: hosho_theme_write() writes the [terminal] keys they gave.
A widget that is given no terminal theme makes one from the Xtk theme: the background, text, selection, selection text and cursor of Xtk's text view, and the fallbacks for the rest. It makes it again each time the host gives it another Xtk theme with hosho_widget_set_theme().
demo/hosho_demo -t ../unryu/editor_themes/Gruvbox.conf
10. The functions
| Function | What it does |
|---|---|
hosho_theme_read(theme, path) |
Reads a theme file: an empty theme, the file's keys, then the fallbacks. Returns 1 when the file was read, 0 when it could not be opened; the theme is then the default (all fallbacks). It reads into one buffer of its own, so two threads must not read themes at the same time. |
hosho_theme_builtin(name, theme) |
Gives a built-in theme, complete. Returns 0 when no built-in theme has that name; the theme is then the default. |
hosho_theme_init(theme) |
Makes a theme empty: no key present, each setting "not said". |
hosho_theme_parse(theme, text, length) |
Reads a theme from text into a theme; keys the text does not have stay as they are, so a host can lay one text over another. Returns the number of keys read with a correct value. |
hosho_theme_resolve(theme) |
Fills each item and setting the theme left out, each fallback after what it is made from. A theme from hosho_theme_parse() needs this before it is used. |
hosho_theme_write(theme, file) |
Writes a theme file with every key and a line of words above each, then the rules. Returns 0 when a write failed. |
hosho_theme_apply(theme, terminal) |
Gives a terminal what the theme says of it: the default colors and the cursor's color, the 16 palette colors, the cursor's shape and blink, the answerback message, the keyboard and the function keys' set, and the permissions for the window functions and the clipboard. |
hosho_theme_item_section(), hosho_theme_item_key(), hosho_theme_item_kind() |
The section, the key and the kind (one color, or a style) of a HoshoThemeItem, for a host that shows the items in a dialog. |
A HoshoTheme has the name and description, an item for each color and style (items, indexed by HoshoThemeItem, in the order of the file), the settings, the editor colors it read, and the rules. An item is a HoshoThemeStyle: foreground and background as 0xRRGGBB, has_foreground and has_background (0 for - or none), bold, italic, and present. A color item uses only its foreground. A host that changes a key changes the item or setting and sets the theme again; the widget copies the theme it is given.
Hosho API
The whole library
From bytes to a screen
For the host that shows it
The program