Implemented initial user interface

This commit is contained in:
2025-04-10 03:29:04 +02:00
parent 31532493cb
commit 750713b6b0
9 changed files with 729 additions and 80 deletions

26
src/tunnel/tui.rs Normal file
View File

@@ -0,0 +1,26 @@
use std::ops::Deref;
use ratatui::style::Stylize;
use ratatui::text::Span;
use super::{Tunnel, TunnelAccess};
pub fn header() -> Vec<Span<'static>> {
vec!["Access".into(), "Port".into(), "Address".into()]
}
pub async fn to_row((address, tunnel): (&String, &Option<Tunnel>)) -> Vec<Span<'static>> {
let (access, port) = if let Some(tunnel) = tunnel {
let access = match tunnel.access.read().await.deref() {
TunnelAccess::Private(owner) => owner.clone().yellow(),
TunnelAccess::Public => "PUBLIC".green(),
};
(access, tunnel.port.to_string().into())
} else {
("FAILED".red(), "".into())
};
let address = format!("http://{address}").into();
vec![access, port, address]
}