From 417c5d258c8a80790b848882e4b92dc2b5ae5f63 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 1 May 2021 22:31:59 -0700 Subject: themes --- src/main.rs | 41 ++++++++++++++++++++++++++++++++++++++--- src/view.rs | 2 +- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'src') 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, links: HashMap, // 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, + /// background color (eg 282a36) + #[argh(option)] + bg: Option, + + /// foreground color (eg f8f8f2) + #[argh(option)] + fg: Option, + /// 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> { } }; + // 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 } -- cgit v1.2.3