summaryrefslogtreecommitdiff
path: root/book/src/themes.md
blob: 2d347176eba50c31a3bc4bfcf44779bfb63a9246 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
150
151
152
153
154
155
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# Themes

To use a theme add `theme = "<name>"` to the top of your [`config.toml`](./configuration.md) file, or select it during runtime using `:theme <name>`.

## Creating a theme

Create a file with the name of your theme as the file name (i.e `mytheme.toml`) and place it in your `themes` directory (i.e `~/.config/helix/themes` or `%AppData%\helix\themes` on Windows). The directory might have to be created beforehand.

> 💡 The names "default" and "base16_default" are reserved for built-in themes
> and cannot be overridden by user-defined themes.

### Overview

Each line in the theme file is specified as below:

```toml
key = { fg = "#ffffff", bg = "#000000", underline = { color = "#ff0000", style = "curl"}, modifiers = ["bold", "italic"] }
```

Where `key` represents what you want to style, `fg` specifies the foreground color, `bg` the background color, `underline` the underline `style`/`color`, and `modifiers` is a list of style modifiers. `bg`, `underline` and `modifiers` can be omitted to defer to the defaults.

To specify only the foreground color:

```toml
key = "#ffffff"
```

If the key contains a dot `'.'`, it must be quoted to prevent it being parsed as a [dotted key](https://toml.io/en/v1.0.0#keys).

```toml
"key.key" = "#ffffff"
```

For inspiration, you can find the default `theme.toml`
[here](https://github.com/helix-editor/helix/blob/master/theme.toml) and
user-submitted themes
[here](https://github.com/helix-editor/helix/blob/master/runtime/themes).

### Using the linter

Use the supplied linting tool to check for errors and missing scopes:

```sh
cargo xtask themelint onedark # replace onedark with <name>
```

## The details of theme creation

### Color palettes

It's recommended to define a palette of named colors, and refer to them in the
configuration values in your theme. To do this, add a table called
`palette` to your theme file:

```toml
"ui.background" = "white"
"ui.text" = "black"

[palette]
white = "#ffffff"
black = "#000000"
```

Keep in mind that the `[palette]` table includes all keys after its header,
so it should be defined after the normal theme options.

The default palette uses the terminal's default 16 colors, and the colors names
are listed below. The `[palette]` section in the config file takes precedence
over it and is merged into the default palette.

| Color Name      |
| ---             |
| `default`       |
| `black`         |
| `red`           |
| `green`         |
| `yellow`        |
| `blue`          |
| `magenta`       |
| `cyan`          |
| `gray`          |
| `light-red`     |
| `light-green`   |
| `light-yellow`  |
| `light-blue`    |
| `light-magenta` |
| `light-cyan`    |
| `light-gray`    |
| `white`         |

### Modifiers

The following values may be used as modifier, provided they are supported by
your terminal emulator.

| Modifier             |
| ---                  |
| `bold`               |
| `dim`                |
| `italic`             |
| `underlined`         |
| `slow_blink`         |
| `rapid_blink`        |
| `reversed`           |
| `hidden`             |
| `crossed_out`        |

> 💡 The `underlined` modifier is deprecated and only available for backwards compatibility.
> Its behavior is equivalent to setting `underline.style="line"`.

### Underline style

One of the following values may be used as a value for `underline.style`, providing it is
supported by your terminal emulator.

| Modifier       |
| ---            |
| `line`         |
| `curl`         |
| `dashed`       |
| `dotted`       |
| `double_line`  |


### Inheritance

Extend other themes by setting the `inherits` property to an existing theme.

```toml
inherits = "boo_berry"

# Override the theming for "keyword"s:
"keyword" = { fg = "gold" }

# Override colors in the palette:
[palette]
berry = "#2A2A4D"
```

### Rainbow

The `rainbow` key is used for rainbow highlight for matching brackets.
The key is a list of styles.

```toml
rainbow = ["#ff0000", "#ffa500", "#fff000", { fg = "#00ff00", modifiers = ["bold"] }]
```

Colors from the palette and modifiers may be used.

### Scopes

The following is a list of scopes available to use for styling:

#### Syntax highlighting

These keys match [tree-sitter scopes](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#theme).

When determining styling for a highlight, the longest matching theme key will be used. For example, if the highlight is `function.builtin.static`, the key `function.builtin` will be used instead of `function`.

We use a similar set of scopes as
[Sublime Text](https://www.sublimetext.com/docs/scope_naming.html). See also
[TextMate](https://macromates.com/manual/en/language_grammars) scopes.

- `attribute` - Class attributes, HTML tag attributes

- `type` - Types
  - `builtin` - Primitive types provided by the language (`int`, `usize`)
  - `enum`
    - `variant`
- `constructor`

- `constant` (TODO: constant.other.placeholder for `%v`)
  - `builtin` Special constants provided by the language (`true`, `false`, `nil` etc)
    - `boolean`
  - `character`
    - `escape`
  - `numeric` (numbers)
    - `integer`
    - `float`

- `string` (TODO: string.quoted.{single, double}, string.raw/.unquoted)?
  - `regexp` - Regular expressions
  - `special`
    - `path`
    - `url`
    - `symbol` - Erlang/Elixir atoms, Ruby symbols, Clojure keywords

- `comment` - Code comments
  - `line` - Single line comments (`//`)
  - `block` - Block comments (e.g. (`/* */`)
    - `documentation` - Documentation comments (e.g. `///` in Rust)

- `variable` - Variables
  - `builtin` - Reserved language variables (`self`, `this`, `super`, etc.)
  - `parameter` - Function parameters
  - `other`
    - `member` - Fields of composite data types (e.g. structs, unions)

- `label`

- `punctuation`
  - `delimiter` - Commas, colons
  - `bracket` - Parentheses, angle brackets, etc.
  - `special` - String interpolation brackets.

- `keyword`
  - `control`
    - `conditional` - `if`, `else`
    - `repeat` - `for`, `while`, `loop`
    - `import` - `import`, `export`
    - `return`
    - `exception`
  - `operator` - `or`, `in`
  - `directive` - Preprocessor directives (`#if` in C)
  - `function` - `fn`, `func`
  - `storage` - Keywords describing how things are stored
    - `type` - The type of something, `class`, `function`, `var`, `let`, etc.
    - `modifier` - Storage modifiers like `static`, `mut`, `const`, `ref`, etc.

- `operator` - `||`, `+=`, `>`

- `function`
  - `builtin`
  - `method`
  - `macro`
  - `special` (preprocessor in C)

- `tag` - Tags (e.g. `<body>` in HTML)
  - `builtin`

- `namespace`

- `special`

- `markup`
  - `heading`
    - `marker`
    - `1`, `2`, `3`, `4`, `5`, `6` - heading text for h1 through h6
  - `list`
    - `unnumbered`
    - `numbered`
    - `checked`
    - `unchecked`
  - `bold`
  - `italic`
  - `strikethrough`
  - `link`
    - `url` - URLs pointed to by links
    - `label` - non-URL link references
    - `text` - URL and image descriptions in links
  - `quote`
  - `raw`
    - `inline`
    - `block`

- `diff` - version control changes
  - `plus` - additions
    - `gutter` - gutter indicator
  - `minus` - deletions
    - `gutter` - gutter indicator
  - `delta` - modifications
    - `moved` - renamed or moved files/changes
    - `gutter` - gutter indicator

#### Interface

These scopes are used for theming the editor interface:

- `markup`
  - `normal`
    - `completion` - for completion doc popup UI
    - `hover` - for hover popup UI
  - `heading`
    - `completion` - for completion doc popup UI
    - `hover` - for hover popup UI
  - `raw`
    - `inline`
      - `completion` - for completion doc popup UI
      - `hover` - for hover popup UI


| Key                               | Notes                                                                                          |
| ---                               | ---                                                                                            |
| `ui.background`                   |                                                                                                |
| `ui.background.separator`         | Picker separator below input line                                                              |
| `ui.cursor`                       |                                                                                                |
| `ui.cursor.normal`                |                                                                                                |
| `ui.cursor.insert`                |                                                                                                |
| `ui.cursor.select`                |                                                                                                |
| `ui.cursor.match`                 | Matching bracket etc.                                                                          |
| `ui.cursor.primary`               | Cursor with primary selection                                                                  |
| `ui.cursor.primary.normal`        |                                                                                                |
| `ui.cursor.primary.insert`        |                                                                                                |
| `ui.cursor.primary.select`        |                                                                                                |
| `ui.debug.breakpoint`             | Breakpoint indicator, found in the gutter                                                      |
| `ui.debug.active`                 | Indicator for the line at which debugging execution is paused at, found in the gutter          |
| `ui.gutter`                       | Gutter                                                                                         |
| `ui.gutter.selected`              | Gutter for the line the cursor is on                                                           |
| `ui.highlight.frameline`          | Line at which debugging execution is paused at                                                 |
| `ui.linenr`                       | Line numbers                                                                                   |
| `ui.linenr.selected`              | Line number for the line the cursor is on                                                      |
| `ui.statusline`                   | Statusline                                                                                     |
| `ui.statusline.inactive`          | Statusline (unfocused document)                                                                |
| `ui.statusline.normal`            | Statusline mode during normal mode ([only if `editor.color-modes` is enabled][editor-section]) |
| `ui.statusline.insert`            | Statusline mode during insert mode ([only if `editor.color-modes` is enabled][editor-section]) |
| `ui.statusline.select`            | Statusline mode during select mode ([only if `editor.color-modes` is enabled][editor-section]) |
| `ui.statusline.separator`         | Separator character in statusline                                                              |
| `ui.popup`                        | Documentation popups (e.g. Space + k)                                                          |
| `ui.popup.info`                   | Prompt for multiple key options                                                                |
| `ui.window`                       | Borderlines separating splits                                                                  |
| `ui.help`                         | Description box for commands                                                                   |
| `ui.text`                         | Command prompts, popup text, etc.                                                              |
| `ui.text.focus`                   | The currently selected line in the picker                                                      |
| `ui.text.inactive`                | Same as `ui.text` but when the text is inactive (e.g. suggestions)                             |
| `ui.text.info`                    | The key: command text in `ui.popup.info` boxes                                                 |
| `ui.virtual.ruler`                | Ruler columns (see the [`editor.rulers` config][editor-section])                               |
| `ui.virtual.whitespace`           | Visible whitespace characters                                                                  |
| `ui.virtual.indent-guide`         | Vertical indent width guides                                                                   |
| `ui.virtual.inlay-hint`           | Default style for inlay hints of all kinds                                                     |
| `ui.virtual.inlay-hint.parameter` | Style for inlay hints of kind `parameter` (LSPs are not required to set a kind)                |
| `ui.virtual.inlay-hint.type`      | Style for inlay hints of kind `type` (LSPs are not required to set a kind)                     |
| `ui.virtual.wrap`                 | Soft-wrap indicator (see the [`editor.soft-wrap` config][editor-section])                      |
| `ui.menu`                         | Code and command completion menus                                                              |
| `ui.menu.selected`                | Selected autocomplete item                                                                     |
| `ui.menu.scroll`                  | `fg` sets thumb color, `bg` sets track color of scrollbar                                      |
| `ui.selection`                    | For selections in the editing area                                                             |
| `ui.selection.primary`            |                                                                                                |
| `ui.highlight`                    | Highlighted lines in the picker preview                                                        |
| `ui.cursorline.primary`           | The line of the primary cursor ([if cursorline is enabled][editor-section])                    |
| `ui.cursorline.secondary`         | The lines of any other cursors ([if cursorline is enabled][editor-section])                    |
| `ui.cursorcolumn.primary`         | The column of the primary cursor ([if cursorcolumn is enabled][editor-section])                |
| `ui.cursorcolumn.secondary`       | The columns of any other cursors ([if cursorcolumn is enabled][editor-section])                |
| `warning`                         | Diagnostics warning (gutter)                                                                   |
| `error`                           | Diagnostics error (gutter)                                                                     |
| `info`                            | Diagnostics info (gutter)                                                                      |
| `hint`                            | Diagnostics hint (gutter)                                                                      |
| `diagnostic`                      | Diagnostics fallback style (editing area)                                                      |
| `diagnostic.hint`                 | Diagnostics hint (editing area)                                                                |
| `diagnostic.info`                 | Diagnostics info (editing area)                                                                |
| `diagnostic.warning`              | Diagnostics warning (editing area)                                                             |
| `diagnostic.error`                | Diagnostics error (editing area)                                                               |

[editor-section]: ./configuration.md#editor-section