Skip to content

Commit

Permalink
Recover non-lemnos themes (#902)
Browse files Browse the repository at this point in the history
Changes:

* Custom Nushell `color_config`'s (non-Lemnos) are moved to the
`./src/custom-nu-themes` directory and used to generate the main theme
files when doing a `./make.nu`
* `make.nu` and other scripts (e.g. preview) have been moved to the
`src` directory
* A separate `README` for the `src` scripts
* Main theme `README` updated for clarity
* Reordered the theme template, so all themes were regenerated. I'd like
to stop doing this ;-)

@amtoine Thanks for your suggestions on the `README`. I've pretty
extensively changed the flow, so please re-review and let me know how it
looks. Also note that I haven't personally tested with Nupm, so please
especially review this section. Thanks!

@fdncred CC

Still planning on working on the preview scripts next. They'll need only
slight changes to run (probably a path change), but they can be
simplified a bit now, I hope. At the same time, I'll complicate them in
other ways ;-).

Note that there is a bug in both `nushell-dark` and `nushell-light` that
prevented the terminal colors from being updated regardless. You can see
that in the existing screenshots, where both those themes simply re-use
the previous theme (alphabetically's) background. I haven't fixed this
yet.
  • Loading branch information
NotTheDr01ds committed Jul 19, 2024
1 parent bd1ab4e commit 8557653
Show file tree
Hide file tree
Showing 465 changed files with 13,081 additions and 11,811 deletions.
108 changes: 71 additions & 37 deletions themes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,114 @@

Credit to @lemnos and [all contributors](https://github.com/lemnos/theme.sh/blob/master/CREDITS.md).

## Use a colorscheme
### Without Nupm
Note:

To list all the themes, from the root of the repository run:
* If using Nupm, or the `<package_root>/themes` directory of this package/repository is in your `$env.NU_LIB_DIRS`, then most of the commands below can be run from anywhere on your system.
* Otherwise, all examples assume they are run from the `<package_root>/themes` directory.

```rust
ls ./themes/nu-themes
## Basic usage
### Activate a colorscheme

```nu
source nu-themes/<theme>.nu
```

To use the `dracula` theme for instance, please run:
For example, to use the `dracula` theme:

```rust
source ./themes/nu-themes/dracula.nu
```nu
source nu-themes/dracula.nu
```

The theme should be activated!

### Using Nupm
Note that these settings are for the current shell only.

1. Install [Nupm] by following the [Nupm instructions]
2. Download the `nu_scripts` repository
### Making changes permanent

```shell
git clone https://github.com/nushell/nu_scripts
```
Add the command above to your `config.nu` file as shown in [the Configuration chapter of The Book](https://www.nushell.sh/book/configuration.html).

3. Activate the `nupm` module with `use nupm`
4. Install the `nu-scripts` package
Note that, if not using Nupm or a `NU_LIB_DIR` path, you should use the fully qualified path to the themes directory on your system. For example:

```nushell
nupm install --path --force nu_scripts
```
```nu
source ~/nu_scripts/themes/nu-themes/dracula.nu
```

> **Note**
> installing the `nu-scripts` package will install `nu-themes` and other modules
### List all themes

5. Add the following in your config, substituting the `theme_name` as desired:
Currently, this is done by simply manually listing the contents of the `nu-themes` directory:

```nushell
source nu-themes/<theme_name>.nu
```
```nu
ls <package_root>/themes/nu-themes
```

## Advanced

## Loading a theme's color_config
Themes are composed of two parts:

When sourcing the theme, as above, the theme will:
* A Nushell `color_config` record which is used to set `$env.config.color_config`
* A command to update your terminal's foreground, background, and cursor colors. While this assumes that your terminal supports the appropriate OSC codes, the codes need are very basic and should be supported by most any terminal.

* Set Nushell's `$env.config.color_config` to the appropriate theme colors
* If supported, set your terminal's foreground, background, and cursor colors to match the theme
You may wish to set the Nushell `color_config` without changing your terminal's colors, or vice-versa. These themes provide additional commands that allow you to accomplish this.

If you would like to do *just* one or the other, you can load a theme's color definition and terminal settings separately.
**Important:** Notice that while the "Basic usage" above uses `source` to activate the theme, the following examples *import* the theme module with a `use` statement.

### Load a color_config

For example, to load and use the `tokyo-night` theme's colors:
For example, to load and use the `tokyo-night` theme's colors without changing the terminal settings:

```nushell
> use nu-themes/tokyo-night.nu *
# Display the values
#### Display a theme's `color_config` settings

```nu
> use nu-themes/tokyo-night.nu
> tokyo-night
# Set the color_config to that scheme
```

#### Activate a Nushell `color_config`

```nu
> use nu-themes/tokyo-night.nu
> tokyo-night set color_config
# Or
```

or

```nu
> use nu-themes/tokyo-night.nu
> $env.config.color_config = (tokyo-night)
```

### Set terminal colors

Or you can change the terminal settings to use the theme's foreground/background/cursor colors without changing the Nushell `color_config`.

Again, using the `tokyo-night` theme as an example:

```nushell
> use nu-themes/tokyo-night.nu *
> use nu-themes/tokyo-night.nu
> tokyo-night update terminal
```

## Using Nupm

The parent `nu_scripts` package can be installed and updated using [Nupm].

1. Install [Nupm] by following the [Nupm instructions]
2. Download the `nu_scripts` repository

```shell
git clone https://github.com/nushell/nu_scripts
```

3. Activate the `nupm` module with `use nupm`
4. Install the `nu-scripts` package

```nushell
nupm install --path --force nu_scripts
```

> **Note**
> installing the `nu-scripts` package will install `nu-themes` and other modules

## Screenshots

Here are [screenshots](./screenshots/README.md) of our themes.
Expand Down
177 changes: 0 additions & 177 deletions themes/make.nu

This file was deleted.

52 changes: 26 additions & 26 deletions themes/nu-themes/3024-day.nu
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
# Update terminal colors
export def "update terminal" [] {
let theme = (main)

# Set terminal colors
let osc_screen_foreground_color = '10;'
let osc_screen_background_color = '11;'
let osc_cursor_color = '12;'

$"
(ansi -o $osc_screen_foreground_color)($theme.foreground)(char bel)
(ansi -o $osc_screen_background_color)($theme.background)(char bel)
(ansi -o $osc_cursor_color)($theme.cursor)(char bel)
"
# Line breaks above are just for source readability
# but create extra whitespace when activating. Collapse
# to one line
| str replace --all "\n" ''
| print $in
}

# Update the Nushell configuration
export def --env "set color_config" [] {
$env.config.color_config = (main)
}

# Retrieve the theme settings
export def main [] {
return {
Expand Down Expand Up @@ -110,6 +84,32 @@ export def main [] {
}
}

# Update the Nushell configuration
export def --env "set color_config" [] {
$env.config.color_config = (main)
}

# Update terminal colors
export def "update terminal" [] {
let theme = (main)

# Set terminal colors
let osc_screen_foreground_color = '10;'
let osc_screen_background_color = '11;'
let osc_cursor_color = '12;'

$"
(ansi -o $osc_screen_foreground_color)($theme.foreground)(char bel)
(ansi -o $osc_screen_background_color)($theme.background)(char bel)
(ansi -o $osc_cursor_color)($theme.cursor)(char bel)
"
# Line breaks above are just for source readability
# but create extra whitespace when activating. Collapse
# to one line
| str replace --all "\n" ''
| print $in
}

export module activate {
export-env {
set color_config
Expand Down
Loading

0 comments on commit 8557653

Please sign in to comment.