mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 12:05:34 +00:00
perf: add cache for icon colors (#89)
This commit is contained in:
parent
b7ddb00c4e
commit
fee4ed2671
@ -47,6 +47,7 @@ pub struct Television {
|
|||||||
/// are rendered correctly even when resizing the terminal while still
|
/// are rendered correctly even when resizing the terminal while still
|
||||||
/// benefiting from a cache mechanism.
|
/// benefiting from a cache mechanism.
|
||||||
pub meta_paragraph_cache: HashMap<(String, u16, u16), Paragraph<'static>>,
|
pub meta_paragraph_cache: HashMap<(String, u16, u16), Paragraph<'static>>,
|
||||||
|
pub icon_color_cache: HashMap<String, Color>,
|
||||||
pub(crate) spinner: Spinner,
|
pub(crate) spinner: Spinner,
|
||||||
pub(crate) spinner_state: SpinnerState,
|
pub(crate) spinner_state: SpinnerState,
|
||||||
}
|
}
|
||||||
@ -81,6 +82,7 @@ impl Television {
|
|||||||
preview_pane_height: 0,
|
preview_pane_height: 0,
|
||||||
current_preview_total_lines: 0,
|
current_preview_total_lines: 0,
|
||||||
meta_paragraph_cache: HashMap::new(),
|
meta_paragraph_cache: HashMap::new(),
|
||||||
|
icon_color_cache: HashMap::new(),
|
||||||
spinner,
|
spinner,
|
||||||
spinner_state: SpinnerState::from(&spinner),
|
spinner_state: SpinnerState::from(&spinner),
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ impl Television {
|
|||||||
.result_name_fg(mode_color(self.mode)),
|
.result_name_fg(mode_color(self.mode)),
|
||||||
),
|
),
|
||||||
self.config.ui.use_nerd_font_icons,
|
self.config.ui.use_nerd_font_icons,
|
||||||
|
&mut self.icon_color_cache,
|
||||||
);
|
);
|
||||||
|
|
||||||
f.render_stateful_widget(
|
f.render_stateful_widget(
|
||||||
|
@ -8,6 +8,7 @@ use ratatui::widgets::{
|
|||||||
Block, BorderType, Borders, List, ListDirection, Padding,
|
Block, BorderType, Borders, List, ListDirection, Padding,
|
||||||
};
|
};
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use television_channels::channels::OnAir;
|
use television_channels::channels::OnAir;
|
||||||
use television_channels::entry::Entry;
|
use television_channels::entry::Entry;
|
||||||
@ -69,6 +70,7 @@ pub fn build_results_list<'a, 'b>(
|
|||||||
list_direction: ListDirection,
|
list_direction: ListDirection,
|
||||||
results_list_colors: Option<ResultsListColors>,
|
results_list_colors: Option<ResultsListColors>,
|
||||||
use_icons: bool,
|
use_icons: bool,
|
||||||
|
icon_color_cache: &mut HashMap<String, Color>,
|
||||||
) -> List<'a>
|
) -> List<'a>
|
||||||
where
|
where
|
||||||
'b: 'a,
|
'b: 'a,
|
||||||
@ -79,10 +81,21 @@ where
|
|||||||
// optional icon
|
// optional icon
|
||||||
if let Some(icon) = entry.icon.as_ref() {
|
if let Some(icon) = entry.icon.as_ref() {
|
||||||
if use_icons {
|
if use_icons {
|
||||||
|
if let Some(icon_color) = icon_color_cache.get(icon.color) {
|
||||||
spans.push(Span::styled(
|
spans.push(Span::styled(
|
||||||
icon.to_string(),
|
icon.to_string(),
|
||||||
Style::default().fg(Color::from_str(icon.color).unwrap()),
|
Style::default().fg(*icon_color),
|
||||||
));
|
));
|
||||||
|
} else {
|
||||||
|
let icon_color = Color::from_str(icon.color).unwrap();
|
||||||
|
icon_color_cache
|
||||||
|
.insert(icon.color.to_string(), icon_color);
|
||||||
|
spans.push(Span::styled(
|
||||||
|
icon.to_string(),
|
||||||
|
Style::default().fg(icon_color),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
spans.push(Span::raw(" "));
|
spans.push(Span::raw(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,6 +216,7 @@ impl Television {
|
|||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
self.config.ui.use_nerd_font_icons,
|
self.config.ui.use_nerd_font_icons,
|
||||||
|
&mut self.icon_color_cache,
|
||||||
);
|
);
|
||||||
|
|
||||||
f.render_stateful_widget(
|
f.render_stateful_widget(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user