diff --git a/README.md b/README.md index 7bf8c2f..072231a 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,12 @@ let in {} ``` +You can also use the `visualize.nu` script to visualize any theme in the terminal: + +```nu +./visualize.nu themes/chalk.nix +``` +
All themes diff --git a/generate-themes.nu b/generate-themes.nu index dffce1b..ac6902c 100755 --- a/generate-themes.nu +++ b/generate-themes.nu @@ -2,7 +2,7 @@ def theme-to-nix [ theme: record, # The theme to convert to Nix. -] { +] -> nothing { $theme | items { |key, value| let key = match $key { diff --git a/visualize.nu b/visualize.nu new file mode 100755 index 0000000..ca4101a --- /dev/null +++ b/visualize.nu @@ -0,0 +1,33 @@ +#!/usr/bin/env nu + +# Visualizes a theme in the terminal. +def main [ + theme: string, # The path to the theme to visualize. +] -> nothing { + if not ($env.COLORTERM | str contains "truecolor") { + echo "your terminal emulator doesn't support truecolor, colors may be wrong\n" + } + + let theme = open $theme + | str replace --all ";" "," + | str replace --all "=" ":" + | from json + + $theme + | reject name author + | transpose name value + | each { |it| + let hex = ("0x" + $in.value) | into int + + let r = $hex bit-shr 16 + let g = $hex bit-shr 8 bit-and 0xFF + let b = $hex bit-and 0xFF + + $it | merge { value: $"\\033[48;2;($r);($g);($b)m" } + } + | each { |it| + ^echo -e $"($it.name): ($it.value) \\033[0m" + } + + $"\n($theme.name) by ($theme.author)" +}