Skip to content

Commit

Permalink
Fixes hello example
Browse files Browse the repository at this point in the history
  • Loading branch information
erak committed Sep 18, 2024
1 parent 432fff0 commit 3a36a03
Showing 1 changed file with 18 additions and 77 deletions.
95 changes: 18 additions & 77 deletions examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,77 +1,3 @@
// 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 termion::event::Key;
Expand All @@ -86,9 +12,24 @@ 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 {
hello: String,
alien: String,
}

#[derive(Clone, Debug)]
Expand All @@ -109,7 +50,7 @@ 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.hello.clone(), &mut (0, 0), Some(Borders::None));
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);
Expand All @@ -123,7 +64,7 @@ impl Show<Message> for App {
#[tokio::main]
pub async fn main() -> Result<()> {
let app = App {
hello: "Hello World!".to_string(),
alien: ALIEN.to_string(),
};

tui::im(app, Viewport::default(), Channel::default()).await?;
Expand Down

0 comments on commit 3a36a03

Please sign in to comment.