add peers list
This commit is contained in:
parent
d3d8a5f3fa
commit
bf74a43cf1
2 changed files with 30 additions and 5 deletions
|
@ -58,12 +58,12 @@ async fn main() -> error::Result<()> {
|
||||||
Ok(result?)
|
Ok(result?)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct App {
|
pub struct App {
|
||||||
state: JoecalState,
|
pub state: JoecalState,
|
||||||
rstate: RunningState,
|
rstate: RunningState,
|
||||||
screen: CurrentScreen,
|
pub screen: CurrentScreen,
|
||||||
// addr to (alias, fingerprint)
|
// addr to (alias, fingerprint)
|
||||||
peers: BTreeMap<SocketAddr, (String, String)>,
|
pub peers: BTreeMap<SocketAddr, (String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
|
|
@ -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
|
// helper function to create a centered rect using up certain percentage of the
|
||||||
// available rect `r`
|
// 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
|
.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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue