Skip to content

Commit f388b6a

Browse files
committed
feat: show total file size
1 parent 0f6e6e3 commit f388b6a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ impl LogViewerApp {
678678
(false, _, total_len) => as_string_with_separators(total_len),
679679
};
680680
ui.label(format!("# Rows: {row_count_text}"));
681+
ui.label(format!("Size: {}", data.file_size));
681682
}
682683
});
683684
}

src/app/data.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
22
calculate_hash,
3-
data_display_options::{DataDisplayOptions, LevelConversion, RowParseErrorHandling},
3+
data_display_options::{DataDisplayOptions, LevelConversion, RowParseErrorHandling, SizeUnits},
44
};
55
use anyhow::Context;
66
use data_iter::DataIter;
@@ -25,6 +25,7 @@ pub struct Data {
2525
rows: Vec<LogRow>,
2626
filtered_rows: Option<Vec<usize>>,
2727
applied_filter: Option<FilterConfig>,
28+
pub file_size: String,
2829
}
2930

3031
#[derive(serde::Deserialize, serde::Serialize, Default, Debug, PartialEq, Eq, Clone)]
@@ -451,7 +452,17 @@ impl TryFrom<(&DataDisplayOptions, &str)> for Data {
451452
fn try_from(
452453
(data_display_options, value): (&DataDisplayOptions, &str),
453454
) -> Result<Self, Self::Error> {
454-
let mut result = Data::default();
455+
let file_size = SizeUnits::Auto.convert(value.len());
456+
let file_size = file_size
457+
.as_str()
458+
.map(|x| x.to_string())
459+
.unwrap_or_else(|| file_size.to_string())
460+
.trim_matches('0')
461+
.to_string();
462+
let mut result = Data {
463+
file_size,
464+
..Default::default()
465+
};
455466
for (i, line) in value.lines().enumerate() {
456467
let row = LogRow::try_from((data_display_options, i, line))
457468
.with_context(|| format!("failed to parse line {}", i + 1))?;

0 commit comments

Comments
 (0)