Code Monkey home page Code Monkey logo

ssh_ui's Introduction

ssh_ui

ssh_ui helps you painlessly turn a cursive-based terminal UI (TUI) into an application accessible over ssh. Designed to make the creation of BBS systems or ssh-based games simple, ssh_ui takes a minimally opinionated approach to opening a TUI up to remote connections, beyond requiring you to use cursive. The ssh server implementation is provided by russh.

The main function of the simplest ssh_ui-based application looks something like this:

#[tokio::main]
async fn main() {
    let key_pair = KeyPair::generate_rsa(3072, SignatureHash::SHA2_256).unwrap();
    let mut server = AppServer::new_with_port(2222);
    let app = DialogApp {};
    server.run(&[key_pair], Arc::new(app)).await.unwrap();
}

First this generates a new keypair (but you should load several from disk for user-facing installations). Then it initializes a new AppServer on port 2222 and a new instance of a DialogApp, then calls AppServer::run to listen on the specified port for incoming connections. Let's look next at what makes AppServer tick.

struct DialogApp {}

impl App for DialogApp {
    fn on_load(&mut self) -> Result<(), Box<dyn Error>> {
        Ok(())
    }

    fn new_session(&self) -> Box<dyn AppSession> {
        Box::new(DialogAppSession::new())
    }
}

All it's doing here is providing a new DialogAppSession whenever there's a new incoming ssh connection. DialogAppSession is implemented as follows:

struct DialogAppSession {}

impl DialogAppSession {
    pub fn new() -> Self {
        Self {}
    }
}

impl AppSession for DialogAppSession {
    fn on_start(
        &mut self,
        _siv: &mut Cursive,
        _session_handle: SessionHandle,
        _pub_key: PublicKey,
        _force_refresh_sender: Sender<()>,
    ) -> Result<Box<dyn cursive::View>, Box<dyn Error>> {
        println!("on_start");
        Ok(Box::new(
            Dialog::around(TextView::new("Hello over ssh!"))
                .title("ssh_ui")
                .button("Quit", |s| s.quit()),
        ))
    }
}

This is where the actual cursive TUI is created and returned to ssh_ui. You can return whatever TUI you want, and ssh_ui will take care of serving it to the client.

Contributions

If you'd like to use ssh_ui and it doesn't quite fit your needs, feel free to open an issue or pull request on the GitHub repository.

ssh_ui's People

Contributors

ellenhp avatar

Stargazers

Arturo Lecuona avatar Richard Zilahi avatar Mark Volovoi avatar Evan Sarmiento avatar Sumit Datta avatar  avatar Anton Troskie avatar James Newman avatar Nikhil Prabhu avatar Matvey avatar Chris Cummings avatar Hector avatar Peter Johnson avatar

Watchers

 avatar  avatar

Forkers

mystery3525

ssh_ui's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.