From 817b6d6da20b2b76cd9a29eda546d8e8faf6f4a8 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 13 Sep 2024 11:39:46 +0200 Subject: [PATCH] lib: Rename examples --- examples/{basic.rs => basic_rmui.rs} | 0 examples/hello.rs | 140 ++++++++++++++++------- examples/{hello_im.rs => hello_rrmui.rs} | 43 +++---- 3 files changed, 121 insertions(+), 62 deletions(-) rename examples/{basic.rs => basic_rmui.rs} (100%) rename examples/{hello_im.rs => hello_rrmui.rs} (57%) diff --git a/examples/basic.rs b/examples/basic_rmui.rs similarity index 100% rename from examples/basic.rs rename to examples/basic_rmui.rs diff --git a/examples/hello.rs b/examples/hello.rs index 5de49408..368813a3 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,36 +1,94 @@ +// use anyhow::Result; + +// use termion::event::Key; + +// use ratatui::{Frame, Viewport}; + +// use radicle_tui as tui; + +// use tui::store; +// use tui::ui::im::widget::Window; +// use tui::ui::im::Show; +// use tui::ui::im::{Borders, Context}; +// use tui::{Channel, Exit}; + +// const ALIEN: &str = r#" +// /// /// ,---------------------------------. +// /// /// | Hey there, press (q) to quit... | +// // // '---------------------------------' +// //,,,///,,,// .. +// /////////////////// . +// //////@@@@@//////@@@@@/// +// //////@@###//////@@###/// +// ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +// ,,, /// /// ,,, +// ,,, /// /// ,,, +// /// /// +// ///// ///// +// "#; + +// #[derive(Clone, Debug)] +// struct App { +// alien: String, +// } + +// #[derive(Clone, Debug)] +// enum Message { +// Quit, +// } + +// impl store::Update for App { +// type Return = (); + +// fn update(&mut self, message: Message) -> Option> { +// match message { +// Message::Quit => Some(Exit { value: None }), +// } +// } +// } + +// impl Show for App { +// fn show(&self, ctx: &Context, frame: &mut Frame) -> Result<()> { +// Window::default().show(ctx, |ui| { +// ui.text_view(frame, self.alien.clone(), &mut (0, 0), Some(Borders::None)); + +// if ui.input_global(|key| key == Key::Char('q')) { +// ui.send_message(Message::Quit); +// } +// }); + +// Ok(()) +// } +// } + +// #[tokio::main] +// pub async fn main() -> Result<()> { +// let app = App { +// alien: ALIEN.to_string(), +// }; + +// tui::im(app, Viewport::default(), Channel::default()).await?; + +// Ok(()) +// } + use anyhow::Result; -use ratatui::Viewport; use termion::event::Key; -use ratatui::style::Color; -use ratatui::text::Text; +use ratatui::{Frame, Viewport}; use radicle_tui as tui; use tui::store; -use tui::ui::rm::widget::input::{TextArea, TextAreaProps}; -use tui::ui::rm::widget::ToWidget; -use tui::{BoxedAny, Channel, Exit}; - -const ALIEN: &str = r#" - /// /// ,---------------------------------. - /// /// | Hey there, press (q) to quit... | - // // '---------------------------------' - //,,,///,,,// .. - /////////////////// . - //////@@@@@//////@@@@@/// - //////@@###//////@@###/// -,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, - ,,, /// /// ,,, - ,,, /// /// ,,, - /// /// - ///// ///// -"#; +use tui::ui::im::widget::Window; +use tui::ui::im::Show; +use tui::ui::im::{Borders, Context}; +use tui::{Channel, Exit}; #[derive(Clone, Debug)] struct App { - alien: String, + hello: String, } #[derive(Clone, Debug)] @@ -48,29 +106,27 @@ impl store::Update for App { } } -#[tokio::main] -pub async fn main() -> Result<()> { - let channel = Channel::default(); - let sender = channel.tx.clone(); - let app = App { - alien: ALIEN.to_string(), - }; +impl Show for App { + fn show(&self, ctx: &Context, frame: &mut Frame) -> Result<()> { + Window::default().show(ctx, |ui| { + ui.text_view(frame, self.hello.clone(), &mut (0, 0), Some(Borders::None)); - let scene = TextArea::default() - .to_widget(sender.clone()) - .on_event(|key, _, _| match key { - Key::Char('q') => Some(Message::Quit), - _ => None, - }) - .on_update(|app: &App| { - TextAreaProps::default() - .content(Text::styled(app.alien.clone(), Color::Rgb(85, 85, 255))) - .handle_keys(false) - .to_boxed_any() - .into() + if ui.input_global(|key| key == Key::Char('q')) { + ui.send_message(Message::Quit); + } }); - tui::rm(app, scene, Viewport::default(), channel).await?; + Ok(()) + } +} + +#[tokio::main] +pub async fn main() -> Result<()> { + let app = App { + hello: "Hello World!".to_string(), + }; + + tui::im(app, Viewport::default(), Channel::default()).await?; Ok(()) } diff --git a/examples/hello_im.rs b/examples/hello_rrmui.rs similarity index 57% rename from examples/hello_im.rs rename to examples/hello_rrmui.rs index 3072a438..5de49408 100644 --- a/examples/hello_im.rs +++ b/examples/hello_rrmui.rs @@ -1,16 +1,17 @@ use anyhow::Result; +use ratatui::Viewport; use termion::event::Key; -use ratatui::{Frame, Viewport}; +use ratatui::style::Color; +use ratatui::text::Text; use radicle_tui as tui; use tui::store; -use tui::ui::im::widget::Window; -use tui::ui::im::Show; -use tui::ui::im::{Borders, Context}; -use tui::{Channel, Exit}; +use tui::ui::rm::widget::input::{TextArea, TextAreaProps}; +use tui::ui::rm::widget::ToWidget; +use tui::{BoxedAny, Channel, Exit}; const ALIEN: &str = r#" /// /// ,---------------------------------. @@ -47,27 +48,29 @@ impl store::Update for App { } } -impl Show for App { - fn show(&self, ctx: &Context, frame: &mut Frame) -> Result<()> { - Window::default().show(ctx, |ui| { - ui.text_view(frame, self.alien.clone(), &mut (0, 0), Some(Borders::None)); - - if ui.input_global(|key| key == Key::Char('q')) { - ui.send_message(Message::Quit); - } - }); - - Ok(()) - } -} - #[tokio::main] pub async fn main() -> Result<()> { + let channel = Channel::default(); + let sender = channel.tx.clone(); let app = App { alien: ALIEN.to_string(), }; - tui::im(app, Viewport::default(), Channel::default()).await?; + let scene = TextArea::default() + .to_widget(sender.clone()) + .on_event(|key, _, _| match key { + Key::Char('q') => Some(Message::Quit), + _ => None, + }) + .on_update(|app: &App| { + TextAreaProps::default() + .content(Text::styled(app.alien.clone(), Color::Rgb(85, 85, 255))) + .handle_keys(false) + .to_boxed_any() + .into() + }); + + tui::rm(app, scene, Viewport::default(), channel).await?; Ok(()) }