Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Rename examples
Erik Kundt committed 1 year ago
commit 817b6d6da20b2b76cd9a29eda546d8e8faf6f4a8
parent a7f99eb1eb91a6c5d2c66dce8e701aa305e8d787
5 files changed +286 -227
deleted examples/basic.rs
@@ -1,114 +0,0 @@
-
use anyhow::Result;
-

-
use ratatui::Viewport;
-
use termion::event::Key;
-

-
use ratatui::layout::Constraint;
-

-
use radicle_tui as tui;
-

-
use tui::store;
-
use tui::ui::rm::widget::container::{Container, Header, HeaderProps};
-
use tui::ui::rm::widget::input::{TextView, TextViewProps, TextViewState};
-
use tui::ui::rm::widget::window::{Page, Shortcuts, ShortcutsProps, Window, WindowProps};
-
use tui::ui::rm::widget::ToWidget;
-
use tui::ui::Column;
-
use tui::{BoxedAny, Channel, Exit};
-

-
const CONTENT: &str = r#"
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
-
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 
-
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure 
-
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
-

-
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
-
mollit anim id est laborum.
-
"#;
-

-
#[derive(Clone, Debug)]
-
struct App {
-
    content: String,
-
}
-

-
#[derive(Clone, Debug)]
-
enum Message {
-
    Quit,
-
    ReverseContent,
-
}
-

-
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 }),
-
            Message::ReverseContent => {
-
                self.content = self.content.chars().rev().collect::<String>();
-
                None
-
            }
-
        }
-
    }
-
}
-

-
#[tokio::main]
-
pub async fn main() -> Result<()> {
-
    let channel = Channel::default();
-
    let sender = channel.tx.clone();
-
    let app = App {
-
        content: CONTENT.to_string(),
-
    };
-

-
    let page =
-
        Page::default()
-
            .content(
-
                Container::default()
-
                    .header(Header::default().to_widget(sender.clone()).on_update(|_| {
-
                        HeaderProps::default()
-
                            .columns(vec![
-
                                Column::new("", Constraint::Length(0)),
-
                                Column::new(
-
                                    "The standard Lorem Ipsum passage, used since the 1500s",
-
                                    Constraint::Fill(1),
-
                                ),
-
                            ])
-
                            .to_boxed_any()
-
                            .into()
-
                    }))
-
                    .content(TextView::default().to_widget(sender.clone()).on_update(
-
                        |app: &App| {
-
                            let content = app.content.clone();
-
                            TextViewProps::default()
-
                                .state(Some(TextViewState::default().content(content)))
-
                                .handle_keys(false)
-
                                .to_boxed_any()
-
                                .into()
-
                        },
-
                    ))
-
                    .to_widget(sender.clone()),
-
            )
-
            .shortcuts(
-
                Shortcuts::default()
-
                    .to_widget(sender.clone())
-
                    .on_update(|_| {
-
                        ShortcutsProps::default()
-
                            .shortcuts(&[("q", "quit"), ("r", "reverse")])
-
                            .to_boxed_any()
-
                            .into()
-
                    }),
-
            )
-
            .to_widget(sender.clone());
-

-
    let window = Window::default()
-
        .page(0, page)
-
        .to_widget(sender.clone())
-
        .on_event(|key, _, _| match key {
-
            Key::Char('r') => Some(Message::ReverseContent),
-
            Key::Char('q') => Some(Message::Quit),
-
            _ => None,
-
        })
-
        .on_update(|_| WindowProps::default().current_page(0).to_boxed_any().into());
-

-
    tui::rm(app, window, Viewport::default(), channel).await?;
-

-
    Ok(())
-
}
added examples/basic_rmui.rs
@@ -0,0 +1,114 @@
+
use anyhow::Result;
+

+
use ratatui::Viewport;
+
use termion::event::Key;
+

+
use ratatui::layout::Constraint;
+

+
use radicle_tui as tui;
+

+
use tui::store;
+
use tui::ui::rm::widget::container::{Container, Header, HeaderProps};
+
use tui::ui::rm::widget::input::{TextView, TextViewProps, TextViewState};
+
use tui::ui::rm::widget::window::{Page, Shortcuts, ShortcutsProps, Window, WindowProps};
+
use tui::ui::rm::widget::ToWidget;
+
use tui::ui::Column;
+
use tui::{BoxedAny, Channel, Exit};
+

+
const CONTENT: &str = r#"
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 
+
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure 
+
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+

+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
+
mollit anim id est laborum.
+
"#;
+

+
#[derive(Clone, Debug)]
+
struct App {
+
    content: String,
+
}
+

+
#[derive(Clone, Debug)]
+
enum Message {
+
    Quit,
+
    ReverseContent,
+
}
+

+
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 }),
+
            Message::ReverseContent => {
+
                self.content = self.content.chars().rev().collect::<String>();
+
                None
+
            }
+
        }
+
    }
+
}
+

+
#[tokio::main]
+
pub async fn main() -> Result<()> {
+
    let channel = Channel::default();
+
    let sender = channel.tx.clone();
+
    let app = App {
+
        content: CONTENT.to_string(),
+
    };
+

+
    let page =
+
        Page::default()
+
            .content(
+
                Container::default()
+
                    .header(Header::default().to_widget(sender.clone()).on_update(|_| {
+
                        HeaderProps::default()
+
                            .columns(vec![
+
                                Column::new("", Constraint::Length(0)),
+
                                Column::new(
+
                                    "The standard Lorem Ipsum passage, used since the 1500s",
+
                                    Constraint::Fill(1),
+
                                ),
+
                            ])
+
                            .to_boxed_any()
+
                            .into()
+
                    }))
+
                    .content(TextView::default().to_widget(sender.clone()).on_update(
+
                        |app: &App| {
+
                            let content = app.content.clone();
+
                            TextViewProps::default()
+
                                .state(Some(TextViewState::default().content(content)))
+
                                .handle_keys(false)
+
                                .to_boxed_any()
+
                                .into()
+
                        },
+
                    ))
+
                    .to_widget(sender.clone()),
+
            )
+
            .shortcuts(
+
                Shortcuts::default()
+
                    .to_widget(sender.clone())
+
                    .on_update(|_| {
+
                        ShortcutsProps::default()
+
                            .shortcuts(&[("q", "quit"), ("r", "reverse")])
+
                            .to_boxed_any()
+
                            .into()
+
                    }),
+
            )
+
            .to_widget(sender.clone());
+

+
    let window = Window::default()
+
        .page(0, page)
+
        .to_widget(sender.clone())
+
        .on_event(|key, _, _| match key {
+
            Key::Char('r') => Some(Message::ReverseContent),
+
            Key::Char('q') => Some(Message::Quit),
+
            _ => None,
+
        })
+
        .on_update(|_| WindowProps::default().current_page(0).to_boxed_any().into());
+

+
    tui::rm(app, window, Viewport::default(), channel).await?;
+

+
    Ok(())
+
}
modified 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<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 {
    }
}

+
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));
+

+
            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(),
+
        hello: "Hello World!".to_string(),
    };

-
    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?;
+
    tui::im(app, Viewport::default(), Channel::default()).await?;

    Ok(())
}
deleted examples/hello_im.rs
@@ -1,73 +0,0 @@
-
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(())
-
}
added examples/hello_rrmui.rs
@@ -0,0 +1,76 @@
+
use anyhow::Result;
+

+
use ratatui::Viewport;
+
use termion::event::Key;
+

+
use ratatui::style::Color;
+
use ratatui::text::Text;
+

+
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... |
+
        //         //       '---------------------------------'  
+
        //,,,///,,,//      .. 
+
     ///////////////////  .  
+
  //////@@@@@//////@@@@@///  
+
  //////@@###//////@@###///  
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
     ,,,  ///   ///  ,,,     
+
     ,,,  ///   ///  ,,,     
+
          ///   ///          
+
        /////   /////
+
"#;
+

+
#[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 }),
+
        }
+
    }
+
}
+

+
#[tokio::main]
+
pub async fn main() -> Result<()> {
+
    let channel = Channel::default();
+
    let sender = channel.tx.clone();
+
    let app = App {
+
        alien: ALIEN.to_string(),
+
    };
+

+
    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(())
+
}