Update tunnel stats every redraw, auto redraw once a second
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 6m21s
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 6m21s
This commit is contained in:
@@ -1,9 +1,33 @@
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Span;
|
||||
|
||||
use super::{Tunnel, TunnelAccess};
|
||||
use crate::io::Stats;
|
||||
|
||||
pub struct TunnelRow {
|
||||
name: Span<'static>,
|
||||
access: Span<'static>,
|
||||
port: Span<'static>,
|
||||
address: Span<'static>,
|
||||
stats: Arc<Stats>,
|
||||
}
|
||||
|
||||
impl From<&TunnelRow> for Vec<Span<'static>> {
|
||||
fn from(row: &TunnelRow) -> Self {
|
||||
vec![
|
||||
row.name.clone(),
|
||||
row.access.clone(),
|
||||
row.port.clone(),
|
||||
row.address.clone(),
|
||||
row.stats.connections().to_string().into(),
|
||||
row.stats.rx().to_string().into(),
|
||||
row.stats.tx().to_string().into(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl Tunnel {
|
||||
pub fn header() -> Vec<Span<'static>> {
|
||||
@@ -18,7 +42,7 @@ impl Tunnel {
|
||||
]
|
||||
}
|
||||
|
||||
pub async fn to_row(tunnel: &Tunnel) -> Vec<Span<'static>> {
|
||||
pub async fn to_row(tunnel: &Tunnel) -> TunnelRow {
|
||||
let access = match tunnel.inner.access.read().await.deref() {
|
||||
TunnelAccess::Private(owner) => owner.clone().yellow(),
|
||||
TunnelAccess::Protected => "PROTECTED".blue(),
|
||||
@@ -30,14 +54,12 @@ impl Tunnel {
|
||||
.map(|address| format!("http://{address}").into())
|
||||
.unwrap_or("FAILED".red());
|
||||
|
||||
vec![
|
||||
tunnel.registry_entry.get_name().to_owned().into(),
|
||||
TunnelRow {
|
||||
name: tunnel.registry_entry.get_name().to_string().into(),
|
||||
access,
|
||||
tunnel.inner.port.to_string().into(),
|
||||
port: tunnel.inner.port.to_string().into(),
|
||||
address,
|
||||
tunnel.inner.stats.connections().to_string().into(),
|
||||
tunnel.inner.stats.rx().to_string().into(),
|
||||
tunnel.inner.stats.tx().to_string().into(),
|
||||
]
|
||||
stats: tunnel.inner.stats.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user