Skip to content

Commit e9b1c87

Browse files
committed
Don't crash if fail to read file.
Also, various visual cleanup.
1 parent 8837dc7 commit e9b1c87

File tree

3 files changed

+70
-54
lines changed

3 files changed

+70
-54
lines changed

src/app/filtered_log_entries_tab.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use std::{
55
};
66

77
use egui::Ui;
8-
use grep::searcher::{sinks::Lossy, Searcher};
8+
use grep::searcher::{Searcher, sinks::Lossy};
99
use grep_regex::RegexMatcherBuilder;
1010
use log::error;
1111

1212
use super::{
1313
log_entries_table::LogEntriesTable,
1414
log_file_reader::{LineNumber, LogFileReader},
15-
log_view::{LogViewTabTrait, LogViewerState},
15+
log_view::{LogViewerState, LogViewTabTrait},
1616
};
1717

1818
#[derive(Debug)]

src/app/log_entries_table.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ impl<'a> LogEntriesTable<'a> {
2121
image_source: ImageSource<'_>,
2222
hover_text: &str,
2323
) -> Response {
24-
ui.add_sized(
25-
Vec2::new(14.0, 14.0),
26-
Button::image(image_source).frame(false),
27-
)
28-
.on_hover_cursor(CursorIcon::PointingHand)
29-
.on_hover_text(hover_text)
24+
ui.add_sized(Vec2::new(18.0, 18.0), Button::image(image_source))
25+
.on_hover_cursor(CursorIcon::PointingHand)
26+
.on_hover_text(hover_text)
3027
}
3128

3229
pub fn new() -> Self {
@@ -67,8 +64,10 @@ impl<'a> LogEntriesTable<'a> {
6764
.max_scroll_height(f32::INFINITY)
6865
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
6966
.striped(true)
67+
.auto_shrink(false)
68+
.min_scrolled_height(0.0)
7069
.sense(egui::Sense::click());
71-
70+
7271
let mut col_iter = viewer_state.displayed_columns.iter().peekable();
7372
while let Some(col_key) = col_iter.next() {
7473
let is_last_col = col_iter.peek().is_none();
@@ -96,7 +95,7 @@ impl<'a> LogEntriesTable<'a> {
9695
}
9796

9897
table_builder
99-
.header(18.0, |mut row| {
98+
.header(24.0, |mut row| {
10099
let columns_displayed_count = viewer_state.displayed_columns.len();
101100
let mut columns_to_remove: Vec<String> = vec![];
102101
for displayed_column in &viewer_state.displayed_columns {
@@ -155,7 +154,19 @@ impl<'a> LogEntriesTable<'a> {
155154
row: &mut TableRow<'_, '_>,
156155
line_num: LineNumber,
157156
) -> Option<()> {
158-
let log_line = log_file_reader.read_line(line_num)?;
157+
let log_line_opt = log_file_reader.read_line(line_num);
158+
159+
if log_line_opt.is_none() {
160+
row.col(|ui| {
161+
ui.label(
162+
RichText::new("⚠ Failed to read from log file.")
163+
.color(ui.visuals().warn_fg_color),
164+
);
165+
});
166+
return None;
167+
}
168+
169+
let log_line = log_line_opt.unwrap();
159170

160171
match LogFileReader::parse_logline(&log_line) {
161172
Some(log_entry) => {
@@ -194,8 +205,6 @@ impl<'a> LogEntriesTable<'a> {
194205
}
195206
}
196207
None => {
197-
row.col(|_| {});
198-
row.col(|_| {});
199208
row.col(|ui| {
200209
ui.label(
201210
RichText::new(log_line.trim())

src/app/log_entry_context_tab.rs

+48-41
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use egui::{
2-
include_image, Button, Color32, CursorIcon, ImageSource, Response, RichText, Sense, Vec2,
2+
Button, Color32, CursorIcon, ImageSource, include_image, Response, RichText, Sense, Vec2,
33
};
44
use egui_extras::{Column, TableBuilder};
55
use egui_toast::ToastKind;
66

77
use super::{
88
log_file_reader::LogFileReader,
9-
log_view::{LogViewTabTrait, LogViewerState},
9+
log_view::{LogViewerState, LogViewTabTrait},
1010
};
1111

1212
pub struct LogEntryContextTab {}
@@ -21,12 +21,9 @@ impl LogEntryContextTab {
2121
image_source: ImageSource<'_>,
2222
hover_text: &str,
2323
) -> Response {
24-
ui.add_sized(
25-
Vec2::new(14.0, 14.0),
26-
Button::image(image_source).frame(false),
27-
)
28-
.on_hover_cursor(CursorIcon::PointingHand)
29-
.on_hover_text(hover_text)
24+
ui.add_sized(Vec2::new(18.0, 18.0), Button::image(image_source))
25+
.on_hover_text(hover_text)
26+
.on_hover_cursor(CursorIcon::PointingHand)
3027
}
3128
}
3229

@@ -52,10 +49,16 @@ impl LogViewTabTrait for LogEntryContextTab {
5249
return;
5350
}
5451

52+
let row_height_padding = 6.0;
53+
let row_content_height = 14.0;
54+
5555
let log_entry = read_log_entry.unwrap();
5656

5757
TableBuilder::new(ui)
5858
.striped(true)
59+
.min_scrolled_height(0.0)
60+
.max_scroll_height(f32::INFINITY)
61+
.auto_shrink(false)
5962
.sense(Sense::hover())
6063
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
6164
.column(Column::auto())
@@ -67,45 +70,49 @@ impl LogViewTabTrait for LogEntryContextTab {
6770
let key_str = entry.0;
6871
let value_str = entry.1.to_string();
6972
let line_count = value_str.chars().filter(|c| *c == '\n').count() + 1;
70-
body.row((line_count as f32) * 16.0, |mut row| {
71-
row.col(|ui| {
72-
let column_is_shown =
73-
viewer_state.displayed_columns.iter().any(|s| s == key_str);
74-
if !column_is_shown {
75-
let add_icon =
76-
include_image!("../../assets/icons8-add-48-white.png");
77-
if Self::add_tool_button(ui, add_icon, "Add Column").clicked() {
78-
viewer_state.displayed_columns.push(key_str.to_string());
73+
body.row(
74+
(line_count as f32) * row_content_height + row_height_padding,
75+
|mut row| {
76+
row.col(|ui| {
77+
let column_is_shown =
78+
viewer_state.displayed_columns.iter().any(|s| s == key_str);
79+
if !column_is_shown {
80+
let add_icon =
81+
include_image!("../../assets/icons8-add-48-white.png");
82+
if Self::add_tool_button(ui, add_icon, "Add Column").clicked() {
83+
viewer_state.displayed_columns.push(key_str.to_string());
84+
85+
viewer_state.add_toast(
86+
ToastKind::Info,
87+
format!("Added column '{}'", key_str).into(),
88+
2.0,
89+
);
90+
}
91+
}
92+
});
93+
row.col(|ui| {
94+
ui.label(RichText::new(key_str).color(Color32::WHITE).monospace());
95+
});
96+
row.col(|ui| {
97+
let copy_icon =
98+
include_image!("../../assets/icons8-copy-48-white.png");
99+
if Self::add_tool_button(ui, copy_icon, "Copy Value").clicked() {
100+
ui.output_mut(|o| {
101+
o.copied_text = value_str.clone();
102+
});
79103

80104
viewer_state.add_toast(
81105
ToastKind::Info,
82-
format!("Added column '{}'", key_str).into(),
106+
"Copied value to clipboard.".into(),
83107
2.0,
84108
);
85109
}
86-
}
87-
});
88-
row.col(|ui| {
89-
ui.label(RichText::new(key_str).color(Color32::WHITE).monospace());
90-
});
91-
row.col(|ui| {
92-
let copy_icon = include_image!("../../assets/icons8-copy-48-white.png");
93-
if Self::add_tool_button(ui, copy_icon, "Copy Value").clicked() {
94-
ui.output_mut(|o| {
95-
o.copied_text = value_str.clone();
96-
});
97-
98-
viewer_state.add_toast(
99-
ToastKind::Info,
100-
"Copied value to clipboard.".into(),
101-
2.0,
102-
);
103-
}
104-
});
105-
row.col(|ui| {
106-
ui.label(RichText::new(value_str.trim()).monospace());
107-
});
108-
});
110+
});
111+
row.col(|ui| {
112+
ui.label(RichText::new(value_str.trim()).monospace());
113+
});
114+
},
115+
);
109116
}
110117
});
111118
}

0 commit comments

Comments
 (0)