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
+15 -20
View File
@@ -35,6 +35,7 @@ a8" "8a `Y8, ,8P' 88 ,a8" a8P_____88 88P' "Y8
const NAME: &str = env!("CARGO_PKG_NAME"); const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
const REPO: &str = env!("CARGO_PKG_REPOSITORY"); const REPO: &str = env!("CARGO_PKG_REPOSITORY");
const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
const ORANGE: Color = Color::Rgb(255, 178, 36); const ORANGE: Color = Color::Rgb(255, 178, 36);
const MARGIN: &str = " "; const MARGIN: &str = " ";
@@ -45,7 +46,9 @@ fn generate_block<'a>(
app_data: &Arc<Mutex<AppData>>, app_data: &Arc<Mutex<AppData>>,
selected_panel: &SelectablePanel, selected_panel: &SelectablePanel,
) -> Block<'a> { ) -> 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 { if let Some(panel) = selectable_panel {
let title = match panel { let title = match panel {
@@ -66,8 +69,7 @@ fn generate_block<'a>(
// let selected_style = Style::default().fg(Color::LightCyan); // let selected_style = Style::default().fg(Color::LightCyan);
// let selected_border = BorderType::Plain; // let selected_border = BorderType::Plain;
// let selected_border = BorderType::Rounded; // let selected_border = BorderType::Rounded;
block = block block = block.border_style(Style::default().fg(Color::LightCyan));
.border_style(Style::default().fg(Color::LightCyan));
// .border_type(BorderType::Rounded); // .border_type(BorderType::Rounded);
} }
} }
@@ -173,7 +175,12 @@ pub fn draw_containers<B: Backend>(
state_style, state_style,
), ),
Span::styled( Span::styled(
format!("{}{:>width$}", MARGIN, i.id.chars().take(8).collect::<String>(), width = widths.id.1), format!(
"{}{:>width$}",
MARGIN,
i.id.chars().take(8).collect::<String>(),
width = widths.id.1
),
blue, blue,
), ),
Span::styled( Span::styled(
@@ -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()); .push_str(format!("{}{:>width$}", MARGIN, columns.cpu.0, width = columns.cpu.1).as_str());
column_headings column_headings
.push_str(format!("{}{:>width$}", MARGIN, columns.mem.0, width = columns.mem.1).as_str()); .push_str(format!("{}{:>width$}", MARGIN, columns.mem.0, width = columns.mem.1).as_str());
column_headings.push_str( column_headings
format!( .push_str(format!("{}{:>width$}", MARGIN, columns.id.0, width = columns.id.1).as_str());
"{}{:>width$}",
MARGIN,
columns.id.0,
width = columns.id.1
)
.as_str(),
);
column_headings.push_str( column_headings.push_str(
format!( format!(
"{}{:>width$}", "{}{:>width$}",
@@ -471,7 +471,7 @@ pub fn draw_heading_bar<B: Backend>(
pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) { pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
let title = format!(" {} ", VERSION); 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"); 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 ( ↑ ↓ ← → ) mto change selected line");
@@ -480,14 +480,11 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
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 ( 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 ( q ) to quit at any time");
help_text.push_str("\n mouse scrolling & clicking also available"); help_text.push_str("\n mouse scrolling & clicking also available");
help_text help_text.push_str("\n\n currenty an early work in progress, all and any input appreciated");
.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()); help_text.push_str(format!("\n {}", REPO.trim()).as_str());
let mut max_line_width = 0; let mut max_line_width = 0;
let all_text = format!("{}{}{}", NAME_TEXT, description_text, help_text); let all_text = format!("{}{}{}", NAME_TEXT, description_text, help_text);
all_text.lines().into_iter().for_each(|line| { all_text.lines().into_iter().for_each(|line| {
@@ -508,7 +505,6 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
.block(Block::default()) .block(Block::default())
.alignment(Alignment::Center); .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)) .style(Style::default().bg(Color::Magenta).fg(Color::Black))
.block(Block::default()) .block(Block::default())
@@ -646,7 +642,6 @@ 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 /// 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 { 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 { let blank_vertical = if r.height > text_lines {
(r.height - text_lines) / 2 (r.height - text_lines) / 2