Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewrite column algorithm #227

Merged
merged 12 commits into from
Sep 10, 2020
Prev Previous commit
Next Next commit
mooooooo. Move to cows.
  • Loading branch information
ClementTsang committed Sep 9, 2020
commit a08a08d41b4b5f70ce236e21d34d801ab68b3e3a
11 changes: 6 additions & 5 deletions src/canvas/widgets/disk_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
},
constants::*,
};
use std::borrow::Cow;

const DISK_HEADERS: [&str; 7] = ["Disk", "Mount", "Used", "Free", "Total", "R/s", "W/s"];

Expand Down Expand Up @@ -115,18 +116,18 @@ impl DiskTableWidget for Painter {
// Truncate with ellipsis
let (first, _last) =
entry.split_at(*calculated_col_width as usize - 1);
format!("{}…", first)
Cow::Owned(format!("{}…", first))
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
},
);
Expand Down
13 changes: 7 additions & 6 deletions src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tui::{
widgets::{Block, Borders, Paragraph, Row, Table, Text},
};

use std::borrow::Cow;
use unicode_segmentation::{GraphemeIndices, UnicodeSegmentation};
use unicode_width::UnicodeWidthStr;

Expand Down Expand Up @@ -342,25 +343,25 @@ impl ProcessTableWidget for Painter {
&& *calculated_col_width > 0
{
if let Some(alternative) = alternative {
alternative.clone()
Cow::Borrowed(alternative)
} else if entry.len() > *calculated_col_width as usize
&& *calculated_col_width > 1
{
// Truncate with ellipsis
let (first, _last) =
entry.split_at(*calculated_col_width as usize - 1);
format!("{}…", first)
Cow::Owned(format!("{}…", first))
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
},
);
Expand Down
11 changes: 6 additions & 5 deletions src/canvas/widgets/temp_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
},
constants::*,
};
use std::borrow::Cow;

const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"];

Expand Down Expand Up @@ -115,18 +116,18 @@ impl TempTableWidget for Painter {
// Truncate with ellipsis
let (first, _last) =
entry.split_at(*calculated_col_width as usize - 1);
format!("{}…", first)
Cow::Owned(format!("{}…", first))
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
} else {
entry.clone()
Cow::Borrowed(entry)
}
},
);
Expand Down
4 changes: 2 additions & 2 deletions src/data_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,9 @@ pub fn group_process_data(
wps_f64: p.write_per_sec,
tr_f64: p.total_read,
tw_f64: p.total_write,
process_state: p.process_state, // TODO: What the heck
process_state: p.process_state,
process_description_prefix: None,
process_char: char::default(), // TODO: What the heck
process_char: char::default(),
is_disabled_entry: false,
}
})
Expand Down