refactor: Simplify library ui and widget modules

This commit is contained in:
Erik Kundt
2023-10-06 10:55:37 +02:00
parent e47a0401fa
commit f4eaf5c17e
17 changed files with 351 additions and 168 deletions
+12 -11
View File
@@ -9,16 +9,17 @@ use radicle::identity::{Id, Project};
use radicle::prelude::Signer;
use radicle::profile::Profile;
use radicle_tui::ui::subscription;
use radicle_tui::ui::widget;
use tuirealm::application::PollStrategy;
use tuirealm::{Application, Frame, NoUserEvent, Sub, SubClause};
use radicle_tui::cob;
use radicle_tui::ui::context::Context;
use radicle_tui::ui::theme::{self, Theme};
use radicle_tui::PageStack;
use radicle_tui::Tui;
use radicle_tui as tui;
use tui::cob;
use tui::ui::context::Context;
use tui::ui::subscription;
use tui::ui::theme::{self, Theme};
use tui::PageStack;
use tui::Tui;
use page::{IssuePage, ListPage};
@@ -235,7 +236,7 @@ impl App {
theme: &Theme,
message: &str,
) -> Result<()> {
let popup = widget::common::info(theme, message);
let popup = tui::ui::info(theme, message);
app.remount(Cid::Popup, popup.to_boxed(), vec![])?;
app.active(&Cid::Popup)?;
@@ -248,7 +249,7 @@ impl App {
theme: &Theme,
message: &str,
) -> Result<()> {
let popup = widget::common::warning(theme, message);
let popup = tui::ui::warning(theme, message);
app.remount(Cid::Popup, popup.to_boxed(), vec![])?;
app.active(&Cid::Popup)?;
@@ -261,7 +262,7 @@ impl App {
theme: &Theme,
message: &str,
) -> Result<()> {
let popup = widget::common::error(theme, message);
let popup = tui::ui::error(theme, message);
app.remount(Cid::Popup, popup.to_boxed(), vec![])?;
app.active(&Cid::Popup)?;
@@ -304,7 +305,7 @@ impl Tui<Cid, Message> for App {
self.view_list(app, &self.theme.clone())?;
// Add global key listener and subscribe to key events
let global = widget::common::global_listener().to_boxed();
let global = tui::ui::global_listener().to_boxed();
app.mount(
Cid::GlobalListener,
global,
+7 -7
View File
@@ -3,14 +3,14 @@ use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection, Position};
use tuirealm::event::{Event, Key, KeyEvent, KeyModifiers};
use tuirealm::{MockComponent, NoUserEvent, State, StateValue};
use radicle_tui::ui::widget::common::container::{
AppHeader, GlobalListener, LabeledContainer, Popup,
};
use radicle_tui::ui::widget::common::context::{ContextBar, Shortcuts};
use radicle_tui::ui::widget::common::form::Form;
use radicle_tui::ui::widget::common::list::PropertyList;
use radicle_tui as tui;
use radicle_tui::ui::widget::Widget;
use tui::ui::widget::container::{AppHeader, GlobalListener, LabeledContainer, Popup};
use tui::ui::widget::context::{ContextBar, Shortcuts};
use tui::ui::widget::form::Form;
use tui::ui::widget::list::PropertyList;
use tui::ui::widget::Widget;
use super::ui;
use super::{IssueCid, IssueMessage, Message, PopupMessage};
+32 -29
View File
@@ -3,15 +3,18 @@ use std::collections::HashMap;
use anyhow::Result;
use radicle::cob::issue::{Issue, IssueId};
use radicle_tui::cob;
use radicle_tui::ui::widget::common::context::{Progress, Shortcuts};
use tuirealm::{AttrValue, Attribute, Frame, NoUserEvent, State, StateValue, Sub, SubClause};
use radicle_tui::ui::context::Context;
use radicle_tui::ui::layout;
use radicle_tui::ui::theme::Theme;
use radicle_tui::ui::widget::{self, Widget};
use radicle_tui::ViewPage;
use radicle_tui as tui;
use tui::cob;
use tui::ui::context::Context;
use tui::ui::layout;
use tui::ui::theme::Theme;
use tui::ui::widget::context::{Progress, Shortcuts};
use tui::ui::widget::Widget;
use tui::ViewPage;
use super::{
Application, Cid, IssueCid, IssueCobMessage, IssueMessage, ListCid, Message, PopupMessage,
@@ -53,14 +56,14 @@ impl ListPage {
fn build_shortcuts(theme: &Theme) -> HashMap<ListCid, Widget<Shortcuts>> {
[(
ListCid::IssueBrowser,
widget::common::shortcuts(
tui::ui::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "tab", "section"),
widget::common::shortcut(theme, "↑/↓", "navigate"),
widget::common::shortcut(theme, "enter", "show"),
widget::common::shortcut(theme, "o", "open"),
widget::common::shortcut(theme, "q", "quit"),
tui::ui::shortcut(theme, "tab", "section"),
tui::ui::shortcut(theme, "↑/↓", "navigate"),
tui::ui::shortcut(theme, "enter", "show"),
tui::ui::shortcut(theme, "o", "open"),
tui::ui::shortcut(theme, "q", "quit"),
],
),
)]
@@ -112,7 +115,7 @@ impl ViewPage<Cid, Message> for ListPage {
theme: &Theme,
) -> Result<()> {
let navigation = ui::list_navigation(theme);
let header = widget::common::app_header(context, theme, Some(navigation)).to_boxed();
let header = tui::ui::app_header(context, theme, Some(navigation)).to_boxed();
let issue_browser = ui::issues(context, theme, None).to_boxed();
app.remount(Cid::List(ListCid::Header), header, vec![])?;
@@ -229,36 +232,36 @@ impl IssuePage {
[
(
IssueCid::List,
widget::common::shortcuts(
tui::ui::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "esc", "back"),
widget::common::shortcut(theme, "↑/↓", "navigate"),
widget::common::shortcut(theme, "enter", "show"),
widget::common::shortcut(theme, "o", "open"),
widget::common::shortcut(theme, "q", "quit"),
tui::ui::shortcut(theme, "esc", "back"),
tui::ui::shortcut(theme, "↑/↓", "navigate"),
tui::ui::shortcut(theme, "enter", "show"),
tui::ui::shortcut(theme, "o", "open"),
tui::ui::shortcut(theme, "q", "quit"),
],
),
),
(
IssueCid::Details,
widget::common::shortcuts(
tui::ui::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "esc", "back"),
widget::common::shortcut(theme, "↑/↓", "scroll"),
widget::common::shortcut(theme, "q", "quit"),
tui::ui::shortcut(theme, "esc", "back"),
tui::ui::shortcut(theme, "↑/↓", "scroll"),
tui::ui::shortcut(theme, "q", "quit"),
],
),
),
(
IssueCid::Form,
widget::common::shortcuts(
tui::ui::shortcuts(
theme,
vec![
widget::common::shortcut(theme, "esc", "back"),
widget::common::shortcut(theme, "shift + tab / tab", "navigate"),
widget::common::shortcut(theme, "ctrl + s", "submit"),
tui::ui::shortcut(theme, "esc", "back"),
tui::ui::shortcut(theme, "shift + tab / tab", "navigate"),
tui::ui::shortcut(theme, "ctrl + s", "submit"),
],
),
),
@@ -334,7 +337,7 @@ impl ViewPage<Cid, Message> for IssuePage {
theme: &Theme,
) -> Result<()> {
let navigation = ui::list_navigation(theme);
let header = widget::common::app_header(context, theme, Some(navigation)).to_boxed();
let header = tui::ui::app_header(context, theme, Some(navigation)).to_boxed();
let list = ui::list(context, theme, self.issue.clone()).to_boxed();
app.remount(Cid::Issue(IssueCid::Header), header, vec![])?;
+40 -39
View File
@@ -8,18 +8,19 @@ use tuirealm::command::{Cmd, CmdResult};
use tuirealm::tui::layout::{Constraint, Direction, Layout, Rect};
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State};
use radicle_tui::ui::cob;
use radicle_tui::ui::cob::IssueItem;
use radicle_tui::ui::context::Context;
use radicle_tui::ui::theme::Theme;
use radicle_tui::ui::widget::common;
use radicle_tui::ui::widget::{Widget, WidgetComponent};
use radicle_tui as tui;
use common::container::{Container, Tabs};
use common::context::{ContextBar, Progress};
use common::form::{Form, TextArea, TextField};
use common::label::Textarea;
use common::list::{ColumnWidth, List, Property, Table};
use tui::ui::cob;
use tui::ui::cob::IssueItem;
use tui::ui::context::Context;
use tui::ui::theme::Theme;
use tui::ui::widget::{Widget, WidgetComponent};
use tui::ui::widget::container::{Container, Tabs};
use tui::ui::widget::context::{ContextBar, Progress};
use tui::ui::widget::form::{Form, TextArea, TextField};
use tui::ui::widget::label::Textarea;
use tui::ui::widget::list::{ColumnWidth, List, Property, Table};
pub const FORM_ID_EDIT: &str = "edit-form";
@@ -31,13 +32,13 @@ pub struct IssueBrowser {
impl IssueBrowser {
pub fn new(context: &Context, theme: &Theme, selected: Option<(IssueId, Issue)>) -> Self {
let header = [
common::label(" ● "),
common::label("ID"),
common::label("Title"),
common::label("Author"),
common::label("Tags"),
common::label("Assignees"),
common::label("Opened"),
tui::ui::label(" ● "),
tui::ui::label("ID"),
tui::ui::label("Title"),
tui::ui::label("Author"),
tui::ui::label("Tags"),
tui::ui::label("Assignees"),
tui::ui::label("Opened"),
];
let widths = [
@@ -121,7 +122,7 @@ impl LargeList {
let list = Widget::new(List::new(&items, selected, theme.clone()))
.highlight(theme.colors.item_list_highlighted_bg);
let container = common::container(theme, list.to_boxed());
let container = tui::ui::container(theme, list.to_boxed());
Self {
items,
@@ -166,30 +167,30 @@ impl IssueHeader {
let item = IssueItem::from((context.profile(), repo, id, issue.clone()));
let title = Property::new(
common::label("Title").foreground(theme.colors.property_name_fg),
common::label(item.title()).foreground(theme.colors.browser_list_title),
tui::ui::label("Title").foreground(theme.colors.property_name_fg),
tui::ui::label(item.title()).foreground(theme.colors.browser_list_title),
);
let author = Property::new(
common::label("Author").foreground(theme.colors.property_name_fg),
common::label(&cob::format_author(issue.author().id(), by_you))
tui::ui::label("Author").foreground(theme.colors.property_name_fg),
tui::ui::label(&cob::format_author(issue.author().id(), by_you))
.foreground(theme.colors.browser_list_author),
);
let issue_id = Property::new(
common::label("Issue").foreground(theme.colors.property_name_fg),
common::label(&id.to_string()).foreground(theme.colors.browser_list_description),
tui::ui::label("Issue").foreground(theme.colors.property_name_fg),
tui::ui::label(&id.to_string()).foreground(theme.colors.browser_list_description),
);
let labels = Property::new(
common::label("Labels").foreground(theme.colors.property_name_fg),
common::label(&cob::format_labels(item.labels()))
tui::ui::label("Labels").foreground(theme.colors.property_name_fg),
tui::ui::label(&cob::format_labels(item.labels()))
.foreground(theme.colors.browser_list_labels),
);
let assignees = Property::new(
common::label("Assignees").foreground(theme.colors.property_name_fg),
common::label(&cob::format_assignees(
tui::ui::label("Assignees").foreground(theme.colors.property_name_fg),
tui::ui::label(&cob::format_assignees(
&item
.assignees()
.iter()
@@ -200,11 +201,11 @@ impl IssueHeader {
);
let state = Property::new(
common::label("Status").foreground(theme.colors.property_name_fg),
common::label(&item.state().to_string()).foreground(theme.colors.browser_list_title),
tui::ui::label("Status").foreground(theme.colors.property_name_fg),
tui::ui::label(&item.state().to_string()).foreground(theme.colors.browser_list_title),
);
let table = common::property_table(
let table = tui::ui::property_table(
theme,
vec![
Widget::new(title),
@@ -215,7 +216,7 @@ impl IssueHeader {
Widget::new(state),
],
);
let container = common::container(theme, table.to_boxed());
let container = tui::ui::container(theme, table.to_boxed());
Self { container }
}
@@ -294,7 +295,7 @@ impl CommentBody {
.content(AttrValue::String(content))
.foreground(theme.colors.default_fg);
let textarea = common::container(theme, textarea.to_boxed());
let textarea = tui::ui::container(theme, textarea.to_boxed());
Self { textarea }
}
@@ -320,9 +321,9 @@ impl WidgetComponent for CommentBody {
}
pub fn list_navigation(theme: &Theme) -> Widget<Tabs> {
common::tabs(
tui::ui::tabs(
theme,
vec![common::reversable_label("Issues").foreground(theme.colors.tabs_highlighted_fg)],
vec![tui::ui::reversable_label("Issues").foreground(theme.colors.tabs_highlighted_fg)],
)
}
@@ -403,7 +404,7 @@ pub fn browse_context(context: &Context, theme: &Theme, progress: Progress) -> W
.collect::<Vec<_>>()
.len();
common::context::bar(
tui::ui::widget::context::bar(
theme,
"Browse",
"",
@@ -418,11 +419,11 @@ pub fn description_context(
theme: &Theme,
progress: Progress,
) -> Widget<ContextBar> {
common::context::bar(theme, "Show", "", "", "", &progress.to_string())
tui::ui::widget::context::bar(theme, "Show", "", "", "", &progress.to_string())
}
pub fn form_context(_context: &Context, theme: &Theme, progress: Progress) -> Widget<ContextBar> {
common::context::bar(theme, "Open", "", "", "", &progress.to_string())
tui::ui::widget::context::bar(theme, "Open", "", "", "", &progress.to_string())
.custom(ContextBar::PROP_EDIT_MODE, AttrValue::Flag(true))
}