From d119ce6b0de738a9ceba79eff4e04683b94333a9 Mon Sep 17 00:00:00 2001 From: graelo Date: Fri, 19 Mar 2021 09:39:30 +0100 Subject: [PATCH] refactor: UiColors -> colors module --- src/colors.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 +- src/ui/mod.rs | 2 +- src/ui/vc.rs | 48 +----------------------------------------------- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/colors.rs b/src/colors.rs index c3614db..19bf50e 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -1,4 +1,5 @@ use crate::error; +use clap::Clap; use termion::color; pub fn parse_color(src: &str) -> Result, error::ParseError> { @@ -45,3 +46,49 @@ mod tests { assert!(parse_color("wat").is_err(), "this color should not exist"); } } + +/// Holds color-related data, for clarity. +/// +/// - `focus_*` colors are used to render the currently focused matched text. +/// - `normal_*` colors are used to render other matched text. +/// - `hint_*` colors are used to render the hints. +#[derive(Clap, Debug)] +pub struct UiColors { + /// Foreground color for base text. + #[clap(long, default_value = "bright-cyan", parse(try_from_str = parse_color))] + pub text_fg: Box, + + /// Background color for base text. + #[clap(long, default_value = "bright-white", parse(try_from_str = parse_color))] + pub text_bg: Box, + + /// Foreground color for matches. + #[clap(long, default_value = "yellow", + parse(try_from_str = parse_color))] + pub match_fg: Box, + + /// Background color for matches. + #[clap(long, default_value = "bright-white", + parse(try_from_str = parse_color))] + pub match_bg: Box, + + /// Foreground color for the focused match. + #[clap(long, default_value = "magenta", + parse(try_from_str = parse_color))] + pub focused_fg: Box, + + /// Background color for the focused match. + #[clap(long, default_value = "bright-white", + parse(try_from_str = parse_color))] + pub focused_bg: Box, + + /// Foreground color for hints. + #[clap(long, default_value = "white", + parse(try_from_str = parse_color))] + pub hint_fg: Box, + + /// Background color for hints. + #[clap(long, default_value = "magenta", + parse(try_from_str = parse_color))] + pub hint_bg: Box, +} diff --git a/src/lib.rs b/src/lib.rs index 5dcc402..d1ceb77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,7 @@ pub struct CliOpt { unique_hint: bool, #[clap(flatten)] - colors: ui::UiColors, + colors: colors::UiColors, /// Align hint with its match. #[clap(long, arg_enum, default_value = "leading")] diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 1dcac7f..8501623 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -19,4 +19,4 @@ mod vc; pub use vc::ViewController; -pub use vc::{HintAlignment, HintStyle, UiColors}; +pub use vc::{HintAlignment, HintStyle}; diff --git a/src/ui/vc.rs b/src/ui/vc.rs index 391e848..e3dcff6 100644 --- a/src/ui/vc.rs +++ b/src/ui/vc.rs @@ -8,7 +8,7 @@ use sequence_trie::SequenceTrie; use termion::{self, color, cursor, event, style}; use crate::error::ParseError; -use crate::{colors, model, output_destination::OutputDestination, selection::Selection}; +use crate::{colors::UiColors, model, output_destination::OutputDestination, selection::Selection}; pub struct ViewController<'a> { model: &'a mut model::Model<'a>, @@ -1115,49 +1115,3 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - "; assert_eq!(writer, expected.as_bytes()); } } - -// /// Holds color-related data, for clarity. -// /// -// /// - `focus_*` colors are used to render the currently focused matched text. -// /// - `normal_*` colors are used to render other matched text. -// /// - `hint_*` colors are used to render the hints. -#[derive(Clap, Debug)] -pub struct UiColors { - /// Foreground color for base text. - #[clap(long, default_value = "bright-cyan", parse(try_from_str = colors::parse_color))] - pub text_fg: Box, - - /// Background color for base text. - #[clap(long, default_value = "bright-white", parse(try_from_str = colors::parse_color))] - pub text_bg: Box, - - /// Foreground color for matches. - #[clap(long, default_value = "yellow", - parse(try_from_str = colors::parse_color))] - pub match_fg: Box, - - /// Background color for matches. - #[clap(long, default_value = "bright-white", - parse(try_from_str = colors::parse_color))] - pub match_bg: Box, - - /// Foreground color for the focused match. - #[clap(long, default_value = "magenta", - parse(try_from_str = colors::parse_color))] - pub focused_fg: Box, - - /// Background color for the focused match. - #[clap(long, default_value = "bright-white", - parse(try_from_str = colors::parse_color))] - pub focused_bg: Box, - - /// Foreground color for hints. - #[clap(long, default_value = "white", - parse(try_from_str = colors::parse_color))] - pub hint_fg: Box, - - /// Background color for hints. - #[clap(long, default_value = "magenta", - parse(try_from_str = colors::parse_color))] - pub hint_bg: Box, -}