Skip to content

Commit

Permalink
refactor(table): prepare selectable history entry
Browse files Browse the repository at this point in the history
the last entry is now bold instead of highlighting the last one always
  • Loading branch information
EdJoPaTo committed Oct 30, 2023
1 parent c6cb1d4 commit a0aa9f4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/interactive/details/history/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ fn draw_table(
) {
let mut title = format!("History ({}", topic_history.len());

let last_index = topic_history.len().saturating_sub(1);

let without_retain = topic_history
.iter()
.filter(|o| !matches!(o.time, Time::Retained))
Expand Down Expand Up @@ -76,7 +78,7 @@ fn draw_table(
}
title += ")";

let rows = topic_history.iter().map(|entry| {
let rows = topic_history.iter().enumerate().map(|(index, entry)| {
let time = entry.time.to_string();
let qos = format::qos(entry.qos).to_string();
let value = match &entry.payload {
Expand All @@ -86,7 +88,12 @@ fn draw_table(
.unwrap_or(json)
.to_string(),
};
Row::new(vec![time, qos, value])
let row = Row::new(vec![time, qos, value]);
if index == last_index {
row.style(STYLE_BOLD)
} else {
row
}
});

let t = Table::new(rows)
Expand Down

0 comments on commit a0aa9f4

Please sign in to comment.