mirror of
https://github.com/EasyTier/EasyTier.git
synced 2025-09-26 20:51:17 +08:00
cli: improve peer table display with shorter columns for small display (#1342)
- Add short column names for latency, loss rate, rx/tx bytes, tunnel protocol and NAT type - Format loss rate as percentage with one decimal place - Change table style from modern to markdown for better readability
This commit is contained in:
@@ -47,7 +47,7 @@ use easytier::{
|
||||
rpc_types::controller::BaseController,
|
||||
},
|
||||
tunnel::tcp::TcpTunnelConnector,
|
||||
utils::{cost_to_str, float_to_str, PeerRoutePair},
|
||||
utils::{cost_to_str, PeerRoutePair},
|
||||
};
|
||||
|
||||
rust_i18n::i18n!("locales", fallback = "en");
|
||||
@@ -484,12 +484,19 @@ impl CommandHandler<'_> {
|
||||
ipv4: String,
|
||||
hostname: String,
|
||||
cost: String,
|
||||
#[tabled(rename = "lat(ms)")]
|
||||
lat_ms: String,
|
||||
#[tabled(rename = "loss")]
|
||||
loss_rate: String,
|
||||
#[tabled(rename = "rx")]
|
||||
rx_bytes: String,
|
||||
#[tabled(rename = "tx")]
|
||||
tx_bytes: String,
|
||||
#[tabled(rename = "tunnel")]
|
||||
tunnel_proto: String,
|
||||
#[tabled(rename = "NAT")]
|
||||
nat_type: String,
|
||||
#[tabled(skip)]
|
||||
id: String,
|
||||
version: String,
|
||||
}
|
||||
@@ -497,6 +504,11 @@ impl CommandHandler<'_> {
|
||||
impl From<PeerRoutePair> for PeerTableItem {
|
||||
fn from(p: PeerRoutePair) -> Self {
|
||||
let route = p.route.clone().unwrap_or_default();
|
||||
let lat_ms = if route.cost == 1 {
|
||||
p.get_latency_ms().unwrap_or(0.0)
|
||||
} else {
|
||||
route.path_latency_latency_first() as f64
|
||||
};
|
||||
PeerTableItem {
|
||||
cidr: route.ipv4_addr.map(|ip| ip.to_string()).unwrap_or_default(),
|
||||
ipv4: route
|
||||
@@ -506,12 +518,8 @@ impl CommandHandler<'_> {
|
||||
.unwrap_or_default(),
|
||||
hostname: route.hostname.clone(),
|
||||
cost: cost_to_str(route.cost),
|
||||
lat_ms: if route.cost == 1 {
|
||||
float_to_str(p.get_latency_ms().unwrap_or(0.0), 3)
|
||||
} else {
|
||||
route.path_latency_latency_first().to_string()
|
||||
},
|
||||
loss_rate: float_to_str(p.get_loss_rate().unwrap_or(0.0), 3),
|
||||
lat_ms: format!("{:.2}", lat_ms),
|
||||
loss_rate: format!("{:.1}%", p.get_loss_rate().unwrap_or(0.0) * 100.0),
|
||||
rx_bytes: format_size(p.get_rx_bytes().unwrap_or(0), humansize::DECIMAL),
|
||||
tx_bytes: format_size(p.get_tx_bytes().unwrap_or(0), humansize::DECIMAL),
|
||||
tunnel_proto: p
|
||||
@@ -1460,7 +1468,7 @@ where
|
||||
{
|
||||
match format {
|
||||
OutputFormat::Table => {
|
||||
println!("{}", tabled::Table::new(items).with(Style::modern()));
|
||||
println!("{}", tabled::Table::new(items).with(Style::markdown()));
|
||||
}
|
||||
OutputFormat::Json => {
|
||||
println!("{}", serde_json::to_string_pretty(items)?);
|
||||
@@ -1752,7 +1760,7 @@ async fn main() -> Result<(), Error> {
|
||||
builder.push_record(vec![format!("Listener {}", idx).as_str(), l]);
|
||||
}
|
||||
|
||||
println!("{}", builder.build().with(Style::modern()));
|
||||
println!("{}", builder.build().with(Style::markdown()));
|
||||
}
|
||||
Some(NodeSubCommand::Config) => {
|
||||
println!("{}", node_info.config);
|
||||
|
Reference in New Issue
Block a user