mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 16:10:07 +01:00
refactor: UiColors -> colors module
This commit is contained in:
parent
de1aa3889c
commit
d119ce6b0d
4 changed files with 50 additions and 49 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::error;
|
use crate::error;
|
||||||
|
use clap::Clap;
|
||||||
use termion::color;
|
use termion::color;
|
||||||
|
|
||||||
pub fn parse_color(src: &str) -> Result<Box<dyn color::Color>, error::ParseError> {
|
pub fn parse_color(src: &str) -> Result<Box<dyn color::Color>, error::ParseError> {
|
||||||
|
|
@ -45,3 +46,49 @@ mod tests {
|
||||||
assert!(parse_color("wat").is_err(), "this color should not exist");
|
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<dyn color::Color>,
|
||||||
|
|
||||||
|
/// Background color for base text.
|
||||||
|
#[clap(long, default_value = "bright-white", parse(try_from_str = parse_color))]
|
||||||
|
pub text_bg: Box<dyn color::Color>,
|
||||||
|
|
||||||
|
/// Foreground color for matches.
|
||||||
|
#[clap(long, default_value = "yellow",
|
||||||
|
parse(try_from_str = parse_color))]
|
||||||
|
pub match_fg: Box<dyn color::Color>,
|
||||||
|
|
||||||
|
/// Background color for matches.
|
||||||
|
#[clap(long, default_value = "bright-white",
|
||||||
|
parse(try_from_str = parse_color))]
|
||||||
|
pub match_bg: Box<dyn color::Color>,
|
||||||
|
|
||||||
|
/// Foreground color for the focused match.
|
||||||
|
#[clap(long, default_value = "magenta",
|
||||||
|
parse(try_from_str = parse_color))]
|
||||||
|
pub focused_fg: Box<dyn color::Color>,
|
||||||
|
|
||||||
|
/// Background color for the focused match.
|
||||||
|
#[clap(long, default_value = "bright-white",
|
||||||
|
parse(try_from_str = parse_color))]
|
||||||
|
pub focused_bg: Box<dyn color::Color>,
|
||||||
|
|
||||||
|
/// Foreground color for hints.
|
||||||
|
#[clap(long, default_value = "white",
|
||||||
|
parse(try_from_str = parse_color))]
|
||||||
|
pub hint_fg: Box<dyn color::Color>,
|
||||||
|
|
||||||
|
/// Background color for hints.
|
||||||
|
#[clap(long, default_value = "magenta",
|
||||||
|
parse(try_from_str = parse_color))]
|
||||||
|
pub hint_bg: Box<dyn color::Color>,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ pub struct CliOpt {
|
||||||
unique_hint: bool,
|
unique_hint: bool,
|
||||||
|
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
colors: ui::UiColors,
|
colors: colors::UiColors,
|
||||||
|
|
||||||
/// Align hint with its match.
|
/// Align hint with its match.
|
||||||
#[clap(long, arg_enum, default_value = "leading")]
|
#[clap(long, arg_enum, default_value = "leading")]
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,4 @@
|
||||||
|
|
||||||
mod vc;
|
mod vc;
|
||||||
pub use vc::ViewController;
|
pub use vc::ViewController;
|
||||||
pub use vc::{HintAlignment, HintStyle, UiColors};
|
pub use vc::{HintAlignment, HintStyle};
|
||||||
|
|
|
||||||
48
src/ui/vc.rs
48
src/ui/vc.rs
|
|
@ -8,7 +8,7 @@ use sequence_trie::SequenceTrie;
|
||||||
use termion::{self, color, cursor, event, style};
|
use termion::{self, color, cursor, event, style};
|
||||||
|
|
||||||
use crate::error::ParseError;
|
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> {
|
pub struct ViewController<'a> {
|
||||||
model: &'a mut model::Model<'a>,
|
model: &'a mut model::Model<'a>,
|
||||||
|
|
@ -1115,49 +1115,3 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
assert_eq!(writer, expected.as_bytes());
|
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<dyn color::Color>,
|
|
||||||
|
|
||||||
/// Background color for base text.
|
|
||||||
#[clap(long, default_value = "bright-white", parse(try_from_str = colors::parse_color))]
|
|
||||||
pub text_bg: Box<dyn color::Color>,
|
|
||||||
|
|
||||||
/// Foreground color for matches.
|
|
||||||
#[clap(long, default_value = "yellow",
|
|
||||||
parse(try_from_str = colors::parse_color))]
|
|
||||||
pub match_fg: Box<dyn color::Color>,
|
|
||||||
|
|
||||||
/// Background color for matches.
|
|
||||||
#[clap(long, default_value = "bright-white",
|
|
||||||
parse(try_from_str = colors::parse_color))]
|
|
||||||
pub match_bg: Box<dyn color::Color>,
|
|
||||||
|
|
||||||
/// Foreground color for the focused match.
|
|
||||||
#[clap(long, default_value = "magenta",
|
|
||||||
parse(try_from_str = colors::parse_color))]
|
|
||||||
pub focused_fg: Box<dyn color::Color>,
|
|
||||||
|
|
||||||
/// Background color for the focused match.
|
|
||||||
#[clap(long, default_value = "bright-white",
|
|
||||||
parse(try_from_str = colors::parse_color))]
|
|
||||||
pub focused_bg: Box<dyn color::Color>,
|
|
||||||
|
|
||||||
/// Foreground color for hints.
|
|
||||||
#[clap(long, default_value = "white",
|
|
||||||
parse(try_from_str = colors::parse_color))]
|
|
||||||
pub hint_fg: Box<dyn color::Color>,
|
|
||||||
|
|
||||||
/// Background color for hints.
|
|
||||||
#[clap(long, default_value = "magenta",
|
|
||||||
parse(try_from_str = colors::parse_color))]
|
|
||||||
pub hint_bg: Box<dyn color::Color>,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue