Skip to content

Commit

Permalink
rewrite the theme generation (nushell#437)
Browse files Browse the repository at this point in the history
* remove the template

* update the theme generation script

* fix the local path to the lemnos themes

* use the real `export der main` module template

* remove the empty lines and the comments from theme files

* adapt the default config file theme to the template

This commit uses closures for `filesize`, `date` and `bool`.

* put quotes around all the colors in the template

* fix the `else` of `filesize` => returns a true record now

* use default colors for the filesize

* regenerate all the themes with `./make.nu`
  • Loading branch information
amtoine committed Apr 5, 2023
1 parent d7cdfdb commit b9ec76b
Show file tree
Hide file tree
Showing 448 changed files with 35,345 additions and 26,402 deletions.
138 changes: 111 additions & 27 deletions themes/make.nu
Original file line number Diff line number Diff line change
@@ -1,41 +1,125 @@
#!/usr/bin/env nu

let RAW = "lemnos/themes"
let SOURCE = {
dir: ([lemnos themes] | path join)
local: "lemnos"
remote: "https://github.com/lemnos/theme.sh"
}
let THEMES = "themes"


def make-theme [theme: string] {
def make-theme [name: string] {
let colors = (
open $"($RAW)/($theme)" |
lines |
split column " " |
rename name rgb
open ($SOURCE.dir | path join $name)
| lines --skip-empty
| find --invert --regex '^#'
| split column " "
| rename name rgb
| transpose -r
| into record
)
let theme_file = $"($THEMES)/($theme).nu"

cp template.nu $theme_file
$'export def main [] { return {
separator: "($colors.color7)"
leading_trailing_space_bg: { attr: "n" }
header: { fg: "($colors.color2)" attr: "b" }
empty: "($colors.color4)"
bool: {|| if $in { "($colors.color14)" } else { "light_gray" } }
int: "($colors.color7)"
filesize: {|e|
if $e == 0b {
"($colors.color7)"
} else if $e < 1mb {
"($colors.color6)"
} else {{ fg: "($colors.color4)" }}
}
duration: "($colors.color7)"
date: {|| (char lparen)date now(char rparen) - $in |
if $in < 1hr {
{ fg: "($colors.color1)" attr: "b" }
} else if $in < 6hr {
"($colors.color1)"
} else if $in < 1day {
"($colors.color3)"
} else if $in < 3day {
"($colors.color2)"
} else if $in < 1wk {
{ fg: "($colors.color2)" attr: "b" }
} else if $in < 6wk {
"($colors.color6)"
} else if $in < 52wk {
"($colors.color4)"
} else { "dark_gray" }
}
range: "($colors.color7)"
float: "($colors.color7)"
string: "($colors.color7)"
nothing: "($colors.color7)"
binary: "($colors.color7)"
cellpath: "($colors.color7)"
row_index: { fg: "($colors.color2)" attr: "b" }
record: "($colors.color7)"
list: "($colors.color7)"
block: "($colors.color7)"
hints: "dark_gray"
$colors |
each {
|it|
open $theme_file --raw |
str replace $"{{($it.name)}}" $it.rgb --all |
save $theme_file
}
shape_and: { fg: "($colors.color5)" attr: "b" }
shape_binary: { fg: "($colors.color5)" attr: "b" }
shape_block: { fg: "($colors.color4)" attr: "b" }
shape_bool: "($colors.color14)"
shape_custom: "($colors.color2)"
shape_datetime: { fg: "($colors.color6)" attr: "b" }
shape_directory: "($colors.color6)"
shape_external: "($colors.color6)"
shape_externalarg: { fg: "($colors.color2)" attr: "b" }
shape_filepath: "($colors.color6)"
shape_flag: { fg: "($colors.color4)" attr: "b" }
shape_float: { fg: "($colors.color5)" attr: "b" }
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: "b" }
shape_globpattern: { fg: "($colors.color6)" attr: "b" }
shape_int: { fg: "($colors.color5)" attr: "b" }
shape_internalcall: { fg: "($colors.color6)" attr: "b" }
shape_list: { fg: "($colors.color6)" attr: "b" }
shape_literal: "($colors.color4)"
shape_match_pattern: "($colors.color2)"
shape_matching_brackets: { attr: "u" }
shape_nothing: "($colors.color14)"
shape_operator: "($colors.color3)"
shape_or: { fg: "($colors.color5)" attr: "b" }
shape_pipe: { fg: "($colors.color5)" attr: "b" }
shape_range: { fg: "($colors.color3)" attr: "b" }
shape_record: { fg: "($colors.color6)" attr: "b" }
shape_redirection: { fg: "($colors.color5)" attr: "b" }
shape_signature: { fg: "($colors.color2)" attr: "b" }
shape_string: "($colors.color2)"
shape_string_interpolation: { fg: "($colors.color6)" attr: "b" }
shape_table: { fg: "($colors.color4)" attr: "b" }
shape_variable: "($colors.color5)"
open $theme_file --raw |
str replace "{{theme}}" ($theme | str replace '-' '_') --all |
save $theme_file
background: "($colors.background)"
foreground: "($colors.foreground)"
cursor: "($colors.cursor)"
}}'
| save --force ({
parent: $THEMES
stem: $name
extension: "nu"
} | path join)
}

def main [] {
mkdir $THEMES

mkdir $THEMES
try { git clone $SOURCE.remote $SOURCE.local }

ls $RAW |
get name |
str replace $"($RAW)/" "" |
each {
|it|
print $it
make-theme $it
ls $SOURCE.dir
| get name
| path parse
| get stem
| each {|theme|
print -n $"(ansi erase_line)($theme)\r"
make-theme $theme
}
| ignore

print "all done"
}
61 changes: 0 additions & 61 deletions themes/template.nu

This file was deleted.

138 changes: 79 additions & 59 deletions themes/themes/3024-day.nu
Original file line number Diff line number Diff line change
@@ -1,61 +1,81 @@
export def main [] {
# extra desired values for the 3024_day theme
# which do not fit into any nushell theme
# these colors should be handledd by the terminal
# emulator itself
#
# background: "#f7f7f7"
# foreground: "#4a4543"
# cursor: "#4a4543"
export def main [] { return {
separator: "#a5a2a2"
leading_trailing_space_bg: { attr: "n" }
header: { fg: "#01a252" attr: "b" }
empty: "#01a0e4"
bool: {|| if $in { "#cdab53" } else { "light_gray" } }
int: "#a5a2a2"
filesize: {|e|
if $e == 0b {
"#a5a2a2"
} else if $e < 1mb {
"#b5e4f4"
} else {{ fg: "#01a0e4" }}
}
duration: "#a5a2a2"
date: {|| (date now) - $in |
if $in < 1hr {
{ fg: "#db2d20" attr: "b" }
} else if $in < 6hr {
"#db2d20"
} else if $in < 1day {
"#fded02"
} else if $in < 3day {
"#01a252"
} else if $in < 1wk {
{ fg: "#01a252" attr: "b" }
} else if $in < 6wk {
"#b5e4f4"
} else if $in < 52wk {
"#01a0e4"
} else { "dark_gray" }
}
range: "#a5a2a2"
float: "#a5a2a2"
string: "#a5a2a2"
nothing: "#a5a2a2"
binary: "#a5a2a2"
cellpath: "#a5a2a2"
row_index: { fg: "#01a252" attr: "b" }
record: "#a5a2a2"
list: "#a5a2a2"
block: "#a5a2a2"
hints: "dark_gray"

{
# color for nushell primitives
separator: "#f7f7f7"
leading_trailing_space_bg: { attr: n } # no fg, no bg, attr none effectively turns this off
header: "#3a3432"
empty: "#01a0e4"
bool: "#f7f7f7"
int: "#f7f7f7"
filesize: "#f7f7f7"
duration: "#f7f7f7"
date: "#f7f7f7"
range: "#f7f7f7"
float: "#f7f7f7"
string: "#f7f7f7"
nothing: "#f7f7f7"
binary: "#f7f7f7"
cellpath: "#f7f7f7"
row_index: "#3a3432"
record: "#f7f7f7"
list: "#f7f7f7"
block: "#f7f7f7"
hints: "#5c5855"
shape_and: { fg: "#a16a94" attr: "b" }
shape_binary: { fg: "#a16a94" attr: "b" }
shape_block: { fg: "#01a0e4" attr: "b" }
shape_bool: "#cdab53"
shape_custom: "#01a252"
shape_datetime: { fg: "#b5e4f4" attr: "b" }
shape_directory: "#b5e4f4"
shape_external: "#b5e4f4"
shape_externalarg: { fg: "#01a252" attr: "b" }
shape_filepath: "#b5e4f4"
shape_flag: { fg: "#01a0e4" attr: "b" }
shape_float: { fg: "#a16a94" attr: "b" }
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: "b" }
shape_globpattern: { fg: "#b5e4f4" attr: "b" }
shape_int: { fg: "#a16a94" attr: "b" }
shape_internalcall: { fg: "#b5e4f4" attr: "b" }
shape_list: { fg: "#b5e4f4" attr: "b" }
shape_literal: "#01a0e4"
shape_match_pattern: "#01a252"
shape_matching_brackets: { attr: "u" }
shape_nothing: "#cdab53"
shape_operator: "#fded02"
shape_or: { fg: "#a16a94" attr: "b" }
shape_pipe: { fg: "#a16a94" attr: "b" }
shape_range: { fg: "#fded02" attr: "b" }
shape_record: { fg: "#b5e4f4" attr: "b" }
shape_redirection: { fg: "#a16a94" attr: "b" }
shape_signature: { fg: "#01a252" attr: "b" }
shape_string: "#01a252"
shape_string_interpolation: { fg: "#b5e4f4" attr: "b" }
shape_table: { fg: "#01a0e4" attr: "b" }
shape_variable: "#a16a94"

# shapes are used to change the cli syntax highlighting
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b}
shape_binary: "#d6d5d4"
shape_bool: "#cdab53"
shape_int: "#d6d5d4"
shape_float: "#d6d5d4"
shape_range: "#4a4543"
shape_internalcall: "#cdab53"
shape_external: "#b5e4f4"
shape_externalarg: "#3a3432"
shape_literal: "#01a0e4"
shape_operator: "#fded02"
shape_signature: "#3a3432"
shape_string: "#01a252"
shape_string_interpolation: "#cdab53"
shape_datetime: "#cdab53"
shape_list: "#cdab53"
shape_table: "#807d7c"
shape_record: "#cdab53"
shape_block: "#807d7c"
shape_filepath: "#b5e4f4"
shape_globpattern: "#cdab53"
shape_variable: "#a16a94"
shape_flag: "#807d7c"
shape_custom: "#01a252"
shape_nothing: "#cdab53"
}
}
background: "#f7f7f7"
foreground: "#4a4543"
cursor: "#4a4543"
}}
Loading

0 comments on commit b9ec76b

Please sign in to comment.