summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-16 18:42:55 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-16 18:42:55 -0700
commitebe242a89f0c5b99b60909788c24179ccd154c7c (patch)
tree4953cc879032eede3d9f84e6cc44b40157df411a
parent00635360e52f8f9834be71a1e1e21f24ddb3529f (diff)
Allow reloading theme file
-rw-r--r--TODO.md3
-rw-r--r--src/config.rs66
-rw-r--r--src/tui/app.rs7
3 files changed, 41 insertions, 35 deletions
diff --git a/TODO.md b/TODO.md
index e322e7c..6b15dbd 100644
--- a/TODO.md
+++ b/TODO.md
@@ -17,6 +17,9 @@ changing [soon](https://meta.stackexchange.com/q/348746).
8. Possibly make `--arrow_keys_focus` option to toggle the arrow key consumption
9. Maybe **ESC** cycles layout in the opposite direction? And stops at
BothColumns?
+10. Allow cycling through `~/.config/so/colors/*.toml` themes (or just hardcoded
+ themes in `tui::themes`) with keybinding
+11. Small tray at the bottom with "notifications", e.g. "GitHub Theme loaded!"
#### other
1. Use [par_iter](https://github.com/rayon-rs/rayon) for text preprocess & parsing?
diff --git a/src/config.rs b/src/config.rs
index 7fc3e83..0ef5f2f 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -72,45 +72,43 @@ fn config_file_name() -> Result<PathBuf> {
Ok(project_dir()?.config_dir().join("config.yml"))
}
-// TODO either try to respect terminal defaults, or go all in one solarized or
-// tomorrow night 80s
static DEFAULT_COLORS_TOML: &str = r##"
# Every field in a theme file is optional.
shadow = false
borders = "outset" # Alternatives are "none" and "simple"
-# Base colors are red, green, blue,
-# cyan, magenta, yellow, white and black.
+# Base colors are
+# red, green, blue, cyan, magenta, yellow, white and black.
+#
+# There are 3 ways to select a color:
+# - The 16 base colors are selected by name:
+# "blue", "light red", "magenta", ...
+# - Low-resolution colors use 3 characters, each <= 5:
+# "541", "003", ...
+# - Full-resolution colors start with '#' and can be 3 or 6 hex digits:
+# "#1A6", "#123456", ...
[colors]
- # There are 3 ways to select a color:
- # - The 16 base colors are selected by name:
- # "blue", "light red", "magenta", ...
- # - Low-resolution colors use 3 characters, each <= 5:
- # "541", "003", ...
- # - Full-resolution colors start with '#' and can be 3 or 6 hex digits:
- # "#1A6", "#123456", ...
-
- # If the value is an array, the first valid
- # and supported color will be used.
- background = ["default"]
-
- # If the terminal doesn't support custom color (like the linux TTY),
- # non-base colors will be skipped.
- shadow = []
- view = "111"
-
- # An array with a single value has the same effect as a simple value.
- primary = []
- secondary = "cyan"
- tertiary = "green"
-
- # Hex values can use lower or uppercase.
- # (base color MUST be lowercase)
- title_primary = ["BLUE", "yellow"] # `BLUE` will be skipped.
- title_secondary = "#ffff55"
-
- # Lower precision values can use only 3 digits.
- highlight = "#F88"
- highlight_inactive = "#5555FF"
+background = "default"
+
+# If the terminal doesn't support custom color (like the linux TTY),
+# non-base colors will be skipped.
+shadow = []
+view = "default"
+
+# An array with a single value has the same effect as a simple value.
+primary = ["default"]
+secondary = "cyan" # secondary style is used for code hightlighting
+tertiary = "green"
+
+# Hex values can use lower or uppercase.
+# (base color MUST be lowercase)
+# If the value is an array, the first valid
+# and supported color will be used.
+title_primary = ["BLUE", "red"] # `BLUE` will be skipped.
+title_secondary = "yellow"
+
+# Lower precision values can use only 3 digits.
+highlight = "yellow"
+highlight_inactive = "light yellow"
"##;
diff --git a/src/tui/app.rs b/src/tui/app.rs
index f40021d..c17cf32 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -1,4 +1,5 @@
-use cursive::theme::{BaseColor, Color, Effect, Style};
+use cursive::event::Event;
+use cursive::theme::{BaseColor, Color, ColorStyle, Effect, Style};
use cursive::utils::markup::StyledString;
use cursive::utils::span::SpannedString;
use cursive::Cursive;
@@ -64,6 +65,10 @@ pub fn run(qs: Vec<Question>) -> Result<()> {
}
cursive::logger::init();
siv.add_global_callback('?', cursive::Cursive::toggle_debug_console);
+ siv.add_global_callback(Event::CtrlChar('r'), |s| {
+ s.load_theme_file(config::theme_file_name().unwrap())
+ .unwrap()
+ });
siv.run();
Ok(())
}