diff options
author | James Campos <james.r.campos@gmail.com> | 2021-05-01 22:31:59 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2021-05-01 22:31:59 -0700 |
commit | 417c5d258c8a80790b848882e4b92dc2b5ae5f63 (patch) | |
tree | fdb012ebfe3f6bd536a88e464aafd99d8114cf39 /src | |
parent | c7c15e29581ff60d3ac528783cf689bf5b671869 (diff) | |
download | bk-417c5d258c8a80790b848882e4b92dc2b5ae5f63.tar.gz |
themes
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 41 | ||||
-rw-r--r-- | src/view.rs | 2 |
2 files changed, 39 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index d3e978c..e23896c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use crossterm::{ cursor, event::{DisableMouseCapture, EnableMouseCapture, Event}, queue, - style::{self, Print}, + style::{self, Color::Rgb, Colors, Print, SetColors}, terminal, }; use serde::{Deserialize, Serialize}; @@ -96,6 +96,7 @@ pub struct Bk<'a> { mark: HashMap<char, (usize, usize)>, links: HashMap<String, (usize, usize)>, // layout + colors: Colors, cols: u16, rows: usize, max_width: u16, @@ -136,6 +137,7 @@ impl Bk<'_> { line: 0, mark: HashMap::new(), links: epub.links, + colors: args.colors, cols, rows: rows as usize, max_width: args.width, @@ -157,15 +159,16 @@ impl Bk<'_> { stdout, terminal::EnterAlternateScreen, cursor::Hide, - EnableMouseCapture + EnableMouseCapture, )?; terminal::enable_raw_mode()?; let mut render = |bk: &Bk| { queue!( stdout, + Print(style::Attribute::Reset), + SetColors(bk.colors), terminal::Clear(terminal::ClearType::All), - Print(style::Attribute::Reset) ) .unwrap(); for (i, line) in bk.view.render(bk).iter().enumerate() { @@ -278,6 +281,14 @@ struct Args { #[argh(positional)] path: Option<String>, + /// background color (eg 282a36) + #[argh(option)] + bg: Option<String>, + + /// foreground color (eg f8f8f2) + #[argh(option)] + fg: Option<String>, + /// print metadata and exit #[argh(switch, short = 'm')] meta: bool, @@ -292,6 +303,7 @@ struct Args { } struct Props { + colors: Colors, chapter: usize, byte: usize, width: u16, @@ -348,12 +360,35 @@ fn init() -> Result<State, Box<dyn std::error::Error>> { } }; + // XXX oh god what + let fg = args + .fg + .and_then(|s| { + Some(Rgb { + r: u8::from_str_radix(&s[0..2], 16).unwrap(), + g: u8::from_str_radix(&s[2..4], 16).unwrap(), + b: u8::from_str_radix(&s[4..6], 16).unwrap(), + }) + }) + .unwrap_or(style::Color::Reset); + let bg = args + .bg + .and_then(|s| { + Some(Rgb { + r: u8::from_str_radix(&s[0..2], 16).unwrap(), + g: u8::from_str_radix(&s[2..4], 16).unwrap(), + b: u8::from_str_radix(&s[4..6], 16).unwrap(), + }) + }) + .unwrap_or(style::Color::Reset); + Ok(State { path, save, save_path, meta: args.meta, bk: Props { + colors: Colors::new(fg, bg), chapter, byte, width: args.width, diff --git a/src/view.rs b/src/view.rs index fa50532..5e48772 100644 --- a/src/view.rs +++ b/src/view.rs @@ -175,7 +175,7 @@ impl View for Toc { "{}{}{}", Attribute::Reverse, arr[bk.cursor], - Attribute::Reset + Attribute::NoReverse ); arr } |