mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-09 16:00:35 +00:00
get_color to Box<dyn color::Color> instead of heap-allocating a ref.
This commit is contained in:
parent
422eed9ecc
commit
b97519170b
@ -1,16 +1,16 @@
|
|||||||
use termion::color;
|
use termion::color;
|
||||||
|
|
||||||
pub fn get_color(color_name: &str) -> Box<&dyn color::Color> {
|
pub fn get_color(color_name: &str) -> Box<dyn color::Color> {
|
||||||
match color_name {
|
match color_name {
|
||||||
"black" => Box::new(&color::Black),
|
"black" => Box::new(color::Black),
|
||||||
"red" => Box::new(&color::Red),
|
"red" => Box::new(color::Red),
|
||||||
"green" => Box::new(&color::Green),
|
"green" => Box::new(color::Green),
|
||||||
"yellow" => Box::new(&color::Yellow),
|
"yellow" => Box::new(color::Yellow),
|
||||||
"blue" => Box::new(&color::Blue),
|
"blue" => Box::new(color::Blue),
|
||||||
"magenta" => Box::new(&color::Magenta),
|
"magenta" => Box::new(color::Magenta),
|
||||||
"cyan" => Box::new(&color::Cyan),
|
"cyan" => Box::new(color::Cyan),
|
||||||
"white" => Box::new(&color::White),
|
"white" => Box::new(color::White),
|
||||||
"default" => Box::new(&color::Reset),
|
"default" => Box::new(color::Reset),
|
||||||
_ => panic!("Unknown color: {}", color_name),
|
_ => panic!("Unknown color: {}", color_name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn match_color() {
|
fn match_color() {
|
||||||
let text1 = println!("{}{}", color::Fg(*get_color("green")), "foo");
|
let text1 = println!("{}{}", color::Fg(&*get_color("green")), "foo");
|
||||||
let text2 = println!("{}{}", color::Fg(color::Green), "foo");
|
let text2 = println!("{}{}", color::Fg(color::Green), "foo");
|
||||||
|
|
||||||
assert_eq!(text1, text2);
|
assert_eq!(text1, text2);
|
||||||
@ -30,6 +30,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn no_match_color() {
|
fn no_match_color() {
|
||||||
println!("{}{}", color::Fg(*get_color("wat")), "foo");
|
println!("{}{}", color::Fg(&*get_color("wat")), "foo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
src/view.rs
32
src/view.rs
@ -17,12 +17,12 @@ pub struct View<'a> {
|
|||||||
contrast: bool,
|
contrast: bool,
|
||||||
position: &'a str,
|
position: &'a str,
|
||||||
matches: Vec<state::Match<'a>>,
|
matches: Vec<state::Match<'a>>,
|
||||||
select_foreground_color: Box<&'a dyn color::Color>,
|
select_foreground_color: Box<dyn color::Color>,
|
||||||
select_background_color: Box<&'a dyn color::Color>,
|
select_background_color: Box<dyn color::Color>,
|
||||||
foreground_color: Box<&'a dyn color::Color>,
|
foreground_color: Box<dyn color::Color>,
|
||||||
background_color: Box<&'a dyn color::Color>,
|
background_color: Box<dyn color::Color>,
|
||||||
hint_background_color: Box<&'a dyn color::Color>,
|
hint_background_color: Box<dyn color::Color>,
|
||||||
hint_foreground_color: Box<&'a dyn color::Color>,
|
hint_foreground_color: Box<dyn color::Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CaptureEvent {
|
enum CaptureEvent {
|
||||||
@ -38,12 +38,12 @@ impl<'a> View<'a> {
|
|||||||
unique: bool,
|
unique: bool,
|
||||||
contrast: bool,
|
contrast: bool,
|
||||||
position: &'a str,
|
position: &'a str,
|
||||||
select_foreground_color: Box<&'a dyn color::Color>,
|
select_foreground_color: Box<dyn color::Color>,
|
||||||
select_background_color: Box<&'a dyn color::Color>,
|
select_background_color: Box<dyn color::Color>,
|
||||||
foreground_color: Box<&'a dyn color::Color>,
|
foreground_color: Box<dyn color::Color>,
|
||||||
background_color: Box<&'a dyn color::Color>,
|
background_color: Box<dyn color::Color>,
|
||||||
hint_foreground_color: Box<&'a dyn color::Color>,
|
hint_foreground_color: Box<dyn color::Color>,
|
||||||
hint_background_color: Box<&'a dyn color::Color>,
|
hint_background_color: Box<dyn color::Color>,
|
||||||
) -> View<'a> {
|
) -> View<'a> {
|
||||||
let matches = state.matches(reverse, unique);
|
let matches = state.matches(reverse, unique);
|
||||||
let skip = if reverse { matches.len() - 1 } else { 0 };
|
let skip = if reverse { matches.len() - 1 } else { 0 };
|
||||||
@ -119,8 +119,8 @@ impl<'a> View<'a> {
|
|||||||
print!(
|
print!(
|
||||||
"{goto}{background}{foregroud}{text}{resetf}{resetb}",
|
"{goto}{background}{foregroud}{text}{resetf}{resetb}",
|
||||||
goto = cursor::Goto(offset + 1, mat.y as u16 + 1),
|
goto = cursor::Goto(offset + 1, mat.y as u16 + 1),
|
||||||
foregroud = color::Fg(**selected_color),
|
foregroud = color::Fg(&**selected_color),
|
||||||
background = color::Bg(**selected_background_color),
|
background = color::Bg(&**selected_background_color),
|
||||||
resetf = color::Fg(color::Reset),
|
resetf = color::Fg(color::Reset),
|
||||||
resetb = color::Bg(color::Reset),
|
resetb = color::Bg(color::Reset),
|
||||||
text = &text
|
text = &text
|
||||||
@ -140,8 +140,8 @@ impl<'a> View<'a> {
|
|||||||
print!(
|
print!(
|
||||||
"{goto}{background}{foregroud}{text}{resetf}{resetb}",
|
"{goto}{background}{foregroud}{text}{resetf}{resetb}",
|
||||||
goto = cursor::Goto(final_position as u16 + 1, mat.y as u16 + 1),
|
goto = cursor::Goto(final_position as u16 + 1, mat.y as u16 + 1),
|
||||||
foregroud = color::Fg(*self.hint_foreground_color),
|
foregroud = color::Fg(&*self.hint_foreground_color),
|
||||||
background = color::Bg(*self.hint_background_color),
|
background = color::Bg(&*self.hint_background_color),
|
||||||
resetf = color::Fg(color::Reset),
|
resetf = color::Fg(color::Reset),
|
||||||
resetb = color::Bg(color::Reset),
|
resetb = color::Bg(color::Reset),
|
||||||
text = &text
|
text = &text
|
||||||
|
Loading…
Reference in New Issue
Block a user