Skip to content

Commit

Permalink
perf(footer): generate info string once
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Nov 23, 2023
1 parent a47acd4 commit 2404f5d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/interactive/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ use crate::interactive::ElementInFocus;
const VERSION_TEXT: &str = concat!("mqttui ", env!("CARGO_PKG_VERSION"));

pub struct Footer {
broker: String,
broker: Box<str>,
full_info: Box<str>,
}

impl Footer {
pub fn new(broker: &Broker) -> Self {
Self {
broker: format!("{broker}"),
broker: format!("{broker}").into(),
full_info: format!("{VERSION_TEXT} @ {broker}").into(),
}
}

Expand Down Expand Up @@ -48,9 +50,8 @@ impl Footer {
],
});
let remaining = area.width as usize - line.width();
let full_info = format!("{VERSION_TEXT} @ {}", self.broker);
if remaining > full_info.len() {
let paragraph = Paragraph::new(full_info);
if remaining > self.full_info.len() {
let paragraph = Paragraph::new(&*self.full_info);
f.render_widget(paragraph.alignment(Alignment::Right), area);
} else if remaining > self.broker.len() {
let paragraph = Paragraph::new(&*self.broker);
Expand Down

0 comments on commit 2404f5d

Please sign in to comment.