From a0582ead78fda02e4137a82e100963e88362f252 Mon Sep 17 00:00:00 2001 From: krolxon Date: Tue, 23 Apr 2024 16:10:03 +0530 Subject: get basic tui working with Ratatui --- src/main.rs | 71 +++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 16 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 09c7363..3fbfc14 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,63 @@ -mod cli; -mod connection; +#![allow(unused_imports)] use clap::Parser; -use cli::Args; -use cli::Command; -use connection::Connection; +use rmptui::app; +use rmptui::app::App; +use rmptui::app::AppResult; +use rmptui::cli::Args; +use rmptui::cli::Command; +use rmptui::connection::Connection; +use rmptui::event::Event; +use rmptui::event::EventHandler; +use rmptui::handler; +use rmptui::tui; +use std::io; -fn main() -> Result<(), Box> { - let args = Args::parse(); - let mut conn = Connection::new("127.0.0.1:6600")?; +use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind}; +use ratatui::{ + prelude::*, + symbols::border, + widgets::{block::*, *}, +}; - match args.command { - Command::Volume { vol } => { - conn.set_volume(vol); +pub type Result = core::result::Result; +pub type Error = Box; + +fn main() -> AppResult<()> { + // let args = Args::parse(); + + // if args.no_tui { + // handle_tui()?; + // } else { + // match args.command { + // Command::Volume { vol } => { + // conn.set_volume(vol); + // } + // Command::Dmenu => conn.play_dmenu().unwrap(), + // Command::Fzf => conn.play_fzf().unwrap(), + // Command::Status => conn.status(), + // Command::Pause => conn.pause(), + // Command::Toggle => conn.toggle_pause(), + // }; + // } + + let backend = CrosstermBackend::new(io::stderr()); + let terminal = Terminal::new(backend)?; + let mut app = App::new("127.0.0.1:6600"); + let events = EventHandler::new(250); + + let mut tui = tui::Tui::new(terminal, events); + tui.init()?; + + while app.running { + tui.draw(&mut app)?; + match tui.events.next()? { + Event::Tick => app.tick(), + Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?, + Event::Mouse(_) => {} + Event::Resize(_, _) => {} } - Command::Dmenu => conn.play_dmenu(), - Command::Fzf => conn.play_fzf(), - Command::Status => conn.status(), - Command::Pause => conn.pause(), - Command::Toggle => conn.toggle_pause(), } + Ok(()) } -- cgit v1.2.3