Home Explore Blog CI



nushell

9th chunk of `book/coloring_and_theming.md`
ed47fe5c1d05d705dca9ed821c92df5caf9c6e19f0a780cf0000000100000f2f
let base09 = "#dc9656" # Integers, Boolean, Constants, XML Attributes, Markup Link Url
let base0a = "#f7ca88" # Classes, Markup Bold, Search Text Background
let base0b = "#a1b56c" # Strings, Inherited Class, Markup Code, Diff Inserted
let base0c = "#86c1b9" # Support, Regular Expressions, Escape Characters, Markup Quotes
let base0d = "#7cafc2" # Functions, Methods, Attribute IDs, Headings
let base0e = "#ba8baf" # Keywords, Storage, Selector, Markup Italic, Diff Changed
let base0f = "#a16946" # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>

# we're creating a theme here that uses the colors we defined above.

let base16_theme = {
    separator: $base03
    leading_trailing_space_bg: $base04
    header: $base0b
    date: $base0e
    filesize: $base0d
    row_index: $base0c
    bool: $base08
    int: $base0b
    duration: $base08
    range: $base08
    float: $base08
    string: $base04
    nothing: $base08
    binary: $base08
    cellpath: $base08
    hints: dark_gray

    # shape_garbage: { fg: $base07 bg: $base08 attr: b} # base16 white on red
    # but i like the regular white on red for parse errors
    shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b}
    shape_bool: $base0d
    shape_int: { fg: $base0e attr: b}
    shape_float: { fg: $base0e attr: b}
    shape_range: { fg: $base0a attr: b}
    shape_internalcall: { fg: $base0c attr: b}
    shape_external: $base0c
    shape_externalarg: { fg: $base0b attr: b}
    shape_literal: $base0d
    shape_operator: $base0a
    shape_signature: { fg: $base0b attr: b}
    shape_string: $base0b
    shape_filepath: $base0d
    shape_globpattern: { fg: $base0d attr: b}
    shape_variable: $base0e
    shape_flag: { fg: $base0d attr: b}
    shape_custom: {attr: b}
}

# now let's apply our regular config settings but also apply the "color_config:" theme that we specified above.

let config = {
  filesize_metric: true
  table_mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
  use_ls_colors: true
  color_config: $base16_theme # <-- this is the theme
  use_grid_icons: true
  footer_mode: always #always, never, number_of_rows, auto
  animate_prompt: false
  float_precision: 2
  use_ansi_coloring: true
  filesize_format: "b" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, auto
  edit_mode: emacs # vi
  max_history_size: 10000
  log_level: error
}
```

if you want to go full-tilt on theming, you'll want to theme all the items I mentioned at the very beginning, including LS_COLORS, and the prompt. Good luck!

### Working on Light Background Terminal

Nushell's [standard library](/book/standard_library.md) contains a `config` module with default light and dark themes.
If you are working on a light background terminal, you can apply the light theme easily.

```nu
# in $nu.config-path
use config light-theme   # add this line to load the theme into scope

$env.config = {
  # ...
  color_config: (light_theme)   # if you want a light theme, replace `$dark_theme` to `$light_theme`
  # ...
}
```

You can also load the dark theme.

```nu
# in $nu.config-path
use config dark-theme

$env.config = {
  # ...
  color_config: (dark_theme)
  # ...
}
```

## Accessibility

It's often desired to have the minimum amount of decorations when using a screen reader. In those cases, it's possible to disable borders and other decorations for both table and errors with the following options:

```nu
# in $nu.config-path
$env.config = {
  ...
  table: {
   ...
    mode: "none"
   ...
  }
  error_style: "plain"
  ...
}
```

## Line Editor Menus (completion, history, help…)

Reedline (Nu’s line editor) style is not using the `color_config` key.
Instead, each menu has its own style to be configured separately.
See the [section dedicated to Reedline’s menus configuration](line_editor.md#menus) to learn more on this.

Title: Base16 Theme Application, Light/Dark Themes, Accessibility, and Line Editor Menus
Summary
This section demonstrates how to apply the defined Base16 theme to the Nushell configuration, including customizing specific shapes with different colors and attributes. It then explains how to easily apply light or dark themes from the Nushell standard library for better readability on different terminal backgrounds. Additionally, it covers accessibility options to minimize decorations for screen reader users and mentions that Reedline's menus have separate styling configurations.