Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
inbox: Add shortcut widget
Erik Kundt committed 2 years ago
commit 5e18f3f0fd7060d17237336bdfeb0300f338d19b
parent 2bafeba312c577475a1d0493013347be21a6d35c
1 file changed +17 -6
modified bin/commands/inbox/select/flux/ui.rs
@@ -2,11 +2,11 @@ use tokio::sync::mpsc::UnboundedSender;

use termion::event::Key;

-
use ratatui::backend::Backend;
use ratatui::widgets::Paragraph;
+
use ratatui::{backend::Backend, layout::Rect};

use radicle_tui as tui;
-
use tui::flux::ui::{Render, Widget};
+
use tui::flux::ui::widget::{Render, Shortcut, ShortcutWidget, ShortcutWidgetProps, Widget};

use crate::tui_inbox::select::flux::{Action, InboxState};

@@ -27,6 +27,8 @@ pub struct ListPage {
    pub action_tx: UnboundedSender<Action>,
    // Mapped Props from State
    props: Props,
+
    /// Shortcut widget
+
    shortcuts: ShortcutWidget<Action>,
}

impl Widget<InboxState, Action> for ListPage {
@@ -34,9 +36,10 @@ impl Widget<InboxState, Action> for ListPage {
    where
        Self: Sized,
    {
-
        ListPage {
+
        Self {
            action_tx: action_tx.clone(),
            props: Props::from(state),
+
            shortcuts: ShortcutWidget::new(state, action_tx.clone()),
        }
        .move_with_state(state)
    }
@@ -66,12 +69,20 @@ impl Widget<InboxState, Action> for ListPage {
}

impl Render<()> for ListPage {
-
    fn render<B: Backend>(&self, frame: &mut ratatui::Frame, _props: ()) {
+
    fn render<B: Backend>(&self, frame: &mut ratatui::Frame, _area: Rect, _props: ()) {
        let area = frame.size();
        let layout = tui::flux::ui::layout::default_page(area, 1u16, 1u16);

-
        let shortcuts = Paragraph::new(String::from("q quit"));
+
        self.shortcuts.render::<B>(
+
            frame,
+
            layout.shortcuts,
+
            ShortcutWidgetProps {
+
                shortcuts: vec![Shortcut::new("q", "quit"), Shortcut::new("s", "show"), Shortcut::new("?", "help")],
+
                divider: '∙',
+
            },
+
        );

-
        frame.render_widget(shortcuts, layout.shortcuts);
+
        // let shortcuts = Paragraph::new(String::from("q quit"));
+
        // frame.render_widget(self.shortcuts, layout.shortcuts);
    }
}