lib: Rename examples

This commit is contained in:
Erik Kundt
2024-09-13 15:40:36 +02:00
parent a7f99eb1eb
commit 817b6d6da2
3 changed files with 121 additions and 62 deletions
+98 -42
View File
@@ -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<Message> for App {
// type Return = ();
// fn update(&mut self, message: Message) -> Option<tui::Exit<()>> {
// match message {
// Message::Quit => Some(Exit { value: None }),
// }
// }
// }
// impl Show<Message> for App {
// fn show(&self, ctx: &Context<Message>, 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<Message> 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<Message> for App {
fn show(&self, ctx: &Context<Message>, 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(())
}
@@ -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<Message> for App {
}
}
impl Show<Message> for App {
fn show(&self, ctx: &Context<Message>, 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(())
}