add peers list

This commit is contained in:
Joe Ardent 2025-07-07 21:17:52 -07:00
parent d3d8a5f3fa
commit bf74a43cf1
2 changed files with 30 additions and 5 deletions

View file

@ -58,12 +58,12 @@ async fn main() -> error::Result<()> {
Ok(result?)
}
struct App {
state: JoecalState,
pub struct App {
pub state: JoecalState,
rstate: RunningState,
screen: CurrentScreen,
pub screen: CurrentScreen,
// addr to (alias, fingerprint)
peers: BTreeMap<SocketAddr, (String, String)>,
pub peers: BTreeMap<SocketAddr, (String, String)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

View file

@ -1,4 +1,14 @@
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use std::{collections::BTreeMap, net::SocketAddr};
use ratatui::{
Frame,
layout::{Constraint, Direction, Layout, Rect},
style::Stylize,
text::{Line, Span},
widgets::{List, ListItem},
};
use crate::App;
// helper function to create a centered rect using up certain percentage of the
// available rect `r`
@ -23,3 +33,18 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
])
.split(popup_layout[1])[1] // Return the middle chunk
}
impl App {
pub fn peers(&self, frame: &mut Frame) {
let mut items = Vec::with_capacity(self.peers.len());
for (k, v) in self.peers.iter() {
let item = format!("{:?}: {}({})", k, v.0, v.1);
let s = Line::from(item.yellow());
let item = ListItem::new(s);
items.push(item);
}
let list = List::new(items);
frame.render_widget(list, frame.area());
}
}