refactor: help box description from TOML
This commit is contained in:
@@ -402,7 +402,7 @@ pub struct Columns {
|
|||||||
pub status: (String, usize),
|
pub status: (String, usize),
|
||||||
pub cpu: (String, usize),
|
pub cpu: (String, usize),
|
||||||
pub mem: (String, usize),
|
pub mem: (String, usize),
|
||||||
pub id: (String, usize),
|
pub id: (String, usize),
|
||||||
pub name: (String, usize),
|
pub name: (String, usize),
|
||||||
pub image: (String, usize),
|
pub image: (String, usize),
|
||||||
pub net_rx: (String, usize),
|
pub net_rx: (String, usize),
|
||||||
@@ -417,7 +417,7 @@ impl Columns {
|
|||||||
// 7 to allow for "100.00%"
|
// 7 to allow for "100.00%"
|
||||||
cpu: (String::from("cpu"), 7),
|
cpu: (String::from("cpu"), 7),
|
||||||
mem: (String::from("memory/limit"), 12),
|
mem: (String::from("memory/limit"), 12),
|
||||||
id: (String::from("id"), 8),
|
id: (String::from("id"), 8),
|
||||||
name: (String::from("name"), 4),
|
name: (String::from("name"), 4),
|
||||||
image: (String::from("image"), 5),
|
image: (String::from("image"), 5),
|
||||||
net_rx: (String::from("↓ rx"), 5),
|
net_rx: (String::from("↓ rx"), 5),
|
||||||
|
|||||||
+32
-32
@@ -74,40 +74,40 @@ impl InputHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn m_button(&mut self) {
|
fn m_button(&mut self) {
|
||||||
if self.mouse_capture {
|
if self.mouse_capture {
|
||||||
match execute!(std::io::stdout(), DisableMouseCapture) {
|
match execute!(std::io::stdout(), DisableMouseCapture) {
|
||||||
Ok(_) => self
|
Ok(_) => self
|
||||||
.gui_state
|
.gui_state
|
||||||
.lock()
|
.lock()
|
||||||
.set_info_box("✖ mouse capture disabled".to_owned()),
|
.set_info_box("✖ mouse capture disabled".to_owned()),
|
||||||
Err(_) => self
|
Err(_) => self
|
||||||
.app_data
|
.app_data
|
||||||
.lock()
|
.lock()
|
||||||
.set_error(AppError::MouseCapture(false)),
|
.set_error(AppError::MouseCapture(false)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match execute!(std::io::stdout(), EnableMouseCapture) {
|
match execute!(std::io::stdout(), EnableMouseCapture) {
|
||||||
Ok(_) => self
|
Ok(_) => self
|
||||||
.gui_state
|
.gui_state
|
||||||
.lock()
|
.lock()
|
||||||
.set_info_box("✓ mouse capture enabled".to_owned()),
|
.set_info_box("✓ mouse capture enabled".to_owned()),
|
||||||
Err(_) => self.app_data.lock().set_error(AppError::MouseCapture(true)),
|
Err(_) => self.app_data.lock().set_error(AppError::MouseCapture(true)),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let gui_state = Arc::clone(&self.gui_state);
|
let gui_state = Arc::clone(&self.gui_state);
|
||||||
|
|
||||||
if self.info_sleep.is_some() {
|
if self.info_sleep.is_some() {
|
||||||
self.info_sleep.as_ref().unwrap().abort()
|
self.info_sleep.as_ref().unwrap().abort()
|
||||||
}
|
}
|
||||||
self.info_sleep = Some(tokio::spawn(async move {
|
self.info_sleep = Some(tokio::spawn(async move {
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(4000)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(4000)).await;
|
||||||
gui_state.lock().reset_info_box()
|
gui_state.lock().reset_info_box()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
self.mouse_capture = !self.mouse_capture;
|
self.mouse_capture = !self.mouse_capture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle any keyboard button events
|
/// Handle any keyboard button events
|
||||||
async fn button_press(&mut self, key_code: KeyCode) {
|
async fn button_press(&mut self, key_code: KeyCode) {
|
||||||
@@ -129,7 +129,7 @@ impl InputHandler {
|
|||||||
match key_code {
|
match key_code {
|
||||||
KeyCode::Char('q') => self.is_running.store(false, Ordering::SeqCst),
|
KeyCode::Char('q') => self.is_running.store(false, Ordering::SeqCst),
|
||||||
KeyCode::Char('h') => self.gui_state.lock().show_help = false,
|
KeyCode::Char('h') => self.gui_state.lock().show_help = false,
|
||||||
KeyCode::Char('m') => self.m_button(),
|
KeyCode::Char('m') => self.m_button(),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+36
-41
@@ -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 {
|
||||||
@@ -65,10 +68,9 @@ fn generate_block<'a>(
|
|||||||
if selected_panel == &panel {
|
if selected_panel == &panel {
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
block
|
block
|
||||||
@@ -172,8 +174,13 @@ pub fn draw_containers<B: Backend>(
|
|||||||
format!("{}{:>width$}", MARGIN, mems, width = widths.mem.1),
|
format!("{}{:>width$}", MARGIN, mems, width = widths.mem.1),
|
||||||
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(
|
||||||
@@ -337,7 +344,7 @@ fn make_chart<T: Stats + Display>(
|
|||||||
))
|
))
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
// .border_type(BorderType::Plain),
|
// .border_type(BorderType::Plain),
|
||||||
.border_type(BorderType::Rounded),
|
.border_type(BorderType::Rounded),
|
||||||
)
|
)
|
||||||
.x_axis(
|
.x_axis(
|
||||||
Axis::default()
|
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());
|
.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,23 +471,20 @@ 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");
|
||||||
help_text.push_str("\n ( enter ) to send docker container commands");
|
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 ( 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 ( 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,8 +505,7 @@ 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())
|
||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center);
|
||||||
@@ -537,7 +533,7 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
|||||||
.constraints(
|
.constraints(
|
||||||
[
|
[
|
||||||
Constraint::Max(NAME_TEXT.lines().count() as u16),
|
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),
|
Constraint::Max(help_text.lines().count() as u16),
|
||||||
]
|
]
|
||||||
.as_ref(),
|
.as_ref(),
|
||||||
@@ -547,7 +543,7 @@ pub fn draw_help_box<B: Backend>(f: &mut Frame<'_, B>) {
|
|||||||
// Order is important here
|
// Order is important here
|
||||||
f.render_widget(Clear, area);
|
f.render_widget(Clear, area);
|
||||||
f.render_widget(name_paragraph, split_popup[0]);
|
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(help_paragraph, split_popup[2]);
|
||||||
f.render_widget(block, area);
|
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
|
/// 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
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
let blank_horizontal = if r.width > text_width {
|
let blank_horizontal = if r.width > text_width {
|
||||||
(r.width - text_width) / 2
|
(r.width - text_width) / 2
|
||||||
}else {
|
} else {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
|
|
||||||
let vertical_constraints = box_location.get_vertical_constraints(blank_vertical, text_lines);
|
let vertical_constraints = box_location.get_vertical_constraints(blank_vertical, text_lines);
|
||||||
let horizontal_constraints =
|
let horizontal_constraints =
|
||||||
|
|||||||
Reference in New Issue
Block a user