10 Commits

16 changed files with 1498 additions and 206 deletions
Generated
+847 -13
View File
File diff suppressed because it is too large Load Diff
+7 -3
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "pp" name = "pp"
version = "0.1.1" version = "0.2.0-PREVIEW"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
@@ -10,8 +10,12 @@ ansi_term = "0.12"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
csv = "1.3" csv = "1.3"
[[bin]] # Ratatui
name = "duration_to_string" color-eyre = "0.6.3"
crossterm = "0.28.1"
ratatui = "0.29.0"
# Time Display
chrono = "0.4"
[[bin]] [[bin]]
name = "pp" name = "pp"
+1
View File
@@ -1,3 +1,4 @@
address,name
10.3.100.1,Belleville Router 10.3.100.1,Belleville Router
10.11.31.3,Belleville VPN 11-31 10.11.31.3,Belleville VPN 11-31
10.12.32.1,Belleville VPN 12-32 10.12.32.1,Belleville VPN 12-32
View File
+1
View File
@@ -1,3 +1,4 @@
address,name
10.3.100.1,Belleville Router 10.3.100.1,Belleville Router
10.11.31.3,Belleville VPN 11-31 10.11.31.3,Belleville VPN 11-31
10.12.32.1,Belleville VPN 12-32 10.12.32.1,Belleville VPN 12-32
+8 -6
View File
@@ -1,14 +1,16 @@
10.3.100.1,Belleville Router address,name
10.3.100.1,Belleville Gateway
10.11.31.3,Belleville VPN 11-31 10.11.31.3,Belleville VPN 11-31
10.12.32.1,Belleville VPN 12-32 10.12.32.1,Belleville VPN 12-32
192.186.110.6,Belleville Cogeco
129.222.197.36,Belleville Starlink
10.2.100.1,Lindsay Gateway
24.143.184.98,Lindsay Cogeco
192.168.1.50,Lindsay Sign
10.11.21.1,Lindsay VPN 11-21 10.11.21.1,Lindsay VPN 11-21
10.12.22.1,Lindsay VPN 11-22 10.12.22.1,Lindsay VPN 11-22
8.8.8.8,Google DNS 8.8.8.8,Google DNS
1.1.1.1,1111 DNS 1.1.1.1,1111 DNS
192.168.0.1,Peterborough Gateway
24.51.235.162,Peterborough Cogeco 24.51.235.162,Peterborough Cogeco
99.214.0.92,Peterborough Rogers 99.214.0.92,Peterborough Rogers
216.234.202.122,Lindsay Starlink
24.143.184.98,Lindsay Cogeco
192.186.110.6,Belleville Cogeco
129.222.197.36,Belleville Starlink
192.168.0.50,Sign
+10
View File
@@ -0,0 +1,10 @@
use std::path::PathBuf;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct AppSettings {
/// File of list of hosts
#[arg(short, long)]
pub ping_host_file: Option<PathBuf>,
}
-41
View File
@@ -1,41 +0,0 @@
use std::time::Duration;
pub fn duration_to_string(to_convert: Duration) -> String {
let mut total_seconds = to_convert.as_secs();
let mut working_string = String::new();
if total_seconds > 86400 {
// days
let num_days = total_seconds / 86400;
working_string = format!("{} days", num_days);
total_seconds = total_seconds - (num_days * 86400);
}
if total_seconds > 3600 {
// hours
let num_hours = total_seconds / 3600;
if num_hours > 0 {
working_string = format!("{} {} hours", working_string, num_hours);
total_seconds = total_seconds - (num_hours * 3600);
}
}
if total_seconds > 60 {
let num_minutes = total_seconds / 60;
if num_minutes > 0 {
working_string = format!("{} {} minutes", working_string, num_minutes);
total_seconds = total_seconds - (num_minutes * 60);
}
// minutes
}
working_string = format!("{} {} seconds.", working_string, total_seconds);
working_string
}
fn main() {
println!("1m 12s => {}", duration_to_string(Duration::from_secs(72)));
println!("1h 1m 12s => {}", duration_to_string(Duration::from_secs(3672)));
println!("1d 1h 1m 12s => {}", duration_to_string(Duration::from_secs(90072)));
println!("30d 1h 1m 12s => {}", duration_to_string(Duration::from_secs(2595672)));
}
+51 -31
View File
@@ -11,11 +11,18 @@ use clap::Parser;
use pp::ping_result::PingResult; use pp::ping_result::PingResult;
use pp::ping_request::PingRequest; use pp::ping_request::PingRequest;
use pp::manager::Manager; use pp::manager::Manager;
use pp::SECONDS_BETWEEN_DISPLAY; use pp::{duration_to_string, SECONDS_BETWEEN_DISPLAY};
use pp::target_state::TargetState; use pp::target_state::TargetState;
use std::{env, error::Error, ffi::OsString, process}; use std::{env, error::Error, ffi::OsString, process};
use color_eyre::owo_colors::OwoColorize;
use crossterm::style::Stylize;
use log::debug;
use pp::app_settings::AppSettings;
fn get_default_targets() -> BTreeMap<String, TargetState> { struct PPState {}
impl PPState {
pub fn get_default_targets() -> BTreeMap<String, TargetState> {
let mut working = BTreeMap::new(); let mut working = BTreeMap::new();
working.insert("Localhost".to_string(), working.insert("Localhost".to_string(),
TargetState { TargetState {
@@ -72,21 +79,21 @@ fn get_default_targets() -> BTreeMap<String, TargetState> {
working working
} }
fn build_targets_from_file(filename: Option<PathBuf>) -> BTreeMap<String, TargetState> { pub fn build_targets_from_file(filename: Option<PathBuf>) -> BTreeMap<String, TargetState> {
let mut hosts: BTreeMap<String, TargetState> = get_default_targets(); // PPState::get_default_targets();
if let Some(file) = filename { if let Some(file) = filename {
hosts = if !&file.exists() { let mut working = BTreeMap::new();
println!("Cant load hosts from {:?}. Using default host list.", file.clone().as_os_str()); if !&file.exists() {
debug!("Cant load hosts from {:?}. Using default host list.", file.clone().as_os_str());
// use // use
get_default_targets() PPState::get_default_targets()
} else { } else {
println!("LOADING HOSTS FROM {:?}", file.to_str()); debug!("LOADING HOSTS FROM {:?}", file.to_str());
let file = File::open(file); let file = File::open(file);
let mut rdr = csv::Reader::from_reader(file.unwrap()); let mut rdr = csv::Reader::from_reader(file.unwrap());
for result in rdr.records() { for result in rdr.records() {
let record = result.unwrap(); let record = result.unwrap();
hosts.insert(record[1].to_string(), working.insert(record[1].to_string(),
TargetState { TargetState {
name: record[1].to_string(), name: record[1].to_string(),
target: Ipv4Addr::from_str(&record[0]).unwrap(), target: Ipv4Addr::from_str(&record[0]).unwrap(),
@@ -95,13 +102,13 @@ fn build_targets_from_file(filename: Option<PathBuf>) -> BTreeMap<String, Target
last_rtt: 0, last_rtt: 0,
}); });
} }
hosts working
}
} else {
PPState::get_default_targets()
} }
} }
hosts
} }
fn ips_from_state(to_read_from: BTreeMap<String, TargetState>) -> Vec<Ipv4Addr> { fn ips_from_state(to_read_from: BTreeMap<String, TargetState>) -> Vec<Ipv4Addr> {
let mut working: Vec<Ipv4Addr> = vec![]; let mut working: Vec<Ipv4Addr> = vec![];
for current in to_read_from { for current in to_read_from {
@@ -111,20 +118,22 @@ fn ips_from_state(to_read_from: BTreeMap<String, TargetState>) -> Vec<Ipv4Addr>
} }
/// Simple program to greet a person /// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct AppSettings {
/// File of list of hosts
#[arg(short, long)]
ping_host_file: Option<PathBuf>,
}
fn main() { fn main() {
// Get App Settings // Get App Settings
let settings = AppSettings::parse(); let settings = AppSettings::parse();
print!("Prep to load targets..."); print!("Prep to load targets...");
let mut targets = build_targets_from_file(settings.ping_host_file); let file_to_check = match settings.ping_host_file {
None => {
PathBuf::from("./hosts.txt")
}
Some(actual) => {
actual
}
};
let mut targets = PPState::build_targets_from_file(Some(file_to_check));
// channel to send requests to ping // channel to send requests to ping
let (ping_response_sender, ping_response_listener) = mpsc::channel::<PingResult>(); let (ping_response_sender, ping_response_listener) = mpsc::channel::<PingResult>();
@@ -135,8 +144,10 @@ fn main() {
let mut display_loop_start = SystemTime::now(); let mut display_loop_start = SystemTime::now();
let mut duration_since_last_loop = SystemTime::now().duration_since(display_loop_start).unwrap(); let mut duration_since_last_loop = SystemTime::now().duration_since(display_loop_start).unwrap();
loop { loop {
let now = SystemTime::now();
if let Ok(response) = ping_response_listener.recv_timeout(Duration::from_millis(100)) { if let Ok(response) = ping_response_listener.recv_timeout(Duration::from_millis(100)) {
for (_, (name, current_state)) in targets.clone().iter().enumerate() { let local_targets = targets.clone();
for (_, (name, current_state)) in local_targets.iter().enumerate() {
if current_state.target == response.target { if current_state.target == response.target {
let last_alive_change = if response.success == current_state.alive { let last_alive_change = if response.success == current_state.alive {
current_state.last_alive_change current_state.last_alive_change
@@ -155,27 +166,36 @@ fn main() {
} }
} }
} }
duration_since_last_loop = SystemTime::now() duration_since_last_loop = now
.duration_since(display_loop_start) .duration_since(display_loop_start)
.expect("unable to figure out how long ago we displayed stuff"); .expect("unable to figure out how long ago we displayed stuff");
if duration_since_last_loop.as_secs() > SECONDS_BETWEEN_DISPLAY as u64 { if duration_since_last_loop.as_secs() > SECONDS_BETWEEN_DISPLAY as u64 {
println!("DISPLAY LOOP"); println!("DISPLAY LOOP");
println!("Host \t\t\t\t\t | Alive \t | RTT \t\t"); println!("Host \t\t\t\t\t | Alive \t | RTT \t\t");
for (name, current_result) in targets.clone() { for (name, current_result) in targets.clone() {
let mut target_string = String::new(); let time_since_last_change = now
let time_since_last_change = SystemTime::now().duration_since(current_result.last_alive_change).unwrap(); .duration_since(current_result.last_alive_change)
target_string = format!("{} ({})", name, current_result.target); .unwrap_or(Duration::from_secs(0));
let mut target_string = format!("{} ({})", name, current_result.target);
while target_string.len() < 34 { while target_string.len() < 34 {
target_string = format!("{} ", target_string); target_string.push(' ');
// target_string = format!("{} ", target_string);
} }
println!("{} \t | {} \t | {}\t | Changed {}s ago", target_string = if current_result.alive {
target_string.green().to_string()
} else {
target_string.red().to_string()
};
println!("{} \t | {} \t | {}\t | Changed {} ago",
target_string, target_string,
current_result.alive, current_result.alive,
current_result.last_rtt, time_since_last_change.as_secs() current_result.last_rtt,
duration_to_string(time_since_last_change)
); );
} }
display_loop_start = SystemTime::now(); display_loop_start = now;
} }
} }
} }
+13
View File
@@ -0,0 +1,13 @@
use clap::Parser;
use pp::app_settings::AppSettings;
use pp::tui::ratatui_app::RatatuiApp;
fn main() -> color_eyre::Result<()> {
// find out what file we are using to get our hosts
let settings = AppSettings::parse();
color_eyre::install()?;
let terminal = ratatui::init();
let result = RatatuiApp::new(settings.ping_host_file).run(terminal);
ratatui::restore();
result
}
+44 -1
View File
@@ -1,8 +1,51 @@
use std::time::Duration;
pub mod manager; pub mod manager;
pub mod ping_request; pub mod ping_request;
pub mod ping_result; pub mod ping_result;
pub mod target_state; pub mod target_state;
pub mod tui;
pub mod app_settings;
pub const SECONDS_BETWEEN_DISPLAY: u32 = 1; pub const SECONDS_BETWEEN_DISPLAY: u32 = 1;
pub const SECONDS_BETWEEN_PING: u32 = 2; pub const SECONDS_BETWEEN_PING: u32 = 2;
const SECONDS_IN_MINUTE: u32 = 60;
const SECONDS_IN_HOUR: u32 = SECONDS_IN_MINUTE * 60;
const SECONDS_IN_DAY: u32 = SECONDS_IN_HOUR * 24;
pub fn duration_to_string(to_convert: Duration) -> String {
let mut total_seconds = to_convert.as_secs() as u32;
let mut working_string = String::new();
if total_seconds > 86400 {
// days
let num_days = (total_seconds / SECONDS_IN_DAY) as u32;
working_string = format!("{} days", num_days);
total_seconds = total_seconds - (num_days * SECONDS_IN_DAY);
}
if total_seconds > 3600 {
// hours
let num_hours = (total_seconds / SECONDS_IN_HOUR) as u32;
if num_hours > 0 {
working_string = format!("{} {} hours", working_string, num_hours);
total_seconds = total_seconds - (num_hours * SECONDS_IN_HOUR);
}
}
if total_seconds > 60 {
let num_minutes = (total_seconds / SECONDS_IN_MINUTE) as u32;
if num_minutes > 0 {
working_string = format!("{} {} minutes", working_string, num_minutes);
total_seconds = total_seconds - (num_minutes * SECONDS_IN_MINUTE);
}
// minutes
}
working_string = format!("{} {} seconds", working_string, total_seconds);
working_string
}
+13
View File
@@ -1,5 +1,10 @@
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
use std::time::SystemTime; use std::time::SystemTime;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::prelude::{StatefulWidget, Style};
use ratatui::style::Color;
use ratatui::widgets::Widget;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct TargetState { pub struct TargetState {
@@ -21,3 +26,11 @@ impl Default for TargetState {
} }
} }
} }
struct TargetStateWidget;
impl StatefulWidget for TargetStateWidget {
type State = TargetStateWidget;
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
buf.set_string(area.left(),area.top(),"This is the string set ", Style::default().fg(Color::Red));
}
}
+3
View File
@@ -0,0 +1,3 @@
pub mod target_state_widget;
pub mod ratatui_app;
mod ratatui_ui;
+256
View File
@@ -0,0 +1,256 @@
use color_eyre::Result;
use std::collections::BTreeMap;
use std::fs::File;
use std::net::Ipv4Addr;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::mpsc;
use std::sync::mpsc::Receiver;
use std::time::{Duration, SystemTime};
use chrono::{DateTime, Local};
use crossterm::event;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use ratatui::{DefaultTerminal, Frame};
use ratatui::prelude::*;
use ratatui::widgets::{Block, Paragraph};
use crate::duration_to_string;
use crate::manager::Manager;
use crate::ping_result::PingResult;
use crate::target_state::TargetState;
use crate::tui::ratatui_ui::RatatuiUi;
#[derive(Default)]
pub enum RatatuiScreens {
#[default]
Monitoring,
Exiting,
Editing
}
#[derive(Default)]
pub struct RatatuiApp {
running: bool,
pub(crate) state: BTreeMap<String, TargetState>,
current_screen: RatatuiScreens,
pub(crate) log_entries: Vec<String>
}
impl RatatuiApp {
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
self.running = true;
// start the 'manager' thread that spawns its ping threads as needed
let (sender, receiver) = mpsc::channel::<PingResult>();
Manager::spawn_manager_thread(self.targets_as_vec(), sender);
while self.running {
// check for any waiting ping results...
self.consume_waiting_results(&receiver);
match self.current_screen {
RatatuiScreens::Monitoring => {
terminal.draw(|frame| RatatuiUi::monitoring_mode(frame, &mut self)).expect("Unable to draw to screen");
self.handle_monitoring_crossterm_events();
}
RatatuiScreens::Exiting => {
terminal.draw(| frame | RatatuiUi::exiting_mode(frame));
self.handle_exiting_crossterm_events();
}
RatatuiScreens::Editing => {
terminal.draw(|frame| RatatuiUi::editing_mode(frame, &mut self.state));
self.handle_editing_crossterm_events();
}
}
// self.handle_crossterm_events()?;
}
Ok(())
}
fn consume_waiting_results(&mut self, receiver: &Receiver<PingResult>) {
let mut local_state = self.state.clone();
if let Ok(new_message) = receiver.recv_timeout(Duration::from_millis(10)) {
// find the right TargetState
for (name, mut current_state) in local_state.clone() {
if current_state.target == new_message.target {
let did_change = new_message.success != current_state.alive;
let last_alive_change = if did_change {
SystemTime::now()
} else {
current_state.last_alive_change
};
let new_state = TargetState {
name: current_state.name.clone(),
target: current_state.target,
alive: new_message.success,
last_rtt: new_message.rtt,
last_alive_change,
};
local_state.insert(name.clone(), new_state.clone());
let success_message = if new_state.alive {
"Success"
} else {
"Failure"
};
let current_time: DateTime<Local> = SystemTime::now().into();
if did_change {
self.log_entries.push(
format!("{:?} {} for {}",
current_time.format("%Y-%m-%d %H:%M:%S: ").to_string(),
success_message,
new_state.name.clone())
);
}
}
}
}
self.state = local_state;
}
fn targets_as_vec(&self) -> Vec<Ipv4Addr> {
let mut working = vec![];
for (_, current) in &self.state {
working.push(current.target);
}
working
}
fn render(&mut self, frame: &mut Frame) {
match self.current_screen {
RatatuiScreens::Monitoring => { RatatuiUi::monitoring_mode(frame, self) }
RatatuiScreens::Exiting => { RatatuiUi::exiting_mode(frame)}
RatatuiScreens::Editing => { RatatuiUi::editing_mode(frame, &mut self.state) }
}
}
fn handle_monitoring_crossterm_events(&mut self) -> Result<()> {
if event::poll(Duration::from_millis(100))? {
match event::read()? {
Event::Key(key) if key.kind == KeyEventKind::Press => {
match (key.modifiers, key.code) {
(_, KeyCode::Esc) => {
self.current_screen = RatatuiScreens::Exiting;
}
(_, KeyCode::Char('e')) | (_, KeyCode::Char('E')) => {
self.current_screen = RatatuiScreens::Editing
}
_ => {}
}
},
_ => {}
}
}
Ok(())
}
fn handle_exiting_crossterm_events(&mut self) -> Result<()> {
if event::poll(Duration::from_millis(100))? {
match event::read()? {
Event::Key(key) if key.kind == KeyEventKind::Press => {
match key.code {
KeyCode::Enter => { self.running = false; }
KeyCode::Char('y') | KeyCode::Char('Y') => { self.running = false;
}
KeyCode::Char('n') | KeyCode::Char('N') => { self.current_screen = RatatuiScreens::Monitoring }
_ => {}
}
}
_ => {}
}
}
Ok(())
}
fn handle_editing_crossterm_events(&mut self) -> Result<()> {
if event::poll(Duration::from_millis(100))? {
match event::read()? {
Event::Key(key) if key.kind == KeyEventKind::Press => {
match key.code {
KeyCode::Up => { println!("UP") },
KeyCode::Down => { println!("Down") },
KeyCode::Char('+') => { println!("ADD HOST") },
KeyCode::Char('-') => { println!("Delete Host") }
_ => {}
}
}
_ => {}
}
}
Ok(())
}
fn handle_crossterm_events(&mut self) -> Result<()> {
if event::poll(Duration::from_millis(100))? {
match event::read()? {
// it's important to check KeyEventKind::Press to avoid handling key release events
Event::Key(key) if key.kind == KeyEventKind::Press => self.on_key_event(key),
Event::Mouse(_) => {}
Event::Resize(_, _) => {}
_ => {}
}
}
Ok(())
}
fn quit(&mut self) { self.running = false; }
/// Handles the key events and updates the state of [`App`].
fn on_key_event(&mut self, key: KeyEvent) {
match (key.modifiers, key.code) {
(_, KeyCode::Esc | KeyCode::Char('q'))
| (KeyModifiers::CONTROL, KeyCode::Char('c') |
KeyCode::Char('C')) => { self.quit() }
// Add other key handlers here.
_ => {}
}
}
pub fn new(option: Option<PathBuf>) -> Self {
let targets = if let Some(file) = option {
let mut working = BTreeMap::new();
if !&file.exists() {
RatatuiApp::get_default_targets()
} else {
let real_file = File::open(file);
let mut rdr = csv::Reader::from_reader(real_file.unwrap());
for result in rdr.records() {
let record = result.unwrap();
working.insert(record[1].to_string(),
TargetState {
name: record[1].to_string(),
target: Ipv4Addr::from_str(&record[0]).unwrap(),
alive: false,
last_alive_change: SystemTime::now(),
last_rtt: 0
});
}
working
}
} else { RatatuiApp::get_default_targets() };
let mut working = Self::default();
working.state = targets;
working
}
fn get_default_targets() -> BTreeMap<String, TargetState> {
let mut working = BTreeMap::new();
working.insert("1111 DNS".to_string(), TargetState {
name: "1111 DNS".to_string(),
target: Ipv4Addr::new(1,1,1,1),
..TargetState::default()
});
working.insert("Google DNS".to_string(), TargetState {
name: "Google DNS".to_string(),
target: Ipv4Addr::new(8,8,8,8),
..TargetState::default()
});
working.insert("Test Site 1".to_string(), TargetState {
name: "Test Site 1".to_string(),
target: Ipv4Addr::new(216,234,202,122),
..TargetState::default()
});
working
}
}
+122
View File
@@ -0,0 +1,122 @@
use std::collections::BTreeMap;
use std::time::SystemTime;
use color_eyre::owo_colors::OwoColorize;
use ratatui::Frame;
use ratatui::prelude::*;
use ratatui::widgets::{Block, Borders, List, ListItem, ListState, Paragraph};
use crate::duration_to_string;
use crate::target_state::TargetState;
use crate::tui::ratatui_app::RatatuiApp;
pub struct RatatuiUi {}
impl RatatuiUi {
pub fn exiting_mode(frame: &mut Frame) {
let title = Line::from("Exit?")
.bold()
.red()
.centered();
let mut body = "Do you want to exit? (Y/N)";
frame.render_widget(
Paragraph::new(body)
.block(Block::bordered().title(title))
.centered(),
frame.area()
);
}
pub fn editing_mode(frame: &mut Frame, state: &mut BTreeMap<String, TargetState>) {
let title = Line::from("Editing Hosts")
.bold()
.blue()
.centered();
let body_text = "This is the body text for editing hosts";
frame.render_widget(
Paragraph::new(body_text)
.centered()
.block(Block::new()
.title(title)
.blue()),
frame.area()
);
}
pub fn monitoring_mode(frame: &mut Frame, state: &mut RatatuiApp) {
let layouts = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(10),
Constraint::Length(3)
])
.split(frame.area());
let body_layout = layouts[0];
let logs_layout = layouts[1];
let footer_layout = layouts[2];
let title = Line::from(format!("PP v{}", env!("CARGO_PKG_VERSION")))
.bold()
.blue()
.centered();
let mut working = vec![]; // Line::from("Empty");
for (title, current) in state.state.iter() {
let mut name_field = format!("{} ({})", current.name.clone(), current.target.clone());
while name_field.len() < 40 {
name_field.push(' ');
}
let name_style = if current.alive {
Style::default().fg(Color::Green)
} else {
Style::default().fg(Color::Red)
};
working.push(Line::from(vec![
Span::styled(name_field, name_style),
Span::styled(current.alive.to_string(), Style::default()),
Span::styled(current.last_rtt.to_string(), Style::default()),
Span::styled(
format!("{} ago.", duration_to_string(
SystemTime::now()
.duration_since(current.last_alive_change)
.unwrap()
)), Style::default())
]));
}
let footer_text = "Press <ESC> to exit | Press e to edit hosts";
frame.render_widget(
Paragraph::new(working)
.block(Block::bordered().title(title)),
body_layout
);
let mut list_items = vec![];
for entry in state.log_entries.clone().into_iter().rev() {
list_items.push(ListItem::new(entry));
}
let list = List::new(list_items)
.block(Block::default().title("Hosts").borders(Borders::ALL))
.highlight_style(Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD))
.highlight_symbol(">> ");
let mut list_state = ListState::default();
list_state.select(Some(0));
frame.render_stateful_widget(
list, logs_layout, &mut list_state);
frame.render_widget(
Paragraph::new(footer_text)
.block(Block::bordered())
.centered(),
footer_layout
);
}
}
+11
View File
@@ -0,0 +1,11 @@
use ratatui::buffer::Cell;
use ratatui::prelude::*;
pub struct TargetStateWidget;
impl Widget for TargetStateWidget {
fn render(self, area: Rect, buf: &mut Buffer)
{
}
}