tui: Introduce subscription module
Signed-off-by: Erik Kundt <erik@zirkular.io>
This commit is contained in:
parent
594b63197c
commit
52222939ae
|
|
@ -5,13 +5,10 @@ use anyhow::Result;
|
||||||
use tui_realm_stdlib::Phantom;
|
use tui_realm_stdlib::Phantom;
|
||||||
use tuirealm::application::PollStrategy;
|
use tuirealm::application::PollStrategy;
|
||||||
use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection};
|
use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection};
|
||||||
use tuirealm::event::{Event, Key, KeyEvent, KeyModifiers};
|
use tuirealm::event::{Event, Key, KeyEvent};
|
||||||
use tuirealm::props::{AttrValue, Attribute};
|
use tuirealm::props::{AttrValue, Attribute};
|
||||||
use tuirealm::tui::layout::{Constraint, Direction, Layout};
|
use tuirealm::tui::layout::{Constraint, Direction, Layout};
|
||||||
use tuirealm::{
|
use tuirealm::{Application, Component, Frame, MockComponent, NoUserEvent, State, StateValue};
|
||||||
Application, Component, Frame, MockComponent, NoUserEvent, State, StateValue, Sub, SubClause,
|
|
||||||
SubEventClause,
|
|
||||||
};
|
|
||||||
|
|
||||||
use radicle_tui::cob::patch::{self};
|
use radicle_tui::cob::patch::{self};
|
||||||
|
|
||||||
|
|
@ -23,6 +20,8 @@ use radicle_tui::ui::components::workspace::Browser;
|
||||||
use radicle_tui::ui::theme;
|
use radicle_tui::ui::theme;
|
||||||
use radicle_tui::ui::widget::Widget;
|
use radicle_tui::ui::widget::Widget;
|
||||||
|
|
||||||
|
use radicle_tui::subs;
|
||||||
|
|
||||||
use radicle_tui::Tui;
|
use radicle_tui::Tui;
|
||||||
|
|
||||||
use radicle::cob::patch::{Patch, PatchId};
|
use radicle::cob::patch::{Patch, PatchId};
|
||||||
|
|
@ -83,6 +82,8 @@ impl Tui<ComponentId, Message> for App {
|
||||||
let issue_browser = Box::<Phantom>::default();
|
let issue_browser = Box::<Phantom>::default();
|
||||||
let patch_browser = ui::patch_browser(&theme, &self.patches, &self.profile).to_boxed();
|
let patch_browser = ui::patch_browser(&theme, &self.patches, &self.profile).to_boxed();
|
||||||
|
|
||||||
|
let global_listener = ui::global_listener().to_boxed();
|
||||||
|
|
||||||
let shortcuts = ui::shortcuts(
|
let shortcuts = ui::shortcuts(
|
||||||
&theme,
|
&theme,
|
||||||
vec![
|
vec![
|
||||||
|
|
@ -95,19 +96,7 @@ impl Tui<ComponentId, Message> for App {
|
||||||
app.mount(
|
app.mount(
|
||||||
ComponentId::Navigation,
|
ComponentId::Navigation,
|
||||||
navigation,
|
navigation,
|
||||||
vec![Sub::new(
|
vec![subs::navigation()],
|
||||||
SubEventClause::Keyboard(KeyEvent {
|
|
||||||
code: Key::Tab,
|
|
||||||
modifiers: KeyModifiers::NONE,
|
|
||||||
}),
|
|
||||||
SubClause::and(
|
|
||||||
SubClause::IsMounted(ComponentId::Dashboard),
|
|
||||||
SubClause::and(
|
|
||||||
SubClause::IsMounted(ComponentId::IssueBrowser),
|
|
||||||
SubClause::IsMounted(ComponentId::PatchBrowser),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)],
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
app.mount(ComponentId::Dashboard, dashboard, vec![])?;
|
app.mount(ComponentId::Dashboard, dashboard, vec![])?;
|
||||||
|
|
@ -119,14 +108,8 @@ impl Tui<ComponentId, Message> for App {
|
||||||
// Add global key listener and subscribe to key events
|
// Add global key listener and subscribe to key events
|
||||||
app.mount(
|
app.mount(
|
||||||
ComponentId::GlobalListener,
|
ComponentId::GlobalListener,
|
||||||
ui::global_listener().to_boxed(),
|
global_listener,
|
||||||
vec![Sub::new(
|
vec![subs::global()],
|
||||||
SubEventClause::Keyboard(KeyEvent {
|
|
||||||
code: Key::Char('q'),
|
|
||||||
modifiers: KeyModifiers::NONE,
|
|
||||||
}),
|
|
||||||
SubClause::Always,
|
|
||||||
)],
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// We need to give focus to a component then
|
// We need to give focus to a component then
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use tuirealm::Frame;
|
||||||
use tuirealm::{Application, EventListenerCfg, NoUserEvent};
|
use tuirealm::{Application, EventListenerCfg, NoUserEvent};
|
||||||
|
|
||||||
pub mod cob;
|
pub mod cob;
|
||||||
|
pub mod subs;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
|
||||||
/// Trait that must be implemented by client applications in order to be run
|
/// Trait that must be implemented by client applications in order to be run
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
use tuirealm::event::{Key, KeyEvent, KeyModifiers};
|
||||||
|
use tuirealm::{Sub, SubClause, SubEventClause};
|
||||||
|
|
||||||
|
pub fn navigation<Id, UserEvent>() -> Sub<Id, UserEvent>
|
||||||
|
where
|
||||||
|
Id: Clone + Hash + Eq + PartialEq,
|
||||||
|
UserEvent: Clone + Eq + PartialEq + PartialOrd,
|
||||||
|
{
|
||||||
|
Sub::new(
|
||||||
|
SubEventClause::Keyboard(KeyEvent {
|
||||||
|
code: Key::Tab,
|
||||||
|
modifiers: KeyModifiers::NONE,
|
||||||
|
}),
|
||||||
|
SubClause::Always,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn global<Id, UserEvent>() -> Sub<Id, UserEvent>
|
||||||
|
where
|
||||||
|
Id: Clone + Hash + Eq + PartialEq,
|
||||||
|
UserEvent: Clone + Eq + PartialEq + PartialOrd,
|
||||||
|
{
|
||||||
|
Sub::new(
|
||||||
|
SubEventClause::Keyboard(KeyEvent {
|
||||||
|
code: Key::Char('q'),
|
||||||
|
modifiers: KeyModifiers::NONE,
|
||||||
|
}),
|
||||||
|
SubClause::Always,
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue