Skip to main content

Crate sshui

Crate sshui 

Source
Expand description

§SSHUI

A Rust framework for building interactive terminal user interfaces (TUIs) that run over SSH. Built on top of Ratatui and russh.

§Features

  • SSH Server - Host your TUI application on an SSH server
  • Ratatui Integration - Build beautiful terminal UIs using the Ratatui framework
  • Client Isolation - Each SSH client gets its own application instance
  • ANSI Rendering - Full support for colors and styles
  • Terminal Resizing - Handles dynamic terminal size changes
  • Customizable Auth - Ask for a specific username and password (or not!)

§Installation

Add to your Cargo.toml:

[dependencies]
sshui = "0.2"
ratatui = "0.28"
anyhow = "1.0"

§Quick Start

Implement the App trait for your TUI:

use sshui::{App, SSHUITerminal, InputEvent, KeyCode, KeyEvent};
use anyhow::Result;

struct MyApp {
    counter: i32,
    exit: bool,
}

impl App for MyApp {
    fn render(&mut self, terminal: &mut SSHUITerminal) -> Result<Option<String>> {
        terminal.draw(|frame| {
            let area = frame.area();
            // Draw your UI here
        })?;

        Ok(if self.exit {
            Some("Exited".to_string())
        } else {
            None
        })
    }

    fn input(&mut self, event: InputEvent) {
        if let InputEvent::Key(KeyEvent { key, .. }) = event {
            match key {
                KeyCode::Char('q') => self.exit = true,
                KeyCode::Up => self.counter += 1,
                KeyCode::Down => self.counter -= 1,
                _ => {}
            }
        }
    }
}

impl Default for MyApp {
    fn default() -> Self {
        Self {
            counter: 0,
            exit: false,
        }
    }
}

Start the SSH server:

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = sshui::Config::default();
    // also include ssh keys
    // which you can get using the keyring feature
    // and the sshui::get_ssh_key function

    sshui::new_server(config, ("0.0.0.0", 2222), || Box::new(MyApp::default()))
        .await?;

    Ok(())
}

Connect via SSH:

ssh -p 2222 localhost

Press Ctrl+C to exit.

Re-exports§

pub use ratatui;

Modules§

backend

Structs§

Config
Configuration of a server.
Duration
A Duration type to represent a span of time, typically used for system timeouts.
KeyEvent
Lobby
A generic broadcast channel with optional server-side validation.
Modifiers
NoAuth
Authentication handler that accepts all authentication attempts
SSHUIConfig
A SSHUI server configuration struct.

Enums§

AuthDecision
Result of an authentication attempt.
InputEvent
KeyCode
Which key is pressed. Not all of these are probable to appear on most systems. A lot of this list is @wez trawling docs and making an entry for things that might be possible in this first pass.

Traits§

App
The App trait that must be implemented for TUI applications served over SSH.
AuthHandler
Handler for SSH authentication methods.

Functions§

new_server
Starts an SSH server that serves your TUI application.
new_server_with_config
Starts an SSH server with the specified config

Type Aliases§

SSHUITerminal