Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
patch: Move browser to common module
Erik Kundt committed 2 years ago
commit 19d7e3b0380ca1d545d36c377847b950a31e8fea
parent 2526dc47886e569f10a795cd6770d591c2d2c7ad
7 files changed +109 -170
modified bin/commands/patch.rs
@@ -1,3 +1,5 @@
+
#[path = "patch/common.rs"]
+
mod common;
#[path = "patch/select.rs"]
mod select;
#[path = "patch/suite.rs"]
added bin/commands/patch/common.rs
@@ -0,0 +1,2 @@
+
#[path = "common/ui.rs"]
+
pub mod ui;
added bin/commands/patch/common/ui.rs
@@ -0,0 +1,93 @@
+
use radicle::cob::patch::{Patch, PatchId};
+

+
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::context::Context;
+
use tui::ui::cob::PatchItem;
+
use tui::ui::theme::Theme;
+
use tui::ui::widget::{Widget, WidgetComponent};
+

+
use tui::ui::widget::label::{self};
+
use tui::ui::widget::list::{ColumnWidth, Table};
+

+
pub struct PatchBrowser {
+
    items: Vec<PatchItem>,
+
    table: Widget<Table<PatchItem, 8>>,
+
}
+

+
impl PatchBrowser {
+
    pub fn new(context: &Context, theme: &Theme, selected: Option<(PatchId, Patch)>) -> Self {
+
        let header = [
+
            label::header(" ● "),
+
            label::header("ID"),
+
            label::header("Title"),
+
            label::header("Author"),
+
            label::header("Head"),
+
            label::header("+"),
+
            label::header("-"),
+
            label::header("Updated"),
+
        ];
+

+
        let widths = [
+
            ColumnWidth::Fixed(3),
+
            ColumnWidth::Fixed(7),
+
            ColumnWidth::Grow,
+
            ColumnWidth::Fixed(21),
+
            ColumnWidth::Fixed(7),
+
            ColumnWidth::Fixed(4),
+
            ColumnWidth::Fixed(4),
+
            ColumnWidth::Fixed(18),
+
        ];
+

+
        let repo = context.repository();
+
        let patches = context.patches().as_ref().unwrap();
+
        let mut items = vec![];
+

+
        for (id, patch) in patches {
+
            if let Ok(item) = PatchItem::try_from((context.profile(), repo, *id, patch.clone())) {
+
                items.push(item);
+
            }
+
        }
+

+
        items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
+
        items.sort_by(|a, b| a.state().cmp(b.state()));
+

+
        let selected = match selected {
+
            Some((id, patch)) => {
+
                Some(PatchItem::try_from((context.profile(), repo, id, patch)).unwrap())
+
            }
+
            _ => items.first().cloned(),
+
        };
+

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

+
        Self { items, table }
+
    }
+

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

+
impl WidgetComponent for PatchBrowser {
+
    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)
+
    }
+
}
modified bin/commands/patch/list/event.rs
@@ -10,7 +10,8 @@ use tui::ui::widget::list::PropertyList;

use tui::ui::widget::Widget;

-
use super::{ui, Message, PopupMessage};
+
use super::super::common;
+
use super::{Message, PopupMessage};

/// 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
@@ -26,7 +27,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<GlobalListener> {
    }
}

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<ui::PatchBrowser> {
+
impl tuirealm::Component<Message, NoUserEvent> for Widget<common::ui::PatchBrowser> {
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
        match event {
            Event::Keyboard(KeyEvent { code: Key::Up, .. })
modified bin/commands/patch/list/ui.rs
@@ -1,98 +1,16 @@
use radicle::cob::patch::{Patch, PatchId};

-
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::context::Context;
-
use tui::ui::cob::PatchItem;
use tui::ui::theme::{style, Theme};
-
use tui::ui::widget::{Widget, WidgetComponent};
+
use tui::ui::widget::Widget;

use tui::ui::widget::container::Tabs;
use tui::ui::widget::context::{ContextBar, Progress};
use tui::ui::widget::label::{self};
-
use tui::ui::widget::list::{ColumnWidth, Table};
-

-
pub struct PatchBrowser {
-
    items: Vec<PatchItem>,
-
    table: Widget<Table<PatchItem, 8>>,
-
}
-

-
impl PatchBrowser {
-
    pub fn new(context: &Context, theme: &Theme, selected: Option<(PatchId, Patch)>) -> Self {
-
        let header = [
-
            label::header(" ● "),
-
            label::header("ID"),
-
            label::header("Title"),
-
            label::header("Author"),
-
            label::header("Head"),
-
            label::header("+"),
-
            label::header("-"),
-
            label::header("Updated"),
-
        ];
-

-
        let widths = [
-
            ColumnWidth::Fixed(3),
-
            ColumnWidth::Fixed(7),
-
            ColumnWidth::Grow,
-
            ColumnWidth::Fixed(21),
-
            ColumnWidth::Fixed(7),
-
            ColumnWidth::Fixed(4),
-
            ColumnWidth::Fixed(4),
-
            ColumnWidth::Fixed(18),
-
        ];
-

-
        let repo = context.repository();
-
        let patches = context.patches().as_ref().unwrap();
-
        let mut items = vec![];
-

-
        for (id, patch) in patches {
-
            if let Ok(item) = PatchItem::try_from((context.profile(), repo, *id, patch.clone())) {
-
                items.push(item);
-
            }
-
        }
-

-
        items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
-
        items.sort_by(|a, b| a.state().cmp(b.state()));
-

-
        let selected = match selected {
-
            Some((id, patch)) => {
-
                Some(PatchItem::try_from((context.profile(), repo, id, patch)).unwrap())
-
            }
-
            _ => items.first().cloned(),
-
        };
-

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

-
        Self { items, table }
-
    }

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

-
impl WidgetComponent for PatchBrowser {
-
    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)
-
    }
-
}
+
use super::super::common;

pub fn list_navigation(theme: &Theme) -> Widget<Tabs> {
    tui::ui::tabs(
@@ -105,8 +23,8 @@ pub fn patches(
    context: &Context,
    theme: &Theme,
    selected: Option<(PatchId, Patch)>,
-
) -> Widget<PatchBrowser> {
-
    Widget::new(PatchBrowser::new(context, theme, selected))
+
) -> Widget<common::ui::PatchBrowser> {
+
    Widget::new(common::ui::PatchBrowser::new(context, theme, selected))
}

pub fn browse_context(context: &Context, _theme: &Theme, progress: Progress) -> Widget<ContextBar> {
modified bin/commands/patch/suite/event.rs
@@ -8,6 +8,7 @@ use radicle_tui::ui::widget::list::PropertyList;

use radicle_tui::ui::widget::Widget;

+
use super::super::common;
use super::{ui, Message, PatchMessage, PopupMessage};

/// Since the framework does not know the type of messages that are being
@@ -43,7 +44,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<AppHeader> {
    }
}

-
impl tuirealm::Component<Message, NoUserEvent> for Widget<ui::PatchBrowser> {
+
impl tuirealm::Component<Message, NoUserEvent> for Widget<common::ui::PatchBrowser> {
    fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
        match event {
            Event::Keyboard(KeyEvent { code: Key::Up, .. })
modified bin/commands/patch/suite/ui.rs
@@ -9,7 +9,6 @@ use radicle_tui as tui;

use tui::context::Context;
use tui::ui::cob;
-
use tui::ui::cob::PatchItem;
use tui::ui::layout;
use tui::ui::theme::{style, Theme};
use tui::ui::widget::{Widget, WidgetComponent};
@@ -17,85 +16,8 @@ use tui::ui::widget::{Widget, WidgetComponent};
use tui::ui::widget::container::Tabs;
use tui::ui::widget::context::{ContextBar, Progress};
use tui::ui::widget::label::{self, Label};
-
use tui::ui::widget::list::{ColumnWidth, Table};

-
pub struct PatchBrowser {
-
    items: Vec<PatchItem>,
-
    table: Widget<Table<PatchItem, 8>>,
-
}
-

-
impl PatchBrowser {
-
    pub fn new(context: &Context, theme: &Theme, selected: Option<(PatchId, Patch)>) -> Self {
-
        let header = [
-
            label::header(" ● "),
-
            label::header("ID"),
-
            label::header("Title"),
-
            label::header("Author"),
-
            label::header("Head"),
-
            label::header("+"),
-
            label::header("-"),
-
            label::header("Updated"),
-
        ];
-

-
        let widths = [
-
            ColumnWidth::Fixed(3),
-
            ColumnWidth::Fixed(7),
-
            ColumnWidth::Grow,
-
            ColumnWidth::Fixed(21),
-
            ColumnWidth::Fixed(7),
-
            ColumnWidth::Fixed(4),
-
            ColumnWidth::Fixed(4),
-
            ColumnWidth::Fixed(18),
-
        ];
-

-
        let repo = context.repository();
-
        let mut items = vec![];
-
        let patches = context.patches().as_ref().unwrap();
-

-
        for (id, patch) in patches {
-
            if let Ok(item) = PatchItem::try_from((context.profile(), repo, *id, patch.clone())) {
-
                items.push(item);
-
            }
-
        }
-

-
        items.sort_by(|a, b| b.timestamp().cmp(a.timestamp()));
-
        items.sort_by(|a, b| a.state().cmp(b.state()));
-

-
        let selected = match selected {
-
            Some((id, patch)) => {
-
                Some(PatchItem::try_from((context.profile(), repo, id, patch)).unwrap())
-
            }
-
            _ => items.first().cloned(),
-
        };
-

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

-
        Self { items, table }
-
    }
-

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

-
impl WidgetComponent for PatchBrowser {
-
    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)
-
    }
-
}
+
use super::super::common;

pub struct Activity {
    label: Widget<Label>,
@@ -180,8 +102,8 @@ pub fn patches(
    context: &Context,
    theme: &Theme,
    selected: Option<(PatchId, Patch)>,
-
) -> Widget<PatchBrowser> {
-
    Widget::new(PatchBrowser::new(context, theme, selected))
+
) -> Widget<common::ui::PatchBrowser> {
+
    Widget::new(common::ui::PatchBrowser::new(context, theme, selected))
}

pub fn activity(_theme: &Theme) -> Widget<Activity> {