refactor: help box description from TOML

This commit is contained in:
Jack Wills
2022-04-29 01:39:21 +00:00
parent db99e61a37
commit 757103c54f
3 changed files with 70 additions and 75 deletions
+36 -41
View File
@@ -35,6 +35,7 @@ a8" "8a `Y8, ,8P' 88 ,a8" a8P_____88 88P' "Y8
const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
const REPO: &str = env!("CARGO_PKG_REPOSITORY");
const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
const ORANGE: Color = Color::Rgb(255, 178, 36);
const MARGIN: &str = " ";
@@ -45,7 +46,9 @@ fn generate_block<'a>(
app_data: &Arc<Mutex<AppData>>,
selected_panel: &SelectablePanel,
) -> Block<'a> {
let mut block = Block::default().borders(Borders::ALL).border_type(BorderType::Rounded);
let mut block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded);
if let Some(panel) = selectable_panel {
let title = match panel {
@@ -65,10 +68,9 @@ fn generate_block<'a>(
if selected_panel == &panel {
// let selected_style = Style::default().fg(Color::LightCyan);
// let selected_border = BorderType::Plain;
// let selected_border = BorderType::Rounded;
block = block
.border_style(Style::default().fg(Color::LightCyan));
// .border_type(BorderType::Rounded);
// let selected_border = BorderType::Rounded;
block = block.border_style(Style::default().fg(Color::LightCyan));
// .border_type(BorderType::Rounded);
}
}
block
@@ -172,8 +174,13 @@ pub fn draw_containers<B: Backend>(
format!("{}{:>width$}", MARGIN, mems, width = widths.mem.1),
state_style,
),
Span::styled(
format!("{}{:>width$}", MARGIN, i.id.chars().take(8).collect::<String>(), width = widths.id.1),
Span::styled(
format!(
"{}{:>width$}",
MARGIN,
i.id.chars().take(8).collect::<String>(),
width = widths.id.1
),
blue,
),
Span::styled(
@@ -337,7 +344,7 @@ fn make_chart<T: Stats + Display>(
))
.borders(Borders::ALL)
// .border_type(BorderType::Plain),
.border_type(BorderType::Rounded),
.border_type(BorderType::Rounded),
)
.x_axis(
Axis::default()
@@ -386,15 +393,8 @@ pub fn draw_heading_bar<B: Backend>(
.push_str(format!("{}{:>width$}", MARGIN, columns.cpu.0, width = columns.cpu.1).as_str());
column_headings
.push_str(format!("{}{:>width$}", MARGIN, columns.mem.0, width = columns.mem.1).as_str());
column_headings.push_str(
format!(
"{}{:>width$}",
MARGIN,
columns.id.0,
width = columns.id.1
)
.as_str(),
);
column_headings
.push_str(format!("{}{:>width$}", MARGIN, columns.id.0, width = columns.id.1).as_str());
column_headings.push_str(
format!(
"{}{:>width$}",
@@ -471,23 +471,20 @@ pub fn draw_heading_bar<B: Backend>(
pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
let title = format!(" {} ", VERSION);
let description_text = String::from("\n A basic docker container information viewer and controller");
let description_text = format!("\n{}", DESCRIPTION);
let mut help_text = String::from("\n ( tab ) or ( alt+tab ) to change panels");
help_text.push_str("\n ( ↑ ↓ ← → ) mto change selected line");
help_text.push_str("\n ( enter ) to send docker container commands");
help_text.push_str("\n ( ↑ ↓ ← → ) mto change selected line");
help_text.push_str("\n ( enter ) to send docker container commands");
help_text.push_str("\n ( h ) to toggle this help information");
help_text.push_str("\n ( m ) to toggle mouse capture - if disabled, text on screen can be selected & copied, but mouse clicks get disabled");
help_text.push_str("\n ( q ) to quit at any time");
help_text.push_str("\n ( m ) to toggle mouse capture - if disabled, text on screen can be selected & copied, but mouse clicks get disabled");
help_text.push_str("\n ( q ) to quit at any time");
help_text.push_str("\n mouse scrolling & clicking also available");
help_text
.push_str("\n\n currenty an early work in progress, all and any input appreciated");
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());
let mut max_line_width = 0;
let all_text = format!("{}{}{}", NAME_TEXT, description_text, help_text);
all_text.lines().into_iter().for_each(|line| {
@@ -508,8 +505,7 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
.block(Block::default())
.alignment(Alignment::Center);
let description_paragrpah = Paragraph::new(description_text.as_str())
let description_paragrpah = Paragraph::new(description_text.as_str())
.style(Style::default().bg(Color::Magenta).fg(Color::Black))
.block(Block::default())
.alignment(Alignment::Center);
@@ -537,7 +533,7 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
.constraints(
[
Constraint::Max(NAME_TEXT.lines().count() as u16),
Constraint::Max(description_text.lines().count() as u16),
Constraint::Max(description_text.lines().count() as u16),
Constraint::Max(help_text.lines().count() as u16),
]
.as_ref(),
@@ -547,7 +543,7 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
// Order is important here
f.render_widget(Clear, area);
f.render_widget(name_paragraph, split_popup[0]);
f.render_widget(description_paragrpah, split_popup[1]);
f.render_widget(description_paragrpah, split_popup[1]);
f.render_widget(help_paragraph, split_popup[2]);
f.render_widget(block, area);
}
@@ -646,18 +642,17 @@ pub fn draw_info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
/// draw a box in the center of the screen, 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
// Make sure blank_space can't be an negative, as will crash
let blank_vertical = if r.height > text_lines {
(r.height - text_lines) / 2
} else {
1
};
let blank_horizontal = if r.width > text_width {
(r.width - text_width) / 2
}else {
1
};
(r.height - text_lines) / 2
} else {
1
};
let blank_horizontal = if r.width > text_width {
(r.width - text_width) / 2
} else {
1
};
let vertical_constraints = box_location.get_vertical_constraints(blank_vertical, text_lines);
let horizontal_constraints =