diff options
author | Canop <cano.petrole@gmail.com> | 2019-11-13 23:20:27 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2019-11-13 23:20:27 +0100 |
commit | 8ee94465c039c8765979e28691d8d3e87adb67ed (patch) | |
tree | 3adcb23d3b287a947fa92775fa3ce1849b12276c | |
parent | 8a45af31a58fe577ff9361850775137d31f0a9de (diff) |
make it possible to define a global background
The default terminal background isn't always good or easy to change.
So there's now a new skin entry `default`.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | Cargo.lock | 4 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/browser_states.rs | 12 | ||||
-rw-r--r-- | src/conf.rs | 1 | ||||
-rw-r--r-- | src/displayable_tree.rs | 16 | ||||
-rw-r--r-- | src/help_states.rs | 18 | ||||
-rw-r--r-- | src/mad_skin.rs | 31 | ||||
-rw-r--r-- | src/skin.rs | 49 | ||||
-rw-r--r-- | website/docs/community.md | 2 | ||||
-rw-r--r-- | website/docs/documentation/configuration.md | 12 |
11 files changed, 86 insertions, 63 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index bbedd84..731cc09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + ### Next Version * colored status line * better handling of errors when opening files externally @@ -5,6 +6,7 @@ * `:parent` no longer keeps the filter (this was too confusing) * new `:up` command, focusing the parent of the current tree root * `$PAGER` used in default config. Fix #20 +* default conf links to the white background skin published on web site <a name="v0.10.1"></a> ### v0.10.1 - 2019-11-04 @@ -106,7 +106,7 @@ dependencies = [ "opener 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", - "termimad 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "termimad 0.7.4", "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "umask 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "users 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -649,7 +649,6 @@ dependencies = [ [[package]] name = "termimad" version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossterm 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -854,7 +853,6 @@ dependencies = [ "checksum syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7bedb3320d0f3035594b0b723c8a28d7d336a3eda3881db79e61d676fb644c" "checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203" "checksum term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" -"checksum termimad 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "046a12865ad6a5b515c0236d3197726a2f970a3b9e4ddad9fa6676c5a4c6f61e" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thiserror 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9fe148fa0fc3363a27092d48f7787363ded15bb8623c5d5dd4e2e9f23e4b21bc" "checksum thiserror-impl 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "258da67e99e590650fa541ac6be764313d23e80cefb6846b516deb8de6b6d921" @@ -27,7 +27,7 @@ opener = "0.4" crossterm = "0.13.2" umask = "0.1.7" minimad = "0.4.2" -termimad = "0.7.4" +termimad = "0.7.5" id-arena = "2.2.1" lazy-regex = "0.1" diff --git a/src/browser_states.rs b/src/browser_states.rs index 79ecfe1..2dc8899 100644 --- a/src/browser_states.rs +++ b/src/browser_states.rs @@ -447,14 +447,10 @@ impl AppState for BrowserState { OptionBool::Yes => 'y', OptionBool::No => 'n', }; - write!( - w, - "{}{} {}{}", - screen.skin.flag_label.apply_to(" h:"), - screen.skin.flag_value.apply_to(h_value), - screen.skin.flag_label.apply_to(" gi:"), - screen.skin.flag_value.apply_to(gi_value), - )?; + screen.skin.flag_label.queue_str(w, " h:")?; + screen.skin.flag_value.queue(w, h_value)?; + screen.skin.flag_label.queue_str(w, " gi:")?; + screen.skin.flag_value.queue(w, gi_value)?; Ok(()) } } diff --git a/src/conf.rs b/src/conf.rs index 5ae0655..026d07a 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -205,6 +205,7 @@ execution = "$PAGER {file}" # render on terminals with low capabilities # # [skin] +# default = "gray(20) gray(1)" # tree = "rgb(89, 73, 101) none" # file = "gray(21) none" # directory = "rgb(255, 152, 0) none bold" diff --git a/src/displayable_tree.rs b/src/displayable_tree.rs index f05df48..e27cb07 100644 --- a/src/displayable_tree.rs +++ b/src/displayable_tree.rs @@ -43,6 +43,7 @@ pub struct DisplayableTree<'s, 't> { } impl<'s, 't> DisplayableTree<'s, 't> { + pub fn out_of_app(tree: &'t Tree, skin: &'s Skin, width: u16) -> DisplayableTree<'s, 't> { DisplayableTree { tree, @@ -122,15 +123,17 @@ impl<'s, 't> DisplayableTree<'s, 't> { LineType::Pruning => &self.skin.pruning, }; let mut style = style.clone(); + let mut char_match_style = self.skin.char_match.clone(); if selected { if let Some(c) = self.skin.selected_line.get_bg() { style.set_bg(c); + char_match_style.set_bg(c); } } if idx == 0 { style.queue_str(f, &line.path.to_string_lossy())?; } else { - pattern.style(&line.name, &style, &self.skin.char_match).write_on(f)?; + pattern.style(&line.name, &style, &char_match_style).write_on(f)?; } match &line.line_type { LineType::Dir => { @@ -183,9 +186,10 @@ impl<'s, 't> DisplayableTree<'s, 't> { if line_index > 0 { line_index += tree.scroll as usize; } + let mut selected = false; if line_index < tree.lines.len() { let line = &tree.lines[line_index]; - let selected = self.in_app && line_index == tree.selection; + selected = self.in_app && line_index == tree.selection; for depth in 0..line.depth { self.skin.tree.queue_str( f, @@ -229,9 +233,11 @@ impl<'s, 't> DisplayableTree<'s, 't> { } } self.write_line_name(f, line, line_index, &tree.options.pattern, selected)?; - if selected { - self.skin.selected_line.queue_bg(f)?; - } + } + if selected { + self.skin.selected_line.queue_bg(f)?; + } else { + self.skin.default.queue_bg(f)?; } if self.in_app { queue!(f, Clear(ClearType::UntilNewLine))?; diff --git a/src/help_states.rs b/src/help_states.rs index 6dd4b48..dc36667 100644 --- a/src/help_states.rs +++ b/src/help_states.rs @@ -1,3 +1,9 @@ +use std::io::Write; + +use crossterm::{ + queue, + terminal::{Clear, ClearType}, +}; use termimad::{Area, MadView}; use crate::{ @@ -8,6 +14,7 @@ use crate::{ errors::ProgramError, help_content, io::W, + mad_skin, screens::Screen, status::Status, task_sync::TaskLifetime, @@ -25,7 +32,7 @@ impl HelpState { pub fn new(screen: &Screen, con: &AppContext) -> HelpState { let area = Area::uninitialized(); // will be fixed at drawing time let markdown = help_content::build_markdown(con); - let view = MadView::from(markdown, area, screen.skin.to_mad_skin()); + let view = MadView::from(markdown, area, mad_skin::make_help_mad_skin(&screen.skin)); HelpState { dirty: true, view, @@ -121,14 +128,15 @@ impl AppState for HelpState { } } - /// the help state doesn't rewrite the flags. We assume the one from the coming - /// state are still relevant. + /// there's no meaningful flags here fn write_flags( &self, - _w: &mut W, - _screen: &mut Screen, + w: &mut W, + screen: &mut Screen, _con: &AppContext ) -> Result<(), ProgramError> { + screen.skin.default.queue_bg(w)?; + queue!(w, Clear(ClearType::UntilNewLine))?; Ok(()) } } diff --git a/src/mad_skin.rs b/src/mad_skin.rs index a2bd5fe..f36272a 100644 --- a/src/mad_skin.rs +++ b/src/mad_skin.rs @@ -1,6 +1,7 @@ /// This module builds Termimad `MadSkin` from Broot `Skin` use termimad::{ + CompoundStyle, Alignment, LineStyle, MadSkin, @@ -52,3 +53,33 @@ impl StatusMadSkinSet { } } } + +/// build a MadSkin, which will be used for markdown formatting +/// for the help screen by applying the `help_*` entries +/// of the skin. +pub fn make_help_mad_skin(skin: &Skin) -> MadSkin { + let mut ms = MadSkin::default(); + ms.paragraph.compound_style = CompoundStyle::from(skin.help_paragraph.clone()); + ms.inline_code = CompoundStyle::from(skin.help_code.clone()); + ms.code_block.compound_style = ms.inline_code.clone(); + ms.bold = CompoundStyle::from(skin.help_bold.clone()); + ms.italic = CompoundStyle::from(skin.help_italic.clone()); + ms.table = LineStyle { + compound_style: CompoundStyle::from(skin.help_table_border.clone()), + align: Alignment::Center, + }; + if let Some(c) = skin.help_headers.get_fg() { + ms.set_headers_fg(c); + } + if let Some(c) = skin.help_headers.get_bg() { + ms.set_headers_bg(c); + } + ms.bullet.set_compound_style(ms.paragraph.compound_style.clone()); + ms.scrollbar + .track + .set_compound_style(CompoundStyle::from(skin.scrollbar_track.clone())); + ms.scrollbar + .thumb + .set_compound_style(CompoundStyle::from(skin.scrollbar_thumb.clone())); + ms +} diff --git a/src/skin.rs b/src/skin.rs index 5b58a11..b4890a3 100644 --- a/src/skin.rs +++ b/src/skin.rs @@ -13,7 +13,7 @@ use crossterm::{ Color::{self, *}, }, }; -use termimad::{Alignment, CompoundStyle, LineStyle, MadSkin}; +use termimad::CompoundStyle; macro_rules! Skin { ( @@ -31,13 +31,19 @@ macro_rules! Skin { } /// build a skin with some entry overloaded by configuration pub fn create(mut skin_conf: HashMap<String, CompoundStyle>) -> Skin { - Skin { + let mut skin = Skin { $($name: skin_conf.remove(stringify!($name)).unwrap_or(CompoundStyle::new( $fg, $bg, [$($a),*].to_vec(), )),)* - } + }; + $( + let mut base = skin.default.clone(); + base.overwrite_with(&skin.$name); + skin.$name = base; + )* + skin } } impl Clone for Skin { @@ -65,6 +71,7 @@ pub fn ansi(v: u8) -> Option<Color> { // Gold alternative: use 178 for boldish and italic/code is 229 // Orange alternative: boldish is 208 and italic/code is 222 Skin! { + default: gray(22), gray(1); tree: gray(5), None; file: gray(18), None; directory: Some(Blue), None; {Bold} @@ -76,14 +83,14 @@ Skin! { selected_line: None, gray(4); char_match: Some(Green), None; file_error: Some(Red), None; - flag_label: gray(15), gray(1); - flag_value: ansi(178), gray(1); {Bold} + flag_label: gray(15), None; + flag_value: ansi(178), None; {Bold} input: Some(White), None; status_error: gray(22), ansi(124); status_job: ansi(220), gray(5); status_normal: gray(20), gray(3); - status_italic: ansi(178), None; - status_bold: ansi(178), None; {Bold} + status_italic: ansi(178), gray(3); + status_bold: ansi(178), gray(3); {Bold} status_code: ansi(229), gray(5); status_ellipsis: gray(19), gray(1); scrollbar_track: gray(7), None; @@ -97,34 +104,6 @@ Skin! { } -impl Skin { - /// build a MadSkin, which will be used for markdown formatting - /// (for the help screen) by applying the `help_*` entries - /// of the skin. - pub fn to_mad_skin(&self) -> MadSkin { - let mut ms = MadSkin::default(); - ms.paragraph.compound_style = CompoundStyle::from(self.help_paragraph.clone()); - ms.inline_code = CompoundStyle::from(self.help_code.clone()); - ms.code_block.compound_style = ms.inline_code.clone(); - ms.bold = CompoundStyle::from(self.help_bold.clone()); - ms.italic = CompoundStyle::from(self.help_italic.clone()); - ms.table = LineStyle { - compound_style: CompoundStyle::from(self.help_table_border.clone()), - align: Alignment::Center, - }; - if let Some(c) = self.help_headers.get_fg() { - ms.set_headers_fg(c); - } - ms.scrollbar - .track - .set_compound_style(CompoundStyle::from(self.scrollbar_track.clone())); - ms.scrollbar - .thumb - .set_compound_style(CompoundStyle::from(self.scrollbar_thumb.clone())); - ms - } -} - impl fmt::Debug for Skin { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Skin") diff --git a/website/docs/community.md b/website/docs/community.md index 2eb0f84..220d5f2 100644 --- a/website/docs/community.md +++ b/website/docs/community.md @@ -21,7 +21,7 @@ Before posting a new issue, check your problem hasn't already been raised and in ## Contribute -**Broot** is written in [rust](https://www.rust-lang.org/). The current focus is linux+mac but we try to support windows too. +**Broot** is written in [rust](https://www.rust-lang.org/). The current focus is linux+mac but we try to support windows too (use PowerShell instead of the old cmd). Before starting working on a Pull Request, please join the Miaou room to coordinate the developement. There are frequently several feature branchs waiting to be merged and adding some wild ones may make the process painful. diff --git a/website/docs/documentation/configuration.md b/website/docs/documentation/configuration.md index de7d23f..64e52a2 100644 --- a/website/docs/documentation/configuration.md +++ b/website/docs/documentation/configuration.md @@ -226,6 +226,7 @@ You can change all colors by adding a `[skin]` section in your `conf.toml` file. For example: [skin] + default = "gray(22) gray(1)" tree = "rgb(89, 73, 101) none" file = "gray(21) none" directory = "rgb(255, 152, 0) none bold" @@ -292,6 +293,7 @@ Here's a skin specifically designed for this case: ![light skin](../img/20191114-light-skin.png) [skin] + default = "gray(2) gray(23)" tree = "gray(17) none" file = "gray(1) none" directory = "ansi(20) none bold" @@ -299,19 +301,19 @@ Here's a skin specifically designed for this case: link = "Magenta none" pruning = "gray(5) none Italic" permissions = "gray(4) none " - selected_line = "none gray(21)" + selected_line = "none gray(20)" char_match = "ansi(28) none" file_error = "Red none" flag_label = "gray(16) none" flag_value = "ansi(202) none bold" input = "ansi(0) none" status_error = "ansi(196) gray(22)" - status_job = "ansi(220) gray(5)" + status_job = "ansi(220) gray(18)" status_normal = "gray(2) gray(22)" - status_italic = "ansi(202) None" - status_bold = "ansi(202) None bold" + status_italic = "ansi(202) gray(22)" + status_bold = "ansi(202) gray(22) bold" status_code = "ansi(17) gray(22)" - status_ellipsis = "gray(1) gray(23)" + status_ellipsis = "gray(1) white" scrollbar_track = "gray(20) none" scrollbar_thumb = "ansi(238) none" help_paragraph = "gray(2) none" |