String optimizations
This commit is contained in:
parent
6109785e63
commit
3929a4a277
2 changed files with 13 additions and 13 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use std::borrow::Cow;
|
||||
use std::cmp::min;
|
||||
|
||||
use crate::i18n::t;
|
||||
|
|
@ -52,12 +53,7 @@ pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut Dashb
|
|||
height: visible_height as u16,
|
||||
};
|
||||
|
||||
render_group(
|
||||
main_frame,
|
||||
group_area,
|
||||
group,
|
||||
half > rendered_height ,
|
||||
);
|
||||
render_group(main_frame, group_area, group, half > rendered_height);
|
||||
|
||||
current_y += visible_height;
|
||||
rendered_height += visible_height;
|
||||
|
|
@ -178,10 +174,14 @@ fn create_monitor_item(monitor: &MonitorViewState) -> Row<'_> {
|
|||
let status_icon = get_status_emoji(&monitor.status);
|
||||
let status_color = get_status_color(&monitor.status);
|
||||
|
||||
let display_name: String = if monitor.name.len() > MAX_NAME_LENGTH {
|
||||
format!("{:.width$}...", &monitor.name, width = MAX_NAME_LENGTH - 3)
|
||||
let display_name: Cow<str> = if monitor.name.len() > MAX_NAME_LENGTH {
|
||||
Cow::Owned(format!(
|
||||
"{:.width$}...",
|
||||
monitor.name,
|
||||
width = MAX_NAME_LENGTH - 3
|
||||
))
|
||||
} else {
|
||||
monitor.name.clone()
|
||||
Cow::Borrowed(&monitor.name)
|
||||
};
|
||||
|
||||
let response_text = format!("{:>7}ms", monitor.response_time);
|
||||
|
|
@ -191,7 +191,7 @@ fn create_monitor_item(monitor: &MonitorViewState) -> Row<'_> {
|
|||
|
||||
Row::new(vec![
|
||||
get_formated_line(format!("{} ", status_icon), status_color, Modifier::empty()),
|
||||
get_formated_line(display_name, Color::White, Modifier::empty()),
|
||||
get_formated_line(display_name.to_string(), Color::White, Modifier::empty()),
|
||||
get_formated_line(response_text, Color::Cyan, Modifier::empty()),
|
||||
get_formated_line(uptime_text, Color::Magenta, Modifier::empty()),
|
||||
status_line_spans,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::data::heartbeat::model::HeartbeatEntry;
|
|||
use crate::i18n::t;
|
||||
use ratatui::widgets::ScrollbarState;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use std::borrow::Cow;
|
||||
pub const BORDER_LINES_VIEW: usize = 3;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
@ -15,7 +15,7 @@ pub enum MonitorStatus {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MonitorViewState {
|
||||
pub name: String,
|
||||
pub name: Cow<'static, str>,
|
||||
pub status: MonitorStatus,
|
||||
pub response_time: String,
|
||||
pub uptime_24h: String,
|
||||
|
|
@ -141,7 +141,7 @@ fn add_monitor_view_state(group: UnifiedGroupData) -> Vec<MonitorViewState> {
|
|||
.unwrap_or_else(|| t("unknown").to_string());
|
||||
|
||||
MonitorViewState {
|
||||
name: monitor.name,
|
||||
name: Cow::Owned(monitor.name),
|
||||
status,
|
||||
response_time,
|
||||
uptime_24h,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue