mirror of
https://gitlab.com/fabinfra/fabaccess/sute.git
synced 2025-03-12 22:51:50 +01:00
73 lines
1.7 KiB
Rust
73 lines
1.7 KiB
Rust
|
use std::io;
|
||
|
use std::sync::{Arc, Mutex};
|
||
|
|
||
|
use tui::backend::{Backend, TermionBackend};
|
||
|
use tui::Terminal;
|
||
|
use termion::raw::IntoRawMode;
|
||
|
use termion::input::TermRead;
|
||
|
use termion::event::Key;
|
||
|
|
||
|
use futures::StreamExt;
|
||
|
use futures_signals::signal::SignalExt;
|
||
|
|
||
|
use clap::{App, Arg};
|
||
|
|
||
|
mod banner;
|
||
|
mod config;
|
||
|
mod app;
|
||
|
mod input;
|
||
|
mod util;
|
||
|
mod ui;
|
||
|
mod schema;
|
||
|
|
||
|
use banner::BANNER;
|
||
|
|
||
|
fn main() -> Result<(), io::Error> {
|
||
|
|
||
|
let matches = App::new("sute 🌸")
|
||
|
.version(env!("CARGO_PKG_VERSION"))
|
||
|
.author(env!("CARGO_PKG_AUTHORS"))
|
||
|
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||
|
.usage("Press `?` in the GUI to see keybindings")
|
||
|
.before_help(BANNER)
|
||
|
.arg(Arg::with_name("config")
|
||
|
.short("c")
|
||
|
.long("config")
|
||
|
.help("Specify configuration file path")
|
||
|
.takes_value(true))
|
||
|
.arg(Arg::with_name("server")
|
||
|
.short("s")
|
||
|
.long("server")
|
||
|
.help("Connect to the specified address[:port] as server")
|
||
|
.takes_value(true))
|
||
|
.get_matches();
|
||
|
|
||
|
let server = matches.value_of("server").unwrap_or("localhost");
|
||
|
|
||
|
let stdout = io::stdout().into_raw_mode()?;
|
||
|
let backend = TermionBackend::new(stdout);
|
||
|
let mut terminal = Terminal::new(backend)?;
|
||
|
terminal.hide_cursor()?;
|
||
|
|
||
|
let resize = util::Resize::new()?;
|
||
|
let api = schema::Api::connect(server);
|
||
|
let app = app::Sute::new(resize, Box::pin(api));
|
||
|
|
||
|
let mut stream = app.to_stream();
|
||
|
loop {
|
||
|
if let Some(mut state) = smol::block_on(stream.next()) {
|
||
|
if !state.running {
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
terminal.draw(|f| ui::draw_ui(f, &mut state))?;
|
||
|
} else {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
terminal.show_cursor()?;
|
||
|
|
||
|
Ok(())
|
||
|
}
|