add lua functions for importing color scheme files

This commit is contained in:
Wez Furlong committed 2022-07-14 23:03:18 -07:00
1 parent e566885e7f
commit 181401a2ca
6 files changed
+235 -2

No files matched your search

@@ -0,0 +1,79 @@
# `wezterm.color.load_base16_scheme(file_name)`
*Since: nightly builds only*
Loads a yaml file in [base16](https://github.com/chriskempson/base16) format
and returns it as a wezterm color scheme.
Note that wezterm ships with the base16 color schemes that were referenced via
[base16-schemes-source](https://github.com/chriskempson/base16-schemes-source)
when the release was prepared so this function is primarily useful if you want
to import a base16 color scheme that either isn't listed from the main list, or
that was created after your version of wezterm was built.
This function returns a tuple of the the color definitions and the metadata.
For example, given a yaml file with these contents:
```yaml
scheme: "Cupcake"
author: "Chris Kempson (http://chriskempson.com)"
base00: "fbf1f2"
base01: "f2f1f4"
base02: "d8d5dd"
base03: "bfb9c6"
base04: "a59daf"
base05: "8b8198"
base06: "72677E"
base07: "585062"
base08: "D57E85"
base09: "EBB790"
base0A: "DCB16C"
base0B: "A3B367"
base0C: "69A9A7"
base0D: "7297B9"
base0E: "BB99B4"
base0F: "BAA58C"
```
Then:
```lua
> colors, metadata = wezterm.color.load_base16_scheme("/tmp/cupcake.yaml")
> print(colors)
22:59:26.998 INFO logging > lua: {
"ansi": [
"#fbf1f2",
"#d57e85",
"#a3b367",
"#dcb16c",
"#7297b9",
"#bb99b4",
"#69a9a7",
"#8b8198",
],
"background": "#fbf1f2",
"brights": [
"#bfb9c6",
"#d57e85",
"#a3b367",
"#dcb16c",
"#7297b9",
"#bb99b4",
"#69a9a7",
"#585062",
],
"cursor_bg": "#8b8198",
"cursor_border": "#8b8198",
"cursor_fg": "#8b8198",
"foreground": "#8b8198",
"indexed": {},
"selection_bg": "#8b8198",
"selection_fg": "#fbf1f2",
}
> print(metadata)
22:59:29.671 INFO logging > lua: {
"author": "Chris Kempson (http://chriskempson.com)",
"name": "Cupcake",
}
```
@@ -0,0 +1,46 @@
# `wezterm.color.load_scheme(file_name)`
*Since: nightly builds only*
Loads a wezterm color scheme from a TOML file. This function
returns a tuple of the the color definitions and the metadata:
```lua
> colors, metadata = wezterm.color.load_scheme("wezterm/assets/colors/Abernathy.toml")
> print(metadata)
22:37:06.041 INFO logging > lua: {
"name": "Abernathy",
"origin_url": "https://github.com/mbadolato/iTerm2-Color-Schemes",
}
> print(colors)
22:37:10.416 INFO logging > lua: {
"ansi": [
"#000000",
"#cd0000",
"#00cd00",
"#cdcd00",
"#1093f5",
"#cd00cd",
"#00cdcd",
"#faebd7",
],
"background": "#111416",
"brights": [
"#404040",
"#ff0000",
"#00ff00",
"#ffff00",
"#11b5f6",
"#ff00ff",
"#00ffff",
"#ffffff",
],
"cursor_bg": "#bbbbbb",
"cursor_border": "#bbbbbb",
"cursor_fg": "#ffffff",
"foreground": "#eeeeec",
"indexed": {},
"selection_bg": "#eeeeec",
"selection_fg": "#333333",
}
```
@@ -0,0 +1,77 @@
# `wezterm.color.load_terminal_sexy_scheme(file_name)`
*Since: nightly builds only*
Loads a json file exported from [terminal.sexy](https://terminal.sexy/)
and returns it as a wezterm color scheme.
Note that wezterm ships with all of the pre-defined terminal.sexy color
schemes, so this function is primarily useful if you want to design a color
scheme using terminal.sexy and then import it to wezterm.
This function returns a tuple of the the color definitions and the metadata.
For example, given a json file with these contents:
```json
{
"name": "",
"author": "",
"color": [
"#282a2e",
"#a54242",
"#8c9440",
"#de935f",
"#5f819d",
"#85678f",
"#5e8d87",
"#707880",
"#373b41",
"#cc6666",
"#b5bd68",
"#f0c674",
"#81a2be",
"#b294bb",
"#8abeb7",
"#c5c8c6"
],
"foreground": "#c5c8c6",
"background": "#1d1f21"
}
```
Then:
```
> colors, metadata = wezterm.color.load_terminal_sexy_scheme("/path/to/file.json")
> print(colors)
22:37:10.416 INFO logging > lua: {
"ansi": [
"#282a2e",
"#a54242",
"#8c9440",
"#de935f",
"#5f819d",
"#85678f",
"#5e8d87",
"#707880",
],
"background": "#1d1f21",
"brights": [
"#373b41",
"#cc6666",
"#b5bd68",
"#f0c674",
"#81a2be",
"#b294bb",
"#8abeb7",
"#c5c8c6"
],
"foreground": "#c5c8c6",
}
> print(metadata)
22:37:06.041 INFO logging > lua: {
"name": "",
"author": ""
}
```