Tunnel tui functions are now implemented on Tunnel
This commit is contained in:
parent
3ada40d4ae
commit
693df6817a
|
@ -12,7 +12,7 @@ use ratatui::{
|
||||||
};
|
};
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use crate::tunnel::{self, Tunnel};
|
use crate::tunnel::Tunnel;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
|
@ -28,7 +28,7 @@ impl Renderer {
|
||||||
// NOTE: This needs to be a separate function as the render functions can not be async
|
// NOTE: This needs to be a separate function as the render functions can not be async
|
||||||
pub async fn update(&mut self, tunnels: &[Tunnel], index: Option<usize>) {
|
pub async fn update(&mut self, tunnels: &[Tunnel], index: Option<usize>) {
|
||||||
self.table_rows = futures::stream::iter(tunnels)
|
self.table_rows = futures::stream::iter(tunnels)
|
||||||
.then(tunnel::tui::to_row)
|
.then(Tunnel::to_row)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ impl Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_widths(&mut self) -> Vec<Constraint> {
|
fn compute_widths(&mut self) -> Vec<Constraint> {
|
||||||
let table_header = tunnel::tui::header();
|
let table_header = Tunnel::header();
|
||||||
std::iter::once(&table_header)
|
std::iter::once(&table_header)
|
||||||
.chain(&self.table_rows)
|
.chain(&self.table_rows)
|
||||||
.map(|row| row.iter().map(|cell| cell.width() as u16))
|
.map(|row| row.iter().map(|cell| cell.width() as u16))
|
||||||
|
@ -173,7 +173,7 @@ impl Renderer {
|
||||||
.height(1)
|
.height(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
let header = tunnel::tui::header()
|
let header = Tunnel::header()
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(Cell::from)
|
.map(Cell::from)
|
||||||
|
|
|
@ -5,7 +5,8 @@ use ratatui::text::Span;
|
||||||
|
|
||||||
use super::{Tunnel, TunnelAccess};
|
use super::{Tunnel, TunnelAccess};
|
||||||
|
|
||||||
pub fn header() -> Vec<Span<'static>> {
|
impl Tunnel {
|
||||||
|
pub fn header() -> Vec<Span<'static>> {
|
||||||
vec![
|
vec![
|
||||||
"Name".into(),
|
"Name".into(),
|
||||||
"Access".into(),
|
"Access".into(),
|
||||||
|
@ -15,9 +16,9 @@ pub fn header() -> Vec<Span<'static>> {
|
||||||
"Rx".into(),
|
"Rx".into(),
|
||||||
"Tx".into(),
|
"Tx".into(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn to_row(tunnel: &Tunnel) -> Vec<Span<'static>> {
|
pub async fn to_row(tunnel: &Tunnel) -> Vec<Span<'static>> {
|
||||||
let access = match tunnel.inner.access.read().await.deref() {
|
let access = match tunnel.inner.access.read().await.deref() {
|
||||||
TunnelAccess::Private(owner) => owner.clone().yellow(),
|
TunnelAccess::Private(owner) => owner.clone().yellow(),
|
||||||
TunnelAccess::Protected => "PROTECTED".blue(),
|
TunnelAccess::Protected => "PROTECTED".blue(),
|
||||||
|
@ -38,4 +39,5 @@ pub async fn to_row(tunnel: &Tunnel) -> Vec<Span<'static>> {
|
||||||
tunnel.inner.stats.rx().to_string().into(),
|
tunnel.inner.stats.rx().to_string().into(),
|
||||||
tunnel.inner.stats.tx().to_string().into(),
|
tunnel.inner.stats.tx().to_string().into(),
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user