use a table for the network info

This commit is contained in:
Joe Ardent 2025-07-31 10:21:19 -07:00
parent 2f88b3b2c2
commit 74e9b1ddbf

View file

@ -1,9 +1,9 @@
use ratatui::{ use ratatui::{
buffer::Buffer, buffer::Buffer,
layout::Rect, layout::{Constraint, Rect},
style::Stylize, style::Stylize,
text::Line, text::{Line, ToLine},
widgets::{Block, Borders, List, ListItem, Padding, Widget}, widgets::{Block, Borders, List, ListItem, Padding, Row, Table, Widget},
}; };
use super::Peers; use super::Peers;
@ -47,34 +47,41 @@ impl Widget for NetworkInfoWidget {
// let rows = Rows::new(rect); // let rows = Rows::new(rect);
// let mut table = Table::default(); // let mut table = Table::default();
let udp = Line::default().spans(vec![ let udp = "UDP socket".yellow();
"UDP socket:".to_string().yellow(), let udp = udp.to_line().left_aligned();
format!("{:?}", joecalsend::LISTENING_SOCKET_ADDR).yellow(), let uaddr = format!("{:?}", joecalsend::LISTENING_SOCKET_ADDR).yellow();
]); let udp = Row::new(vec![udp.into(), uaddr.to_line().right_aligned()]);
let multicast: Line = format!(
"Multicast address:\t\t {:?}:{}", let mip = format!(
"{:?}:{:?}",
joecalsend::MULTICAST_IP, joecalsend::MULTICAST_IP,
joecalsend::DEFAULT_PORT joecalsend::DEFAULT_PORT
) )
.yellow() .yellow();
.into(); let multicast = "Multicast address".yellow();
let http: Line = format!( let multicast = Row::new(vec![
"HTTP address:\t\t\t {:?}", multicast.to_line().left_aligned(),
joecalsend::LISTENING_SOCKET_ADDR mip.to_line().right_aligned(),
) ]);
.yellow()
.into(); let haddr = format!("{:?}", joecalsend::LISTENING_SOCKET_ADDR).yellow();
let items = [ let http = "HTTP address".yellow();
ListItem::new(udp), let http = Row::new(vec![
ListItem::new(multicast), http.to_line().left_aligned(),
ListItem::new(http), haddr.to_line().right_aligned(),
]; ]);
let rows = vec![udp, multicast, http];
let widths = vec![Constraint::Percentage(50), Constraint::Percentage(50)];
let title = Line::from(" Listeners ".bold()).centered(); let title = Line::from(" Listeners ".bold()).centered();
let block = Block::default() let block = Block::default()
.title(title) .title(title)
.borders(Borders::all()) .borders(Borders::all())
.padding(Padding::uniform(1)); .padding(Padding::uniform(1));
let list = List::new(items).block(block);
list.render(area, buf); let table = Table::new(rows, widths).block(block);
table.render(area, buf);
} }
} }