Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
inbox: Empty impl as flux app
Erik Kundt committed 2 years ago
commit 2bafeba312c577475a1d0493013347be21a6d35c
parent e8f3179494c31d1a277bfb26f30a70c2a26f0db1
10 files changed +983 -601
modified bin/commands/inbox.rs
@@ -148,11 +148,7 @@ pub fn run(options: Options, _ctx: impl terminal::Context) -> anyhow::Result<()>
            );
            let output = Window::default().run(&mut app, 1000 / FPS)?;

-
            let output = output
-
                .map(|o| serde_json::to_string(&o).unwrap_or_default())
-
                .unwrap_or_default();
-

-
            eprint!("{output}");
+
            eprint!("{:?}", output);
        }
    }

deleted bin/commands/inbox/select/event.rs
@@ -1,161 +0,0 @@
-
use radicle::node::notifications::NotificationId;
-

-
use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection};
-
use tuirealm::event::{Event, Key, KeyEvent};
-
use tuirealm::{MockComponent, NoUserEvent};
-

-
use radicle_tui as tui;
-

-
use tui::realm::ui::state::ItemState;
-
use tui::realm::ui::widget::container::{AppHeader, GlobalListener, LabeledContainer};
-
use tui::realm::ui::widget::context::{ContextBar, Shortcuts};
-
use tui::realm::ui::widget::list::PropertyList;
-
use tui::realm::ui::widget::Widget;
-
use tui::{Id, SelectionExit};
-

-
use super::ui::{IdSelect, OperationSelect};
-
use super::{InboxOperation, Message};
-

-
/// Since the framework does not know the type of messages that are being
-
/// passed around in the app, the following handlers need to be implemented for
-
/// each component used.
-
///
-
/// TODO: should handle `Event::WindowResize`, which is not emitted by `termion`.
-
impl tuirealm::Component<Message, NoUserEvent> for Widget<GlobalListener> {
-
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
-
        match event {
-
            Event::Keyboard(KeyEvent {
-
                code: Key::Char('q'),
-
                ..
-
            }) => Some(Message::Quit(None)),
-
            _ => None,
-
        }
-
    }
-
}
-

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<IdSelect> {
-
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
-
        let mut submit = || -> Option<NotificationId> {
-
            match self.perform(Cmd::Submit) {
-
                CmdResult::Submit(state) => {
-
                    let selected = ItemState::try_from(state).ok()?.selected()?;
-
                    let item = self.items().get(selected)?;
-
                    Some(item.id().to_owned())
-
                }
-
                _ => None,
-
            }
-
        };
-

-
        match event {
-
            Event::Keyboard(KeyEvent { code: Key::Up, .. })
-
            | Event::Keyboard(KeyEvent {
-
                code: Key::Char('k'),
-
                ..
-
            }) => {
-
                self.perform(Cmd::Move(MoveDirection::Up));
-
                Some(Message::Tick)
-
            }
-
            Event::Keyboard(KeyEvent {
-
                code: Key::Down, ..
-
            })
-
            | Event::Keyboard(KeyEvent {
-
                code: Key::Char('j'),
-
                ..
-
            }) => {
-
                self.perform(Cmd::Move(MoveDirection::Down));
-
                Some(Message::Tick)
-
            }
-
            Event::Keyboard(KeyEvent {
-
                code: Key::Enter, ..
-
            }) => submit().map(|id| {
-
                let output = SelectionExit::default().with_id(Id::Notification(id));
-
                Message::Quit(Some(output))
-
            }),
-
            _ => None,
-
        }
-
    }
-
}
-

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<OperationSelect> {
-
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
-
        let mut submit = || -> Option<NotificationId> {
-
            match self.perform(Cmd::Submit) {
-
                CmdResult::Submit(state) => {
-
                    let selected = ItemState::try_from(state).ok()?.selected()?;
-
                    let item = self.items().get(selected)?;
-
                    Some(item.id().to_owned())
-
                }
-
                _ => None,
-
            }
-
        };
-

-
        match event {
-
            Event::Keyboard(KeyEvent { code: Key::Up, .. })
-
            | Event::Keyboard(KeyEvent {
-
                code: Key::Char('k'),
-
                ..
-
            }) => {
-
                self.perform(Cmd::Move(MoveDirection::Up));
-
                Some(Message::Tick)
-
            }
-
            Event::Keyboard(KeyEvent {
-
                code: Key::Down, ..
-
            })
-
            | Event::Keyboard(KeyEvent {
-
                code: Key::Char('j'),
-
                ..
-
            }) => {
-
                self.perform(Cmd::Move(MoveDirection::Down));
-
                Some(Message::Tick)
-
            }
-
            Event::Keyboard(KeyEvent {
-
                code: Key::Enter, ..
-
            }) => submit().map(|id| {
-
                let exit = SelectionExit::default()
-
                    .with_operation(InboxOperation::Show.to_string())
-
                    .with_id(Id::Notification(id));
-
                Message::Quit(Some(exit))
-
            }),
-
            Event::Keyboard(KeyEvent {
-
                code: Key::Char('c'),
-
                ..
-
            }) => submit().map(|id| {
-
                let exit = SelectionExit::default()
-
                    .with_operation(InboxOperation::Clear.to_string())
-
                    .with_id(Id::Notification(id));
-
                Message::Quit(Some(exit))
-
            }),
-
            _ => None,
-
        }
-
    }
-
}
-

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<AppHeader> {
-
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
-
        None
-
    }
-
}
-

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<LabeledContainer> {
-
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
-
        None
-
    }
-
}
-

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<PropertyList> {
-
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
-
        None
-
    }
-
}
-

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<ContextBar> {
-
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
-
        None
-
    }
-
}
-

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<Shortcuts> {
-
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
-
        None
-
    }
-
}
added bin/commands/inbox/select/flux.rs
@@ -0,0 +1,84 @@
+
#[path = "flux/ui.rs"]
+
mod ui;
+

+
use std::default;
+

+
use anyhow::Result;
+

+
use radicle::node::notifications::Notification;
+
use radicle_tui as tui;
+
use tui::cob::inbox::Filter;
+
use tui::context::Context;
+
use tui::flux::store::{State, Store};
+
use tui::flux::termination::{self, Interrupted};
+
use tui::flux::ui::Frontend;
+

+
use crate::tui_inbox::select::flux::ui::ListPage;
+

+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
+
pub enum Mode {
+
    Id,
+
    #[default]
+
    Operation,
+
}
+

+
pub struct App {
+
    context: Context,
+
    filter: Filter,
+
}
+

+
#[derive(Clone)]
+
pub struct InboxState {
+
    notifications: Vec<String>,
+
}
+

+
impl InboxState {
+
    pub fn notifications(&self) -> &Vec<String> {
+
        &self.notifications
+
    }
+
}
+

+
pub enum Action {
+
    Exit,
+
}
+

+
impl State<Action> for InboxState {
+
    fn tick(&self) {}
+

+
    fn handle_action(self, action: Action) -> anyhow::Result<bool> {
+
        match action {
+
            Action::Exit => Ok(true),
+
        }
+
    }
+
}
+

+
impl App {
+
    pub fn new(context: Context, filter: Filter) -> Self {
+
        Self { context, filter }
+
    }
+

+
    pub async fn run(&self) -> Result<()> {
+
        let (terminator, mut interrupt_rx) = termination::create_termination();
+
        let (store, state_rx) = Store::<Action, InboxState>::new();
+
        let (frontend, action_rx) = Frontend::<Action>::new();
+
        let state = InboxState {
+
            notifications: vec![],
+
        };
+

+
        tokio::try_join!(
+
            store.main_loop(state, terminator, action_rx, interrupt_rx.resubscribe()),
+
            frontend.main_loop::<InboxState, ListPage>(state_rx, interrupt_rx.resubscribe()),
+
        )?;
+

+
        if let Ok(reason) = interrupt_rx.recv().await {
+
            match reason {
+
                Interrupted::UserInt => {}
+
                Interrupted::OsSigInt => println!("exited because of an os sig int"),
+
            }
+
        } else {
+
            println!("exited because of an unexpected error");
+
        }
+

+
        Ok(())
+
    }
+
}
added bin/commands/inbox/select/flux/ui.rs
@@ -0,0 +1,77 @@
+
use tokio::sync::mpsc::UnboundedSender;
+

+
use termion::event::Key;
+

+
use ratatui::backend::Backend;
+
use ratatui::widgets::Paragraph;
+

+
use radicle_tui as tui;
+
use tui::flux::ui::{Render, Widget};
+

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

+
pub struct Props {
+
    notifications: Vec<String>,
+
}
+

+
impl From<&InboxState> for Props {
+
    fn from(state: &InboxState) -> Self {
+
        Props {
+
            notifications: state.notifications().clone(),
+
        }
+
    }
+
}
+

+
pub struct ListPage {
+
    /// Action sender
+
    pub action_tx: UnboundedSender<Action>,
+
    // Mapped Props from State
+
    props: Props,
+
}
+

+
impl Widget<InboxState, Action> for ListPage {
+
    fn new(state: &InboxState, action_tx: UnboundedSender<Action>) -> Self
+
    where
+
        Self: Sized,
+
    {
+
        ListPage {
+
            action_tx: action_tx.clone(),
+
            props: Props::from(state),
+
        }
+
        .move_with_state(state)
+
    }
+

+
    fn move_with_state(self, state: &InboxState) -> Self
+
    where
+
        Self: Sized,
+
    {
+
        ListPage {
+
            props: Props::from(state),
+
            ..self
+
        }
+
    }
+

+
    fn name(&self) -> &str {
+
        "list-page"
+
    }
+

+
    fn handle_key_event(&mut self, key: termion::event::Key) {
+
        match key {
+
            Key::Char('q') => {
+
                let _ = self.action_tx.send(Action::Exit);
+
            }
+
            _ => {}
+
        }
+
    }
+
}
+

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

+
        let shortcuts = Paragraph::new(String::from("q quit"));
+

+
        frame.render_widget(shortcuts, layout.shortcuts);
+
    }
+
}
deleted bin/commands/inbox/select/page.rs
@@ -1,168 +0,0 @@
-
use std::collections::HashMap;
-

-
use anyhow::Result;
-

-
use tuirealm::{AttrValue, Attribute, Frame, NoUserEvent};
-

-
use radicle_tui as tui;
-

-
use tui::common::cob::inbox::{Filter, SortBy};
-
use tui::common::context::Context;
-
use tui::realm::ui::layout;
-
use tui::realm::ui::state::ItemState;
-
use tui::realm::ui::theme::Theme;
-
use tui::realm::ui::widget::context::{Progress, Shortcuts};
-
use tui::realm::ui::widget::Widget;
-
use tui::realm::ViewPage;
-

-
use super::{ui, Application, Cid, ListCid, Message, Mode};
-

-
///
-
/// Home
-
///
-
pub struct ListView {
-
    active_component: ListCid,
-
    mode: Mode,
-
    filter: Filter,
-
    sort_by: SortBy,
-
    shortcuts: HashMap<ListCid, Widget<Shortcuts>>,
-
}
-

-
impl ListView {
-
    pub fn new(mode: Mode, filter: Filter, sort_by: SortBy) -> Self {
-
        Self {
-
            active_component: ListCid::NotificationBrowser,
-
            mode,
-
            filter,
-
            sort_by,
-
            shortcuts: HashMap::default(),
-
        }
-
    }
-

-
    fn update_context(
-
        &self,
-
        app: &mut Application<Cid, Message, NoUserEvent>,
-
        context: &Context,
-
        theme: &Theme,
-
    ) -> Result<()> {
-
        let state = app.state(&Cid::List(ListCid::NotificationBrowser))?;
-
        let progress = match ItemState::try_from(state) {
-
            Ok(state) => Progress::Step(
-
                state
-
                    .selected()
-
                    .map(|s| s.saturating_add(1))
-
                    .unwrap_or_default(),
-
                state.len(),
-
            ),
-
            Err(_) => Progress::None,
-
        };
-

-
        let context = ui::browse_context(context, theme, self.filter.clone(), progress);
-

-
        app.remount(Cid::List(ListCid::Context), context.to_boxed(), vec![])?;
-

-
        Ok(())
-
    }
-

-
    fn update_shortcuts(
-
        &self,
-
        app: &mut Application<Cid, Message, NoUserEvent>,
-
        cid: ListCid,
-
    ) -> Result<()> {
-
        if let Some(shortcuts) = self.shortcuts.get(&cid) {
-
            app.remount(
-
                Cid::List(ListCid::Shortcuts),
-
                shortcuts.clone().to_boxed(),
-
                vec![],
-
            )?;
-
        }
-

-
        Ok(())
-
    }
-
}
-

-
impl ViewPage<Cid, Message> for ListView {
-
    fn mount(
-
        &mut self,
-
        app: &mut Application<Cid, Message, NoUserEvent>,
-
        context: &Context,
-
        theme: &Theme,
-
    ) -> Result<()> {
-
        let browser = ui::operation_select(theme, context, self.filter.clone(), self.sort_by, None)
-
            .to_boxed();
-
        self.shortcuts = browser.as_ref().shortcuts();
-

-
        match self.mode {
-
            Mode::Id => {
-
                let notif_browser =
-
                    ui::id_select(theme, context, self.filter.clone(), self.sort_by, None)
-
                        .to_boxed();
-
                self.shortcuts = notif_browser.as_ref().shortcuts();
-

-
                app.remount(Cid::List(ListCid::NotificationBrowser), browser, vec![])?;
-
            }
-
            Mode::Operation => {
-
                let notif_browser =
-
                    ui::operation_select(theme, context, self.filter.clone(), self.sort_by, None)
-
                        .to_boxed();
-
                self.shortcuts = notif_browser.as_ref().shortcuts();
-

-
                app.remount(Cid::List(ListCid::NotificationBrowser), browser, vec![])?;
-
            }
-
        };
-

-
        app.active(&Cid::List(self.active_component.clone()))?;
-
        self.update_shortcuts(app, self.active_component.clone())?;
-
        self.update_context(app, context, theme)?;
-

-
        Ok(())
-
    }
-

-
    fn unmount(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
-
        app.umount(&Cid::List(ListCid::NotificationBrowser))?;
-
        app.umount(&Cid::List(ListCid::Context))?;
-
        app.umount(&Cid::List(ListCid::Shortcuts))?;
-
        Ok(())
-
    }
-

-
    fn update(
-
        &mut self,
-
        app: &mut Application<Cid, Message, NoUserEvent>,
-
        context: &Context,
-
        theme: &Theme,
-
        _message: Message,
-
    ) -> Result<Option<Message>> {
-
        self.update_context(app, context, theme)?;
-

-
        Ok(None)
-
    }
-

-
    fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, frame: &mut Frame) {
-
        let area = frame.size();
-
        let context_h = app
-
            .query(&Cid::List(ListCid::Context), Attribute::Height)
-
            .unwrap_or_default()
-
            .unwrap_or(AttrValue::Size(0))
-
            .unwrap_size();
-
        let shortcuts_h = 1u16;
-

-
        let layout = layout::default_page(area, context_h, shortcuts_h);
-

-
        app.view(
-
            &Cid::List(self.active_component.clone()),
-
            frame,
-
            layout.component,
-
        );
-

-
        app.view(&Cid::List(ListCid::Context), frame, layout.context);
-
        app.view(&Cid::List(ListCid::Shortcuts), frame, layout.shortcuts);
-
    }
-

-
    fn subscribe(&self, _app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
-
        Ok(())
-
    }
-

-
    fn unsubscribe(&self, _app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
-
        Ok(())
-
    }
-
}
added bin/commands/inbox/select/realm.rs
@@ -0,0 +1,225 @@
+
#[path = "realm/event.rs"]
+
mod event;
+
#[path = "realm/page.rs"]
+
mod page;
+
#[path = "realm/ui.rs"]
+
mod ui;
+

+
use std::fmt::Display;
+
use std::hash::Hash;
+

+
use anyhow::Result;
+

+
use serde::{Serialize, Serializer};
+

+
use tuirealm::application::PollStrategy;
+
use tuirealm::{Application, Frame, NoUserEvent, Sub, SubClause};
+

+
use radicle_tui as tui;
+

+
use tui::cob::inbox::Filter;
+
use tui::context::Context;
+
use tui::ui::subscription;
+
use tui::ui::theme::Theme;
+
use tui::{Exit, PageStack, SelectionExit, Tui};
+

+
use page::ListView;
+

+
/// Wrapper around radicle's `PatchId` that serializes
+
/// to a human-readable string.
+
#[derive(Clone, Debug, Eq, PartialEq)]
+
pub struct PatchId(radicle::cob::patch::PatchId);
+

+
impl From<radicle::cob::patch::PatchId> for PatchId {
+
    fn from(value: radicle::cob::patch::PatchId) -> Self {
+
        PatchId(value)
+
    }
+
}
+

+
impl Display for PatchId {
+
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+
        write!(f, "{}", self.0)
+
    }
+
}
+

+
impl Serialize for PatchId {
+
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+
    where
+
        S: Serializer,
+
    {
+
        serializer.serialize_str(&format!("{}", *self.0))
+
    }
+
}
+

+
/// The application's subject. It tells the application
+
/// which widgets to render and which output to produce.
+
///
+
/// Depends on CLI arguments given by the user.
+
#[derive(Clone, Default, Debug, Eq, PartialEq)]
+
pub enum Mode {
+
    #[default]
+
    Operation,
+
    #[allow(dead_code)]
+
    Id,
+
}
+

+
/// The selected issue operation returned by the operation
+
/// selection widget.
+
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
+
pub enum InboxOperation {
+
    Show,
+
    Clear,
+
}
+

+
impl Display for InboxOperation {
+
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+
        match self {
+
            InboxOperation::Show => {
+
                write!(f, "show")
+
            }
+
            InboxOperation::Clear => {
+
                write!(f, "clear")
+
            }
+
        }
+
    }
+
}
+

+
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
+
pub enum ListCid {
+
    NotificationBrowser,
+
    Context,
+
    Shortcuts,
+
}
+

+
/// All component ids known to this application.
+
#[derive(Debug, Default, Eq, PartialEq, Clone, Hash)]
+
pub enum Cid {
+
    List(ListCid),
+
    #[default]
+
    GlobalListener,
+
}
+

+
#[derive(Clone, Default, Debug, Eq, PartialEq)]
+
pub enum Message {
+
    #[default]
+
    Tick,
+
    Quit(Option<SelectionExit>),
+
    Batch(Vec<Message>),
+
}
+

+
pub struct App {
+
    context: Context,
+
    pages: PageStack<Cid, Message>,
+
    theme: Theme,
+
    quit: bool,
+
    filter: Filter,
+
    output: Option<SelectionExit>,
+
}
+

+
/// Creates a new application using a tui-realm-application, mounts all
+
/// components and sets focus to a default one.
+
#[allow(dead_code)]
+
impl App {
+
    pub fn new(context: Context, filter: Filter) -> Self {
+
        Self {
+
            context,
+
            pages: PageStack::default(),
+
            theme: Theme::default(),
+
            quit: false,
+
            filter,
+
            output: None,
+
        }
+
    }
+

+
    fn view_list(
+
        &mut self,
+
        app: &mut Application<Cid, Message, NoUserEvent>,
+
        theme: &Theme,
+
    ) -> Result<()> {
+
        let home = Box::new(ListView::new(self.filter.clone()));
+
        self.pages.push(home, app, &self.context, theme)?;
+

+
        Ok(())
+
    }
+

+
    fn process(
+
        &mut self,
+
        app: &mut Application<Cid, Message, NoUserEvent>,
+
        message: Message,
+
    ) -> Result<Option<Message>> {
+
        let theme = Theme::default();
+
        match message {
+
            Message::Batch(messages) => {
+
                let mut results = vec![];
+
                for message in messages {
+
                    if let Some(result) = self.process(app, message)? {
+
                        results.push(result);
+
                    }
+
                }
+
                match results.len() {
+
                    0 => Ok(None),
+
                    1 => Ok(Some(results[0].to_owned())),
+
                    _ => Ok(Some(Message::Batch(results))),
+
                }
+
            }
+
            Message::Quit(output) => {
+
                self.quit = true;
+
                self.output = output;
+
                Ok(None)
+
            }
+
            _ => self
+
                .pages
+
                .peek_mut()?
+
                .update(app, &self.context, &theme, message),
+
        }
+
    }
+
}
+

+
impl Tui<Cid, Message, SelectionExit> for App {
+
    fn init(&mut self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
+
        self.view_list(app, &self.theme.clone())?;
+

+
        // Add global key listener and subscribe to key events
+
        let global = tui::ui::global_listener().to_boxed();
+
        app.mount(
+
            Cid::GlobalListener,
+
            global,
+
            vec![Sub::new(
+
                subscription::quit_clause(tuirealm::event::Key::Char('q')),
+
                SubClause::Always,
+
            )],
+
        )?;
+

+
        Ok(())
+
    }
+

+
    fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, frame: &mut Frame) {
+
        if let Ok(page) = self.pages.peek_mut() {
+
            page.view(app, frame);
+
        }
+
    }
+

+
    fn update(&mut self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<bool> {
+
        match app.tick(PollStrategy::Once) {
+
            Ok(messages) if !messages.is_empty() => {
+
                for message in messages {
+
                    let mut msg = Some(message);
+
                    while msg.is_some() {
+
                        msg = self.process(app, msg.unwrap())?;
+
                    }
+
                }
+
                Ok(true)
+
            }
+
            _ => Ok(false),
+
        }
+
    }
+

+
    fn exit(&self) -> Option<Exit<SelectionExit>> {
+
        if self.quit {
+
            return Some(Exit {
+
                value: self.output.clone(),
+
            });
+
        }
+
        None
+
    }
+
}
added bin/commands/inbox/select/realm/event.rs
@@ -0,0 +1,161 @@
+
use radicle::node::notifications::NotificationId;
+

+
use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection};
+
use tuirealm::event::{Event, Key, KeyEvent};
+
use tuirealm::{MockComponent, NoUserEvent};
+

+
use radicle_tui as tui;
+

+
use tui::realm::ui::state::ItemState;
+
use tui::realm::ui::widget::container::{AppHeader, GlobalListener, LabeledContainer};
+
use tui::realm::ui::widget::context::{ContextBar, Shortcuts};
+
use tui::realm::ui::widget::list::PropertyList;
+
use tui::realm::ui::widget::Widget;
+
use tui::{Id, SelectionExit};
+

+
use super::ui::{IdSelect, OperationSelect};
+
use super::{InboxOperation, Message};
+

+
/// Since the framework does not know the type of messages that are being
+
/// passed around in the app, the following handlers need to be implemented for
+
/// each component used.
+
///
+
/// TODO: should handle `Event::WindowResize`, which is not emitted by `termion`.
+
impl tuirealm::Component<Message, NoUserEvent> for Widget<GlobalListener> {
+
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
+
        match event {
+
            Event::Keyboard(KeyEvent {
+
                code: Key::Char('q'),
+
                ..
+
            }) => Some(Message::Quit(None)),
+
            _ => None,
+
        }
+
    }
+
}
+

+
impl tuirealm::Component<Message, NoUserEvent> for Widget<IdSelect> {
+
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
+
        let mut submit = || -> Option<NotificationId> {
+
            match self.perform(Cmd::Submit) {
+
                CmdResult::Submit(state) => {
+
                    let selected = ItemState::try_from(state).ok()?.selected()?;
+
                    let item = self.items().get(selected)?;
+
                    Some(item.id().to_owned())
+
                }
+
                _ => None,
+
            }
+
        };
+

+
        match event {
+
            Event::Keyboard(KeyEvent { code: Key::Up, .. })
+
            | Event::Keyboard(KeyEvent {
+
                code: Key::Char('k'),
+
                ..
+
            }) => {
+
                self.perform(Cmd::Move(MoveDirection::Up));
+
                Some(Message::Tick)
+
            }
+
            Event::Keyboard(KeyEvent {
+
                code: Key::Down, ..
+
            })
+
            | Event::Keyboard(KeyEvent {
+
                code: Key::Char('j'),
+
                ..
+
            }) => {
+
                self.perform(Cmd::Move(MoveDirection::Down));
+
                Some(Message::Tick)
+
            }
+
            Event::Keyboard(KeyEvent {
+
                code: Key::Enter, ..
+
            }) => submit().map(|id| {
+
                let output = SelectionExit::default().with_id(Id::Notification(id));
+
                Message::Quit(Some(output))
+
            }),
+
            _ => None,
+
        }
+
    }
+
}
+

+
impl tuirealm::Component<Message, NoUserEvent> for Widget<OperationSelect> {
+
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
+
        let mut submit = || -> Option<NotificationId> {
+
            match self.perform(Cmd::Submit) {
+
                CmdResult::Submit(state) => {
+
                    let selected = ItemState::try_from(state).ok()?.selected()?;
+
                    let item = self.items().get(selected)?;
+
                    Some(item.id().to_owned())
+
                }
+
                _ => None,
+
            }
+
        };
+

+
        match event {
+
            Event::Keyboard(KeyEvent { code: Key::Up, .. })
+
            | Event::Keyboard(KeyEvent {
+
                code: Key::Char('k'),
+
                ..
+
            }) => {
+
                self.perform(Cmd::Move(MoveDirection::Up));
+
                Some(Message::Tick)
+
            }
+
            Event::Keyboard(KeyEvent {
+
                code: Key::Down, ..
+
            })
+
            | Event::Keyboard(KeyEvent {
+
                code: Key::Char('j'),
+
                ..
+
            }) => {
+
                self.perform(Cmd::Move(MoveDirection::Down));
+
                Some(Message::Tick)
+
            }
+
            Event::Keyboard(KeyEvent {
+
                code: Key::Enter, ..
+
            }) => submit().map(|id| {
+
                let exit = SelectionExit::default()
+
                    .with_operation(InboxOperation::Show.to_string())
+
                    .with_id(Id::Notification(id));
+
                Message::Quit(Some(exit))
+
            }),
+
            Event::Keyboard(KeyEvent {
+
                code: Key::Char('c'),
+
                ..
+
            }) => submit().map(|id| {
+
                let exit = SelectionExit::default()
+
                    .with_operation(InboxOperation::Clear.to_string())
+
                    .with_id(Id::Notification(id));
+
                Message::Quit(Some(exit))
+
            }),
+
            _ => None,
+
        }
+
    }
+
}
+

+
impl tuirealm::Component<Message, NoUserEvent> for Widget<AppHeader> {
+
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
+
        None
+
    }
+
}
+

+
impl tuirealm::Component<Message, NoUserEvent> for Widget<LabeledContainer> {
+
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
+
        None
+
    }
+
}
+

+
impl tuirealm::Component<Message, NoUserEvent> for Widget<PropertyList> {
+
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
+
        None
+
    }
+
}
+

+
impl tuirealm::Component<Message, NoUserEvent> for Widget<ContextBar> {
+
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
+
        None
+
    }
+
}
+

+
impl tuirealm::Component<Message, NoUserEvent> for Widget<Shortcuts> {
+
    fn on(&mut self, _event: Event<NoUserEvent>) -> Option<Message> {
+
        None
+
    }
+
}
added bin/commands/inbox/select/realm/page.rs
@@ -0,0 +1,168 @@
+
use std::collections::HashMap;
+

+
use anyhow::Result;
+

+
use tuirealm::{AttrValue, Attribute, Frame, NoUserEvent};
+

+
use radicle_tui as tui;
+

+
use tui::common::cob::inbox::{Filter, SortBy};
+
use tui::common::context::Context;
+
use tui::realm::ui::layout;
+
use tui::realm::ui::state::ItemState;
+
use tui::realm::ui::theme::Theme;
+
use tui::realm::ui::widget::context::{Progress, Shortcuts};
+
use tui::realm::ui::widget::Widget;
+
use tui::realm::ViewPage;
+

+
use super::{ui, Application, Cid, ListCid, Message, Mode};
+

+
///
+
/// Home
+
///
+
pub struct ListView {
+
    active_component: ListCid,
+
    mode: Mode,
+
    filter: Filter,
+
    sort_by: SortBy,
+
    shortcuts: HashMap<ListCid, Widget<Shortcuts>>,
+
}
+

+
impl ListView {
+
    pub fn new(mode: Mode, filter: Filter, sort_by: SortBy) -> Self {
+
        Self {
+
            active_component: ListCid::NotificationBrowser,
+
            mode,
+
            filter,
+
            sort_by,
+
            shortcuts: HashMap::default(),
+
        }
+
    }
+

+
    fn update_context(
+
        &self,
+
        app: &mut Application<Cid, Message, NoUserEvent>,
+
        context: &Context,
+
        theme: &Theme,
+
    ) -> Result<()> {
+
        let state = app.state(&Cid::List(ListCid::NotificationBrowser))?;
+
        let progress = match ItemState::try_from(state) {
+
            Ok(state) => Progress::Step(
+
                state
+
                    .selected()
+
                    .map(|s| s.saturating_add(1))
+
                    .unwrap_or_default(),
+
                state.len(),
+
            ),
+
            Err(_) => Progress::None,
+
        };
+

+
        let context = ui::browse_context(context, theme, self.filter.clone(), progress);
+

+
        app.remount(Cid::List(ListCid::Context), context.to_boxed(), vec![])?;
+

+
        Ok(())
+
    }
+

+
    fn update_shortcuts(
+
        &self,
+
        app: &mut Application<Cid, Message, NoUserEvent>,
+
        cid: ListCid,
+
    ) -> Result<()> {
+
        if let Some(shortcuts) = self.shortcuts.get(&cid) {
+
            app.remount(
+
                Cid::List(ListCid::Shortcuts),
+
                shortcuts.clone().to_boxed(),
+
                vec![],
+
            )?;
+
        }
+

+
        Ok(())
+
    }
+
}
+

+
impl ViewPage<Cid, Message> for ListView {
+
    fn mount(
+
        &mut self,
+
        app: &mut Application<Cid, Message, NoUserEvent>,
+
        context: &Context,
+
        theme: &Theme,
+
    ) -> Result<()> {
+
        let browser = ui::operation_select(theme, context, self.filter.clone(), self.sort_by, None)
+
            .to_boxed();
+
        self.shortcuts = browser.as_ref().shortcuts();
+

+
        match self.mode {
+
            Mode::Id => {
+
                let notif_browser =
+
                    ui::id_select(theme, context, self.filter.clone(), self.sort_by, None)
+
                        .to_boxed();
+
                self.shortcuts = notif_browser.as_ref().shortcuts();
+

+
                app.remount(Cid::List(ListCid::NotificationBrowser), browser, vec![])?;
+
            }
+
            Mode::Operation => {
+
                let notif_browser =
+
                    ui::operation_select(theme, context, self.filter.clone(), self.sort_by, None)
+
                        .to_boxed();
+
                self.shortcuts = notif_browser.as_ref().shortcuts();
+

+
                app.remount(Cid::List(ListCid::NotificationBrowser), browser, vec![])?;
+
            }
+
        };
+

+
        app.active(&Cid::List(self.active_component.clone()))?;
+
        self.update_shortcuts(app, self.active_component.clone())?;
+
        self.update_context(app, context, theme)?;
+

+
        Ok(())
+
    }
+

+
    fn unmount(&self, app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
+
        app.umount(&Cid::List(ListCid::NotificationBrowser))?;
+
        app.umount(&Cid::List(ListCid::Context))?;
+
        app.umount(&Cid::List(ListCid::Shortcuts))?;
+
        Ok(())
+
    }
+

+
    fn update(
+
        &mut self,
+
        app: &mut Application<Cid, Message, NoUserEvent>,
+
        context: &Context,
+
        theme: &Theme,
+
        _message: Message,
+
    ) -> Result<Option<Message>> {
+
        self.update_context(app, context, theme)?;
+

+
        Ok(None)
+
    }
+

+
    fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, frame: &mut Frame) {
+
        let area = frame.size();
+
        let context_h = app
+
            .query(&Cid::List(ListCid::Context), Attribute::Height)
+
            .unwrap_or_default()
+
            .unwrap_or(AttrValue::Size(0))
+
            .unwrap_size();
+
        let shortcuts_h = 1u16;
+

+
        let layout = layout::default_page(area, context_h, shortcuts_h);
+

+
        app.view(
+
            &Cid::List(self.active_component.clone()),
+
            frame,
+
            layout.component,
+
        );
+

+
        app.view(&Cid::List(ListCid::Context), frame, layout.context);
+
        app.view(&Cid::List(ListCid::Shortcuts), frame, layout.shortcuts);
+
    }
+

+
    fn subscribe(&self, _app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
+
        Ok(())
+
    }
+

+
    fn unsubscribe(&self, _app: &mut Application<Cid, Message, NoUserEvent>) -> Result<()> {
+
        Ok(())
+
    }
+
}
added bin/commands/inbox/select/realm/ui.rs
@@ -0,0 +1,267 @@
+
use std::collections::HashMap;
+

+
use radicle::node::notifications::Notification;
+

+
use tuirealm::command::{Cmd, CmdResult};
+
use tuirealm::tui::layout::Rect;
+
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
+

+
use radicle_tui as tui;
+

+
use tui::common::cob::inbox::{Filter, SortBy};
+
use tui::common::context::Context;
+
use tui::realm::ui::cob::NotificationItem;
+
use tui::realm::ui::theme::{style, Theme};
+
use tui::realm::ui::widget::context::{ContextBar, Progress, Shortcuts};
+
use tui::realm::ui::widget::label::{self};
+
use tui::realm::ui::widget::list::{ColumnWidth, Table};
+
use tui::realm::ui::widget::{Widget, WidgetComponent};
+

+
use super::ListCid;
+

+
pub struct NotificationBrowser {
+
    items: Vec<NotificationItem>,
+
    table: Widget<Table<NotificationItem, 7>>,
+
}
+

+
impl NotificationBrowser {
+
    pub fn new(
+
        theme: &Theme,
+
        context: &Context,
+
        sort_by: SortBy,
+
        selected: Option<Notification>,
+
    ) -> Self {
+
        let header = [
+
            label::header(""),
+
            label::header(" ● "),
+
            label::header("Type"),
+
            label::header("Summary"),
+
            label::header("ID"),
+
            label::header("Status"),
+
            label::header("Updated"),
+
        ];
+
        let widths = [
+
            ColumnWidth::Fixed(5),
+
            ColumnWidth::Fixed(3),
+
            ColumnWidth::Fixed(6),
+
            ColumnWidth::Grow,
+
            ColumnWidth::Fixed(15),
+
            ColumnWidth::Fixed(10),
+
            ColumnWidth::Fixed(18),
+
        ];
+
        
+
        let mut items = vec![];
+
        for notification in context.notifications() {
+
            if let Ok(item) =
+
                NotificationItem::try_from((context.repository(), notification.clone()))
+
            {
+
                items.push(item);
+
            }
+
        }
+

+
        match sort_by.field {
+
            "timestamp" => items.sort_by(|a, b| b.timestamp().cmp(a.timestamp())),
+
            "id" => items.sort_by(|a, b| b.id().cmp(a.id())),
+
            _ => {}
+
        }
+
        if sort_by.reverse {
+
            items.reverse();
+
        }
+

+
        let selected = match selected {
+
            Some(notif) => {
+
                Some(NotificationItem::try_from((context.repository(), notif.clone())).unwrap())
+
            }
+
            _ => items.first().cloned(),
+
        };
+

+
        let table = Widget::new(Table::new(&items, selected, header, widths, theme.clone()));
+

+
        Self { items, table }
+
    }
+

+
    pub fn items(&self) -> &Vec<NotificationItem> {
+
        &self.items
+
    }
+
}
+

+
impl WidgetComponent for NotificationBrowser {
+
    fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
+
        let focus = properties
+
            .get_or(Attribute::Focus, AttrValue::Flag(false))
+
            .unwrap_flag();
+

+
        self.table.attr(Attribute::Focus, AttrValue::Flag(focus));
+
        self.table.view(frame, area);
+
    }
+

+
    fn state(&self) -> State {
+
        self.table.state()
+
    }
+

+
    fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
+
        self.table.perform(cmd)
+
    }
+
}
+

+
pub struct IdSelect {
+
    theme: Theme,
+
    browser: Widget<NotificationBrowser>,
+
}
+

+
impl IdSelect {
+
    pub fn new(theme: Theme, browser: Widget<NotificationBrowser>) -> Self {
+
        Self { theme, browser }
+
    }
+

+
    pub fn items(&self) -> &Vec<NotificationItem> {
+
        self.browser.items()
+
    }
+

+
    pub fn shortcuts(&self) -> HashMap<ListCid, Widget<Shortcuts>> {
+
        [(
+
            ListCid::NotificationBrowser,
+
            tui::realm::ui::shortcuts(
+
                &self.theme,
+
                vec![
+
                    tui::realm::ui::shortcut(&self.theme, "enter", "select"),
+
                    tui::realm::ui::shortcut(&self.theme, "q", "quit"),
+
                ],
+
            ),
+
        )]
+
        .iter()
+
        .cloned()
+
        .collect()
+
    }
+
}
+

+
impl WidgetComponent for IdSelect {
+
    fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
+
        let focus = properties
+
            .get_or(Attribute::Focus, AttrValue::Flag(false))
+
            .unwrap_flag();
+

+
        self.browser.attr(Attribute::Focus, AttrValue::Flag(focus));
+
        self.browser.view(frame, area);
+
    }
+

+
    fn state(&self) -> State {
+
        self.browser.state()
+
    }
+

+
    fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
+
        self.browser.perform(cmd)
+
    }
+
}
+

+
pub struct OperationSelect {
+
    theme: Theme,
+
    browser: Widget<NotificationBrowser>,
+
}
+

+
impl OperationSelect {
+
    pub fn new(theme: Theme, browser: Widget<NotificationBrowser>) -> Self {
+
        Self { theme, browser }
+
    }
+

+
    pub fn items(&self) -> &Vec<NotificationItem> {
+
        self.browser.items()
+
    }
+

+
    pub fn shortcuts(&self) -> HashMap<ListCid, Widget<Shortcuts>> {
+
        [(
+
            ListCid::NotificationBrowser,
+
            tui::realm::ui::shortcuts(
+
                &self.theme,
+
                vec![
+
                    tui::realm::ui::shortcut(&self.theme, "enter", "show"),
+
                    tui::realm::ui::shortcut(&self.theme, "c", "clear"),
+
                    tui::realm::ui::shortcut(&self.theme, "q", "quit"),
+
                ],
+
            ),
+
        )]
+
        .iter()
+
        .cloned()
+
        .collect()
+
    }
+
}
+

+
impl WidgetComponent for OperationSelect {
+
    fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
+
        let focus = properties
+
            .get_or(Attribute::Focus, AttrValue::Flag(false))
+
            .unwrap_flag();
+

+
        self.browser.attr(Attribute::Focus, AttrValue::Flag(focus));
+
        self.browser.view(frame, area);
+
    }
+

+
    fn state(&self) -> State {
+
        self.browser.state()
+
    }
+

+
    fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
+
        self.browser.perform(cmd)
+
    }
+
}
+

+
pub fn id_select(
+
    theme: &Theme,
+
    context: &Context,
+
    _filter: Filter,
+
    sort_by: SortBy,
+
    selected: Option<Notification>,
+
) -> Widget<IdSelect> {
+
    let browser = Widget::new(NotificationBrowser::new(theme, context, sort_by, selected));
+

+
    Widget::new(IdSelect::new(theme.clone(), browser))
+
}
+

+
pub fn operation_select(
+
    theme: &Theme,
+
    context: &Context,
+
    _filter: Filter,
+
    sort_by: SortBy,
+
    selected: Option<Notification>,
+
) -> Widget<OperationSelect> {
+
    let browser = Widget::new(NotificationBrowser::new(theme, context, sort_by, selected));
+

+
    Widget::new(OperationSelect::new(theme.clone(), browser))
+
}
+

+
pub fn browse_context(
+
    _context: &Context,
+
    _theme: &Theme,
+
    _filter: Filter,
+
    progress: Progress,
+
) -> Widget<ContextBar> {
+
    let context = label::reversable("/").style(style::magenta_reversed());
+
    let filter = label::default("").style(style::magenta_dim());
+

+
    let progress = label::reversable(&progress.to_string()).style(style::magenta_reversed());
+

+
    let spacer = label::default("");
+
    let _divider = label::default(" | ");
+

+
    let context_bar = ContextBar::new(
+
        label::group(&[context]),
+
        label::group(&[filter]),
+
        label::group(&[spacer.clone()]),
+
        label::group(&[
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
            spacer.clone(),
+
        ]),
+
        label::group(&[progress]),
+
    );
+

+
    Widget::new(context_bar).height(1)
+
}
deleted bin/commands/inbox/select/ui.rs
@@ -1,267 +0,0 @@
-
use std::collections::HashMap;
-

-
use radicle::node::notifications::Notification;
-

-
use tuirealm::command::{Cmd, CmdResult};
-
use tuirealm::tui::layout::Rect;
-
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
-

-
use radicle_tui as tui;
-

-
use tui::common::cob::inbox::{Filter, SortBy};
-
use tui::common::context::Context;
-
use tui::realm::ui::cob::NotificationItem;
-
use tui::realm::ui::theme::{style, Theme};
-
use tui::realm::ui::widget::context::{ContextBar, Progress, Shortcuts};
-
use tui::realm::ui::widget::label::{self};
-
use tui::realm::ui::widget::list::{ColumnWidth, Table};
-
use tui::realm::ui::widget::{Widget, WidgetComponent};
-

-
use super::ListCid;
-

-
pub struct NotificationBrowser {
-
    items: Vec<NotificationItem>,
-
    table: Widget<Table<NotificationItem, 7>>,
-
}
-

-
impl NotificationBrowser {
-
    pub fn new(
-
        theme: &Theme,
-
        context: &Context,
-
        sort_by: SortBy,
-
        selected: Option<Notification>,
-
    ) -> Self {
-
        let header = [
-
            label::header(""),
-
            label::header(" ● "),
-
            label::header("Type"),
-
            label::header("Summary"),
-
            label::header("ID"),
-
            label::header("Status"),
-
            label::header("Updated"),
-
        ];
-
        let widths = [
-
            ColumnWidth::Fixed(5),
-
            ColumnWidth::Fixed(3),
-
            ColumnWidth::Fixed(6),
-
            ColumnWidth::Grow,
-
            ColumnWidth::Fixed(15),
-
            ColumnWidth::Fixed(10),
-
            ColumnWidth::Fixed(18),
-
        ];
-

-
        let mut items = vec![];
-
        for notification in context.notifications() {
-
            if let Ok(item) =
-
                NotificationItem::try_from((context.repository(), notification.clone()))
-
            {
-
                items.push(item);
-
            }
-
        }
-

-
        match sort_by.field {
-
            "timestamp" => items.sort_by(|a, b| b.timestamp().cmp(a.timestamp())),
-
            "id" => items.sort_by(|a, b| b.id().cmp(a.id())),
-
            _ => {}
-
        }
-
        if sort_by.reverse {
-
            items.reverse();
-
        }
-

-
        let selected = match selected {
-
            Some(notif) => {
-
                Some(NotificationItem::try_from((context.repository(), notif.clone())).unwrap())
-
            }
-
            _ => items.first().cloned(),
-
        };
-

-
        let table = Widget::new(Table::new(&items, selected, header, widths, theme.clone()));
-

-
        Self { items, table }
-
    }
-

-
    pub fn items(&self) -> &Vec<NotificationItem> {
-
        &self.items
-
    }
-
}
-

-
impl WidgetComponent for NotificationBrowser {
-
    fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
-
        let focus = properties
-
            .get_or(Attribute::Focus, AttrValue::Flag(false))
-
            .unwrap_flag();
-

-
        self.table.attr(Attribute::Focus, AttrValue::Flag(focus));
-
        self.table.view(frame, area);
-
    }
-

-
    fn state(&self) -> State {
-
        self.table.state()
-
    }
-

-
    fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
-
        self.table.perform(cmd)
-
    }
-
}
-

-
pub struct IdSelect {
-
    theme: Theme,
-
    browser: Widget<NotificationBrowser>,
-
}
-

-
impl IdSelect {
-
    pub fn new(theme: Theme, browser: Widget<NotificationBrowser>) -> Self {
-
        Self { theme, browser }
-
    }
-

-
    pub fn items(&self) -> &Vec<NotificationItem> {
-
        self.browser.items()
-
    }
-

-
    pub fn shortcuts(&self) -> HashMap<ListCid, Widget<Shortcuts>> {
-
        [(
-
            ListCid::NotificationBrowser,
-
            tui::realm::ui::shortcuts(
-
                &self.theme,
-
                vec![
-
                    tui::realm::ui::shortcut(&self.theme, "enter", "select"),
-
                    tui::realm::ui::shortcut(&self.theme, "q", "quit"),
-
                ],
-
            ),
-
        )]
-
        .iter()
-
        .cloned()
-
        .collect()
-
    }
-
}
-

-
impl WidgetComponent for IdSelect {
-
    fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
-
        let focus = properties
-
            .get_or(Attribute::Focus, AttrValue::Flag(false))
-
            .unwrap_flag();
-

-
        self.browser.attr(Attribute::Focus, AttrValue::Flag(focus));
-
        self.browser.view(frame, area);
-
    }
-

-
    fn state(&self) -> State {
-
        self.browser.state()
-
    }
-

-
    fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
-
        self.browser.perform(cmd)
-
    }
-
}
-

-
pub struct OperationSelect {
-
    theme: Theme,
-
    browser: Widget<NotificationBrowser>,
-
}
-

-
impl OperationSelect {
-
    pub fn new(theme: Theme, browser: Widget<NotificationBrowser>) -> Self {
-
        Self { theme, browser }
-
    }
-

-
    pub fn items(&self) -> &Vec<NotificationItem> {
-
        self.browser.items()
-
    }
-

-
    pub fn shortcuts(&self) -> HashMap<ListCid, Widget<Shortcuts>> {
-
        [(
-
            ListCid::NotificationBrowser,
-
            tui::realm::ui::shortcuts(
-
                &self.theme,
-
                vec![
-
                    tui::realm::ui::shortcut(&self.theme, "enter", "show"),
-
                    tui::realm::ui::shortcut(&self.theme, "c", "clear"),
-
                    tui::realm::ui::shortcut(&self.theme, "q", "quit"),
-
                ],
-
            ),
-
        )]
-
        .iter()
-
        .cloned()
-
        .collect()
-
    }
-
}
-

-
impl WidgetComponent for OperationSelect {
-
    fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) {
-
        let focus = properties
-
            .get_or(Attribute::Focus, AttrValue::Flag(false))
-
            .unwrap_flag();
-

-
        self.browser.attr(Attribute::Focus, AttrValue::Flag(focus));
-
        self.browser.view(frame, area);
-
    }
-

-
    fn state(&self) -> State {
-
        self.browser.state()
-
    }
-

-
    fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
-
        self.browser.perform(cmd)
-
    }
-
}
-

-
pub fn id_select(
-
    theme: &Theme,
-
    context: &Context,
-
    _filter: Filter,
-
    sort_by: SortBy,
-
    selected: Option<Notification>,
-
) -> Widget<IdSelect> {
-
    let browser = Widget::new(NotificationBrowser::new(theme, context, sort_by, selected));
-

-
    Widget::new(IdSelect::new(theme.clone(), browser))
-
}
-

-
pub fn operation_select(
-
    theme: &Theme,
-
    context: &Context,
-
    _filter: Filter,
-
    sort_by: SortBy,
-
    selected: Option<Notification>,
-
) -> Widget<OperationSelect> {
-
    let browser = Widget::new(NotificationBrowser::new(theme, context, sort_by, selected));
-

-
    Widget::new(OperationSelect::new(theme.clone(), browser))
-
}
-

-
pub fn browse_context(
-
    _context: &Context,
-
    _theme: &Theme,
-
    _filter: Filter,
-
    progress: Progress,
-
) -> Widget<ContextBar> {
-
    let context = label::reversable("/").style(style::magenta_reversed());
-
    let filter = label::default("").style(style::magenta_dim());
-

-
    let progress = label::reversable(&progress.to_string()).style(style::magenta_reversed());
-

-
    let spacer = label::default("");
-
    let _divider = label::default(" | ");
-

-
    let context_bar = ContextBar::new(
-
        label::group(&[context]),
-
        label::group(&[filter]),
-
        label::group(&[spacer.clone()]),
-
        label::group(&[
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
            spacer.clone(),
-
        ]),
-
        label::group(&[progress]),
-
    );
-

-
    Widget::new(context_bar).height(1)
-
}