Home Explore Blog CI



nushell

3rd chunk of `book/coloring_and_theming.md`
ab05ad30aadbcc0a8a67604f22eea3815604ab801133459f000000010000100f
| `lpi`     | `light_purple_italic`     |
| `lpd`     | `light_purple_dimmed`     |
| `lpr`     | `light_purple_reverse`    |
| `bg_lp`   | `bg_light_purple`         |
| `m`       | `magenta`                 |
| `mb`      | `magenta_bold`            |
| `mu`      | `magenta_underline`       |
| `mi`      | `magenta_italic`          |
| `md`      | `magenta_dimmed`          |
| `mr`      | `magenta_reverse`         |
| `bg_m`    | `bg_magenta`              |
| `lm`      | `light_magenta`           |
| `lmb`     | `light_magenta_bold`      |
| `lmu`     | `light_magenta_underline` |
| `lmi`     | `light_magenta_italic`    |
| `lmd`     | `light_magenta_dimmed`    |
| `lmr`     | `light_magenta_reverse`   |
| `bg_lm`   | `bg_light_magenta`        |
| `c`       | `cyan`                    |
| `cb`      | `cyan_bold`               |
| `cu`      | `cyan_underline`          |
| `ci`      | `cyan_italic`             |
| `cd`      | `cyan_dimmed`             |
| `cr`      | `cyan_reverse`            |
| `bg_c`    | `bg_cyan`                 |
| `lc`      | `light_cyan`              |
| `lcb`     | `light_cyan_bold`         |
| `lcu`     | `light_cyan_underline`    |
| `lci`     | `light_cyan_italic`       |
| `lcd`     | `light_cyan_dimmed`       |
| `lcr`     | `light_cyan_reverse`      |
| `bg_lc`   | `bg_light_cyan`           |
| `w`       | `white`                   |
| `wb`      | `white_bold`              |
| `wu`      | `white_underline`         |
| `wi`      | `white_italic`            |
| `wd`      | `white_dimmed`            |
| `wr`      | `white_reverse`           |
| `bg_w`    | `bg_white`                |
| `dgr`     | `dark_gray`               |
| `dgrb`    | `dark_gray_bold`          |
| `dgru`    | `dark_gray_underline`     |
| `dgri`    | `dark_gray_italic`        |
| `dgrd`    | `dark_gray_dimmed`        |
| `dgrr`    | `dark_gray_reverse`       |
| `bg_dgr`  | `bg_dark_gray`            |
| `def`     | `default`                 |
| `defb`    | `default_bold`            |
| `defu`    | `default_underline`       |
| `defi`    | `default_italic`          |
| `defd`    | `default_dimmed`          |
| `defr`    | `default_reverse`         |
| `bg_def`  | `bg_default`              |

<!-- The table body can be printed with ansi --list | select 'short name' name | each {|| $"| `($in.'short name')` | `($in.name)` |"} | first 133 | str join "\n" -->

### `"#hex"` Format

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.

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

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

### Full `"#hex"` Format

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

Example: `{ fg: "#ff0000" bg: "#0000ff" attr: b }`

- foreground of red in "#hex" format
- background of blue in "#hex" format
- attribute of bold abbreviated

### Closure

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.

For example:

```nu
$env.config.color_config.filesize = {|x| if $x == 0b { 'dark_gray' } else if $x < 1mb { 'cyan' } else { 'blue' } }
$env.config.color_config.bool = {|x| if $x { 'green' } else { 'light_red' } }
{a:true,b:false,c:0mb,d:0.5mb,e:10mib}
```

prints

```nu
╭───┬───────────╮
│ a │ true      │
│ b │ false     │
│ c │ 0 B       │
│ d │ 488.3 KiB │
│ e │ 10.0 MiB  │
╰───┴───────────╯
```

with a green `true`, a light red `false`, a dark grey `0 B`, a cyan `488.3 KiB`, and a blue `10.0 MiB`.

## Primitive Values

Title: Color Configuration Options: Colors, Hex Codes, and Closures
Summary
This section details the available color configuration options in Nushell. It lists normal color codes (cyan, white, dark gray, default), their variations (bold, underline, italic, dimmed, reverse), and background color options. It then explains how to use hexadecimal color codes ('#hex' format) to specify colors, including a 'full #hex' format for foreground, background, and attributes. Finally, it describes how to use closures to dynamically set colors based on conditions for table output.