mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-15 01:13:53 +01:00
feat: copyrat
This commit is contained in:
parent
0d45a2872a
commit
37f22b67af
11 changed files with 840 additions and 728 deletions
|
|
@ -1,35 +1,39 @@
|
|||
use crate::error;
|
||||
use termion::color;
|
||||
|
||||
pub fn get_color(color_name: &str) -> Box<&dyn color::Color> {
|
||||
match color_name {
|
||||
"black" => Box::new(&color::Black),
|
||||
"red" => Box::new(&color::Red),
|
||||
"green" => Box::new(&color::Green),
|
||||
"yellow" => Box::new(&color::Yellow),
|
||||
"blue" => Box::new(&color::Blue),
|
||||
"magenta" => Box::new(&color::Magenta),
|
||||
"cyan" => Box::new(&color::Cyan),
|
||||
"white" => Box::new(&color::White),
|
||||
"default" => Box::new(&color::Reset),
|
||||
_ => panic!("Unknown color: {}", color_name),
|
||||
}
|
||||
pub fn parse_color(src: &str) -> Result<Box<dyn color::Color>, error::ParseError> {
|
||||
match src {
|
||||
"black" => Ok(Box::new(color::Black)),
|
||||
"red" => Ok(Box::new(color::Red)),
|
||||
"green" => Ok(Box::new(color::Green)),
|
||||
"yellow" => Ok(Box::new(color::Yellow)),
|
||||
"blue" => Ok(Box::new(color::Blue)),
|
||||
"magenta" => Ok(Box::new(color::Magenta)),
|
||||
"cyan" => Ok(Box::new(color::Cyan)),
|
||||
"white" => Ok(Box::new(color::White)),
|
||||
// "default" => Ok(Box::new(color::Reset)),
|
||||
_ => Err(error::ParseError::UnknownColor),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn match_color() {
|
||||
let text1 = println!("{}{}", color::Fg(*get_color("green")), "foo");
|
||||
let text2 = println!("{}{}", color::Fg(color::Green), "foo");
|
||||
#[test]
|
||||
fn match_color() {
|
||||
let text1 = format!(
|
||||
"{}{}",
|
||||
color::Fg(parse_color("green").unwrap().as_ref()),
|
||||
"foo"
|
||||
);
|
||||
let text2 = format!("{}{}", color::Fg(color::Green), "foo");
|
||||
|
||||
assert_eq!(text1, text2);
|
||||
}
|
||||
assert_eq!(text1, text2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn no_match_color() {
|
||||
println!("{}{}", color::Fg(*get_color("wat")), "foo");
|
||||
}
|
||||
#[test]
|
||||
fn no_match_color() {
|
||||
assert!(parse_color("wat").is_err(), "this color should not exist");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue