dialog/
dialog.rs

1use std::{
2    error::Error,
3    sync::{mpsc::Sender, Arc},
4};
5
6use cursive::Cursive;
7use russh_keys::key::SignatureHash;
8use ssh_ui::{
9    cursive::views::{Dialog, TextView},
10    russh_keys::key::{KeyPair, PublicKey},
11    App, AppServer, AppSession, SessionHandle,
12};
13
14struct DialogAppSession {}
15
16impl DialogAppSession {
17    pub fn new() -> Self {
18        Self {}
19    }
20}
21
22impl AppSession for DialogAppSession {
23    fn on_start(
24        &mut self,
25        _siv: &mut Cursive,
26        _session_handle: SessionHandle,
27        _pub_key: Option<PublicKey>,
28        _force_refresh_sender: Sender<()>,
29    ) -> Result<Box<dyn cursive::View>, Box<dyn Error>> {
30        println!("on_start");
31        Ok(Box::new(
32            Dialog::around(TextView::new("Hello over ssh!"))
33                .title("ssh_ui")
34                .button("Quit", |s| s.quit()),
35        ))
36    }
37}
38
39struct DialogApp {}
40
41impl App for DialogApp {
42    fn on_load(&mut self) -> Result<(), Box<dyn Error>> {
43        println!("load");
44        Ok(())
45    }
46
47    fn new_session(&self) -> Box<dyn AppSession> {
48        println!("new session");
49        Box::new(DialogAppSession::new())
50    }
51}
52
53#[tokio::main]
54async fn main() {
55    let key_pairs = [
56        KeyPair::generate_rsa(4096, SignatureHash::SHA2_256).unwrap(),
57        KeyPair::generate_ed25519().unwrap(),
58    ];
59    let mut server = AppServer::new_with_port(2222);
60    let app = DialogApp {};
61    server.run(&key_pairs, Arc::new(app)).await.unwrap();
62}