Skip to content

Commit ac76b22

Browse files
authored
Fix and extend color documentation (nushell#1773)
* Fix and extend color documentation * Drop ambiguous hash label - works just fine with only the symbol `#` * Clarify when it is commented out vs may be (hex) value * Drop text table of contents; the website has it's own sidebar table of contents / headline jump list * Fix headline levels - the general color declaration docs were under Table Borders, and hex and full hex were not on the same level * Introduce/Rename main section 'Color Configuration' * Show command to print the current configuration * Add closure declaration format documentation * Drop separators following headlines; other headlines do not have this, they make no logical sense, and they lead to double-separator-lines being rendered on the website Resolves nushell#1503 * Improve limited closure execution note * Add missing bool closure example Was intended and result is described below. * Improve closure string return description * Be more specific about color description
1 parent e94eabc commit ac76b22

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

book/coloring_and_theming.md

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Coloring and Theming in Nu
22

3-
Many parts of Nushell's interface can have their color customized. All of these can be set in the `config.nu` configuration file. If you see the hash/hashtag/pound mark `#` in the config file it means the text after it is commented out.
4-
5-
1. table borders
6-
2. primitive values
7-
3. shapes (this is the command line syntax)
8-
4. prompt
9-
5. LS_COLORS
3+
Many parts of Nushell's interface can have their color customized. All of these can be set in the `config.nu` configuration file. If you see the `#` outside of a text value in the config file it means the text after it is commented out.
104

115
## Table Borders
126

@@ -34,21 +28,27 @@ Here are the current options for `$env.config.table.mode`:
3428
- `none`
3529
- `other`
3630

37-
### Color Symbologies
31+
## Color Configuration
32+
33+
The color configuration is defined in `$env.config.color_config`. The current configuration can be printed with:
34+
35+
```nu
36+
$env.config.color_config | sort
37+
```
3838

39-
---
39+
The color and style-attributes can be declared in multiple alternative formats.
4040

4141
- `r` - normal color red's abbreviation
4242
- `rb` - normal color red's abbreviation with bold attribute
4343
- `red` - normal color red
4444
- `red_bold` - normal color red with bold attribute
4545
- `"#ff0000"` - "#hex" format foreground color red (quotes are required)
4646
- `{ fg: "#ff0000" bg: "#0000ff" attr: b }` - "full #hex" format foreground red in "#hex" format with a background of blue in "#hex" format with an attribute of bold abbreviated.
47+
- `{|x| 'yellow' }` - closure returning a string with one of the color representations listed above
48+
- `{|x| { fg: "#ff0000" bg: "#0000ff" attr: b } }` - closure returning a valid record
4749

4850
### Attributes
4951

50-
---
51-
5252
| code | meaning |
5353
| ---- | ------------------- |
5454
| l | blink |
@@ -197,17 +197,13 @@ Here are the current options for `$env.config.table.mode`:
197197

198198
### `"#hex"` Format
199199

200-
---
201-
202200
The "#hex" format is one way you typically see colors represented. It's simply the `#` character followed by 6 characters. The first two are for `red`, the second two are for `green`, and the third two are for `blue`. It's important that this string be surrounded in quotes, otherwise Nushell thinks it's a commented out string.
203201

204202
Example: The primary `red` color is `"#ff0000"` or `"#FF0000"`. Upper and lower case in letters shouldn't make a difference.
205203

206204
This `"#hex"` format allows us to specify 24-bit truecolor tones to different parts of Nushell.
207205

208-
## Full `"#hex"` Format
209-
210-
---
206+
### Full `"#hex"` Format
211207

212208
The `full "#hex"` format is a take on the `"#hex"` format but allows one to specify the foreground, background, and attributes in one line.
213209

@@ -217,9 +213,33 @@ Example: `{ fg: "#ff0000" bg: "#0000ff" attr: b }`
217213
- background of blue in "#hex" format
218214
- attribute of bold abbreviated
219215

220-
## Primitive Values
216+
### Closure
221217

222-
---
218+
Note: Closures are only executed for table output. They do not work in other contexts like for `shape_` configurations, when printing a value directly, or as a value in a list.
219+
220+
For example:
221+
222+
```nu
223+
$env.config.color_config.filesize = {|x| if $x == 0b { 'dark_gray' } else if $x < 1mb { 'cyan' } else { 'blue' } }
224+
$env.config.color_config.bool = {|x| if $x { 'green' } else { 'light_red' } }
225+
{a:true,b:false,c:0mb,d:0.5mb,e:10mib}
226+
```
227+
228+
prints
229+
230+
```nu
231+
╭───┬───────────╮
232+
│ a │ true │
233+
│ b │ false │
234+
│ c │ 0 B │
235+
│ d │ 488.3 KiB │
236+
│ e │ 10.0 MiB │
237+
╰───┴───────────╯
238+
```
239+
240+
with a green `true`, a light red `false`, a dark grey `0 B`, a cyan `488.3 KiB`, and a blue `10.0 MiB`.
241+
242+
## Primitive Values
223243

224244
Primitive values are things like `int` and `string`. Primitive values and shapes can be set with a variety of color symbologies seen above.
225245

@@ -256,7 +276,7 @@ This is the current list of primitives. Not all of these are configurable. The c
256276
| `vardecl` | | |
257277
| `variable` | | |
258278

259-
#### Special "primitives" (not really primitives but they exist solely for coloring)
279+
### Special "primitives" (not really primitives but they exist solely for coloring)
260280

261281
| primitive | default color | configurable |
262282
| --------------------------- | -------------------------- | ------------ |

0 commit comments

Comments
 (0)