docs: comments improved

This commit is contained in:
Jack Wills
2022-05-30 14:30:25 +00:00
parent a5d7dabbd6
commit 1674db8a20
5 changed files with 23 additions and 35 deletions
+1 -2
View File
@@ -134,8 +134,6 @@ impl fmt::Display for State {
}
/// Items for the container control list
/// Should probably have a vec for each container
/// so that can remove Pause if container currently Paused etc
#[derive(Debug, Clone)]
pub enum DockerControls {
Pause,
@@ -411,6 +409,7 @@ pub struct Columns {
}
impl Columns {
//. (Column titles, minimum header string length)
pub fn new() -> Self {
Self {
state: (String::from("state"), 11),
+5 -6
View File
@@ -99,7 +99,7 @@ impl AppData {
self.error = Some(error);
}
/// Find the if of the currently selected container.
/// Find the id of the currently selected container.
/// If any containers on system, will always return a string.
/// Only returns None when no containers found.
pub fn get_selected_container_id(&self) -> Option<String> {
@@ -183,7 +183,7 @@ impl AppData {
self.containers.items.len()
}
/// Find the widths for the strings in the containers panel
/// Find the widths for the strings in the containers panel.
/// So can display nicely and evenly
pub fn get_width(&self) -> Columns {
let mut output = Columns::new();
@@ -228,11 +228,9 @@ impl AppData {
if status_count > output.status.1 {
output.status.1 = status_count;
};
if net_rx_count > output.net_rx.1 {
output.net_rx.1 = net_rx_count;
};
if net_tx_count > output.net_tx.1 {
output.net_tx.1 = net_tx_count;
};
@@ -254,7 +252,7 @@ impl AppData {
self.containers.items.iter_mut().find(|i| i.id == id)
}
/// Update container mem + cpu stats, in single function so only need to call .lock() once
/// Update container mem, cpu, & network stats, in single function so only need to call .lock() once
pub fn update_stats(
&mut self,
id: String,
@@ -318,7 +316,7 @@ impl AppData {
.as_ref()
.unwrap_or(&vec!["".to_owned()])
.get(0)
.unwrap()
.unwrap_or(&String::from(""))
.to_owned();
if let Some(c) = name.chars().next() {
if c == '/' {
@@ -391,6 +389,7 @@ impl AppData {
self.logs_parsed = true;
}
/// Update all containers logs, should only be used on first initialisation
pub fn update_all_logs(&mut self, all_logs: Vec<Vec<String>>) {
for (index, output) in all_logs.into_iter().enumerate() {
self.update_log_by_index(output, index);
-2
View File
@@ -175,8 +175,6 @@ impl InputHandler {
}
KeyCode::Enter => {
// This isn't great, just means you can't send docker commands before full initialization of the program
// could change to to if loading = true, although at the moment don't have a loading bool
// Does is matter though?
let panel = self.gui_state.lock().selected_panel;
if panel == SelectablePanel::Commands {
let option_command = self.app_data.lock().get_docker_command();
-1
View File
@@ -44,7 +44,6 @@ impl CliArgs {
docker_interval: args.docker_interval,
gui: !args.gui,
raw: args.raw,
// install: args.install,
timestamp: !args.timestamp,
}
}
+17 -24
View File
@@ -345,7 +345,7 @@ fn make_chart<T: Stats + Display>(
.fg(label_color),
),
])
// Add 0.01, so that max point is always visible?
// Add 0.01, so that max point is always visible?
.bounds([0.0, max.get_value() + 0.01]),
)
}
@@ -456,15 +456,16 @@ pub fn draw_heading_bar<B: Backend>(
f.render_widget(paragraph, split_bar[index]);
}
/// From a given &String, return the maximum number of chars on a single line
fn max_line_width(text: &str) -> usize {
let mut max_line_width = 0;
text.lines().into_iter().for_each(|line| {
let mut max_line_width = 0;
text.lines().into_iter().for_each(|line| {
let width = line.chars().count();
if width > max_line_width {
max_line_width = width;
}
});
max_line_width
max_line_width
}
/// Draw the help box in the centre of the screen
@@ -486,10 +487,10 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
help_text.push_str("\n\n currenty an early work in progress, all and any input appreciated");
help_text.push_str(format!("\n {}", REPO.trim()).as_str());
// Find the maximum line widths & height
// Find the maximum line widths & height
let all_text = format!("{}{}{}", NAME_TEXT, description_text, help_text);
let mut max_line_width = max_line_width(&all_text);
let mut lines = all_text.lines().count();
let mut max_line_width = max_line_width(&all_text);
let mut lines = all_text.lines().count();
// Add some vertical and horizontal padding to the info box
lines += 3;
@@ -567,8 +568,8 @@ pub fn draw_error<B: Backend>(f: &mut Frame<'_, B>, error: AppError, seconds: Op
text.push_str(to_push.as_str());
// Find the maximum line width & height
let mut max_line_width = max_line_width(&text);
// Find the maximum line width & height
let mut max_line_width = max_line_width(&text);
let mut lines = text.lines().count();
// Add some horizontal & vertical margins
@@ -590,21 +591,14 @@ pub fn draw_error<B: Backend>(f: &mut Frame<'_, B>, error: AppError, seconds: Op
f.render_widget(paragraph, area);
}
/// Show info box in bottom right corner
/// Draw info box in one of the 9 BoxLocations
pub fn draw_info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
let block = Block::default()
.title("")
.title_alignment(Alignment::Center)
.borders(Borders::NONE);
let mut max_line_width = 0;
text.lines().into_iter().for_each(|line| {
let width = line.chars().count();
if width > max_line_width {
max_line_width = width;
}
});
let mut max_line_width = max_line_width(&text);
let mut lines = text.lines().count();
// Add some horizontal & vertical margins
@@ -626,7 +620,7 @@ pub fn draw_info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
f.render_widget(paragraph, area);
}
/// draw a box in the center of the screen, based on max line width + number of lines
/// draw a box in the one of the BoxLocations, based on max line width + number of lines
fn draw_popup(text_lines: u16, text_width: u16, r: Rect, box_location: BoxLocation) -> Rect {
// Make sure blank_space can't be an negative, as will crash
let blank_vertical = if r.height > text_lines {
@@ -640,19 +634,18 @@ fn draw_popup(text_lines: u16, text_width: u16, r: Rect, box_location: BoxLocati
1
};
let vertical_constraints = box_location.get_vertical_constraints(blank_vertical, text_lines);
let horizontal_constraints =
box_location.get_horizontal_constraints(blank_horizontal, text_width);
let v_constraints = box_location.get_vertical_constraints(blank_vertical, text_lines);
let h_constraints = box_location.get_horizontal_constraints(blank_horizontal, text_width);
let indexes = box_location.get_indexes();
let popup_layout = Layout::default()
.direction(Direction::Vertical)
.constraints(vertical_constraints)
.constraints(v_constraints)
.split(r);
Layout::default()
.direction(Direction::Horizontal)
.constraints(horizontal_constraints)
.constraints(h_constraints)
.split(popup_layout[indexes.0])[indexes.1]
}