lsmem: Fix specified --output columns with raw print
This commit is contained in:
parent
57b9c1f0f4
commit
924537e792
@ -242,12 +242,6 @@ impl TableRow {
|
|||||||
self.range, self.size, self.state, self.removable, self.block
|
self.range, self.size, self.state, self.removable, self.block
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn to_raw_string(&self) -> String {
|
|
||||||
format!(
|
|
||||||
r#"{} {} {} {} {}"#,
|
|
||||||
self.range, self.size, self.state, self.removable, self.block
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@ -538,7 +532,7 @@ fn print_table(lsmem: &Lsmem, opts: &Options) {
|
|||||||
let table_rows = create_table_rows(lsmem, opts);
|
let table_rows = create_table_rows(lsmem, opts);
|
||||||
let mut col_widths = vec![0; opts.columns.len()];
|
let mut col_widths = vec![0; opts.columns.len()];
|
||||||
|
|
||||||
// Initialize column widths based on column names
|
// Initialize column widths based on pre-defined width hints
|
||||||
for (i, column) in opts.columns.iter().enumerate() {
|
for (i, column) in opts.columns.iter().enumerate() {
|
||||||
col_widths[i] = column.get_width_hint();
|
col_widths[i] = column.get_width_hint();
|
||||||
}
|
}
|
||||||
@ -611,19 +605,25 @@ fn print_pairs(lsmem: &Lsmem, opts: &Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn print_raw(lsmem: &Lsmem, opts: &Options) {
|
fn print_raw(lsmem: &Lsmem, opts: &Options) {
|
||||||
|
let table_rows = create_table_rows(lsmem, opts);
|
||||||
|
|
||||||
if !opts.noheadings {
|
if !opts.noheadings {
|
||||||
println!("RANGE SIZE STATE REMOVABLE BLOCK");
|
let headings = opts
|
||||||
|
.columns
|
||||||
|
.iter()
|
||||||
|
.map(|col| col.get_name().to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
println!("{}", headings.join(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
let table_rows = create_table_rows(lsmem, opts);
|
|
||||||
let mut table_raw_string = String::new();
|
|
||||||
for row in table_rows {
|
for row in table_rows {
|
||||||
table_raw_string += &row.to_raw_string();
|
let columns = opts
|
||||||
table_raw_string += "\n";
|
.columns
|
||||||
|
.iter()
|
||||||
|
.map(|col| row.get_value(col).to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
println!("{}", columns.join(" "));
|
||||||
}
|
}
|
||||||
// remove the last newline
|
|
||||||
table_raw_string.pop();
|
|
||||||
println!("{table_raw_string}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_summary(lsmem: &Lsmem, opts: &Options) {
|
fn print_summary(lsmem: &Lsmem, opts: &Options) {
|
||||||
|
@ -31,14 +31,13 @@ fn test_columns_table() {
|
|||||||
sysroot_test_with_args("test_lsmem_columns_table.expected", &["-o", "block,size"]);
|
sysroot_test_with_args("test_lsmem_columns_table.expected", &["-o", "block,size"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FAILS, COMMENT FOR NOW - TODO
|
#[test]
|
||||||
// #[test]
|
fn test_columns_raw() {
|
||||||
// fn test_columns_raw() {
|
sysroot_test_with_args(
|
||||||
// sysroot_test_with_args(
|
"test_lsmem_columns_raw.expected",
|
||||||
// "test_lsmem_columns_raw.expected",
|
&["-o", "block,size", "-r"],
|
||||||
// &["-o", "block,size", "-r"],
|
);
|
||||||
// );
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// FAILS, COMMENT FOR NOW - TODO
|
// FAILS, COMMENT FOR NOW - TODO
|
||||||
// #[test]
|
// #[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user