mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Add help line to top
This commit is contained in:
parent
0c30eb5b8f
commit
0c8916400d
@ -9,6 +9,7 @@ use crate::{bus::BusMessage, widgets::*};
|
||||
use ratatui::prelude::*;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
use std::io::Stdout;
|
||||
use crate::widgets::help::help_display;
|
||||
|
||||
use self::{top_flows::TopFlows, top_hosts::TopHosts};
|
||||
|
||||
@ -73,6 +74,12 @@ impl TopUi {
|
||||
let mut next_region = 0;
|
||||
|
||||
// Build the layout regions
|
||||
let help_region = {
|
||||
constraints.push(Constraint::Length(1));
|
||||
next_region += 1;
|
||||
next_region - 1
|
||||
};
|
||||
|
||||
let cpu_region = if self.show_cpus {
|
||||
constraints.push(Constraint::Length(1));
|
||||
next_region += 1;
|
||||
@ -95,6 +102,7 @@ impl TopUi {
|
||||
let main_layout = Layout::new(Direction::Vertical, constraints).split(frame.size());
|
||||
|
||||
// Add Widgets
|
||||
frame.render_widget(help_display(), main_layout[help_region]);
|
||||
if self.show_cpus {
|
||||
frame.render_widget(cpu_display(), main_layout[cpu_region]);
|
||||
}
|
||||
|
22
src/rust/lqtop/src/widgets/help.rs
Normal file
22
src/rust/lqtop/src/widgets/help.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use ratatui::prelude::*;
|
||||
use ratatui::widgets::{Block, Borders};
|
||||
|
||||
fn keyhelp(key: char, action: &'static str, buf: &mut Vec<Span>) {
|
||||
buf.push(Span::styled("[", Style::default().fg(Color::Green)));
|
||||
buf.push(Span::styled(key.to_string(), Style::default().fg(Color::Green)));
|
||||
buf.push(Span::styled("] ", Style::default().fg(Color::Green)));
|
||||
buf.push(Span::styled(action, Style::default().fg(Color::Yellow)));
|
||||
buf.push(Span::styled(" ", Style::default().fg(Color::Green)));
|
||||
}
|
||||
|
||||
pub fn help_display() -> impl Widget {
|
||||
let mut span_buf = vec![
|
||||
Span::styled("LQTOP - ", Style::default().fg(Color::White)),
|
||||
];
|
||||
keyhelp('q', "Quit", &mut span_buf);
|
||||
keyhelp('c', "CPUs", &mut span_buf);
|
||||
keyhelp('n', "Network", &mut span_buf);
|
||||
keyhelp('h', "Hosts", &mut span_buf);
|
||||
keyhelp('f', "Flows", &mut span_buf);
|
||||
Block::new().borders(Borders::NONE).title(span_buf)
|
||||
}
|
@ -7,6 +7,7 @@ pub use network_sparkline::*;
|
||||
use ratatui::{layout::Rect, Frame};
|
||||
pub mod top_hosts;
|
||||
pub mod top_flows;
|
||||
pub mod help;
|
||||
|
||||
pub enum MainWidget {
|
||||
Hosts,
|
||||
|
Loading…
Reference in New Issue
Block a user