Skip to content

Commit 3452a6a

Browse files
committed
feat(tui): refactor into modular architecture with async ping support
Split monolithic tui/app.rs (721 lines) and tui/ui.rs (572 lines) into a well-organized module structure: - models.rs: enums, small types (Tab, AppMode, EditState, PingStatus, ...) - state.rs: App struct and state management with mpsc ping channel - input.rs: keyboard handlers dispatched per tab/mode - event_loop.rs: terminal setup/teardown and main loop - ui/mod.rs: draw dispatcher routing to tab views and overlays - ui/header.rs, list.rs, detail.rs, status.rs, overlays.rs, history.rs, config.rs, helpers.rs New features: - Tab-based navigation (Connections, History, Config) - Add new connection form (a key) - Session history view with filters - Environment management in Config tab - Connection grouping by tag (f key) - Quick-connect bar (: key) - Multi-select and batch delete (Space, Ctrl+A, x) - SSH command preview (p key) - Async TCP ping with colored indicators (P key) - Green dot for reachable (with round-trip time) - Red dot for unreachable - Yellow circle for in-progress - Shared ping service (services/ping.rs) using tokio TcpStream Bump version to 1.4.1.
1 parent 261e95c commit 3452a6a

20 files changed

Lines changed: 3104 additions & 1296 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bayesian-ssh"
3-
version = "1.4.0"
3+
version = "1.4.1"
44
edition = "2021"
55
authors = ["Abdoufermat5"]
66
description = "A fast and lightweight SSH session manager with Kerberos support"

src/cli/commands/tui.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use crate::config::AppConfig;
44
use crate::services::SshService;
5-
use crate::tui::app::{run_tui, PendingAction};
5+
use crate::tui::event_loop::run_tui;
6+
use crate::tui::models::PendingAction;
67
use anyhow::Result;
78

89
/// Execute the TUI command

src/services/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod ping;
12
pub mod ssh;
23

34
pub use ssh::*;

src/services/ping.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Lightweight TCP-level ping for SSH host reachability checks.
2+
//!
3+
//! Uses `tokio::net::TcpStream::connect` with a timeout to test whether
4+
//! a host:port is reachable. This avoids spawning an external `ssh`
5+
//! process and is suitable for background checks in the TUI.
6+
7+
use std::time::{Duration, Instant};
8+
use tokio::net::TcpStream;
9+
use tokio::time::timeout;
10+
11+
/// Result of a TCP ping attempt.
12+
#[derive(Debug, Clone)]
13+
pub enum PingResult {
14+
/// Host is reachable; includes the round-trip time.
15+
Reachable(Duration),
16+
/// Host did not respond within the timeout or the connection was refused.
17+
Unreachable,
18+
}
19+
20+
/// Attempt a TCP connection to `host:port` with the given `timeout_secs`.
21+
///
22+
/// For connections that go through a bastion host, callers should ping the
23+
/// bastion (`bastion_host:22`) rather than the final target since the
24+
/// target is typically not directly reachable.
25+
pub async fn tcp_ping(host: &str, port: u16, timeout_secs: u64) -> PingResult {
26+
let addr = format!("{}:{}", host, port);
27+
let start = Instant::now();
28+
29+
match timeout(Duration::from_secs(timeout_secs), TcpStream::connect(&addr)).await {
30+
Ok(Ok(_stream)) => PingResult::Reachable(start.elapsed()),
31+
_ => PingResult::Unreachable,
32+
}
33+
}

0 commit comments

Comments
 (0)