sute/src/main.rs
2020-10-30 16:32:20 +01:00

93 lines
2.4 KiB
Rust

#[macro_use]
extern crate slog;
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()?;
// Refresh the screen once by resizing the terminal
if let Ok((x,y)) = termion::terminal_size() {
terminal.resize(tui::layout::Rect::new(0, 0, x,y)).unwrap();
}
let drain = Arc::new(app::LogDrain::new());
let log = slog::Logger::root(slog::Fuse::new(drain.clone()), o!());
let resize = util::Resize::new()?;
let api = schema::Api::connect(log.clone(), server);
let app = app::Sute::new(resize, drain, Box::pin(api));
crit!(log, "This is a test: {}", 42);
error!(log, "This is a test: {}", 42);
warn!(log, "This is a test: {}", 42);
info!(log, "This is a test: {}", 42);
debug!(log, "This is a test: {}", 42);
trace!(log, "This is a test: {}", 42);
let mut state = app.get_state();
terminal.draw(|f| ui::draw_ui(f, &mut state))?;
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(())
}