From 8e752468d11c1045a896c57515392e5343405a4c Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Thu, 4 Apr 2024 15:58:05 +0200 Subject: [PATCH] lib: Remove legacy tui-realm framework --- Cargo.lock | 181 +------- Cargo.toml | 11 +- src/{common => }/cob.rs | 0 src/{common => }/cob/inbox.rs | 0 src/{common => }/cob/issue.rs | 0 src/{common => }/cob/patch.rs | 0 src/common.rs | 3 - src/{common => }/context.rs | 0 src/{flux => }/event.rs | 0 src/flux.rs | 6 - src/{flux => }/git.rs | 0 src/lib.rs | 18 +- src/{common => }/log.rs | 0 src/realm.rs | 211 --------- src/realm/ui.rs | 164 ------- src/realm/ui/cob.rs | 615 -------------------------- src/realm/ui/cob/format.rs | 27 -- src/realm/ui/ext.rs | 113 ----- src/realm/ui/layout.rs | 278 ------------ src/realm/ui/state.rs | 163 ------- src/realm/ui/subscription.rs | 22 - src/realm/ui/theme.rs | 147 ------ src/realm/ui/widget.rs | 102 ----- src/realm/ui/widget/common.rs | 186 -------- src/realm/ui/widget/container.rs | 484 -------------------- src/realm/ui/widget/context.rs | 233 ---------- src/realm/ui/widget/form.rs | 268 ----------- src/realm/ui/widget/label.rs | 352 --------------- src/realm/ui/widget/list.rs | 375 ---------------- src/realm/ui/widget/utils.rs | 43 -- src/{flux => }/store.rs | 0 src/{flux => }/task.rs | 0 src/{flux => }/terminal.rs | 0 src/{flux => }/ui.rs | 0 src/{flux => }/ui/ext.rs | 0 src/{flux => }/ui/format.rs | 0 src/{flux => }/ui/items.rs | 0 src/{flux => }/ui/layout.rs | 0 src/{flux => }/ui/span.rs | 2 +- src/{flux => }/ui/theme.rs | 0 src/{flux => }/ui/widget.rs | 0 src/{flux => }/ui/widget/container.rs | 4 +- src/{flux => }/ui/widget/input.rs | 0 src/{flux => }/ui/widget/text.rs | 2 +- 44 files changed, 20 insertions(+), 3990 deletions(-) rename src/{common => }/cob.rs (100%) rename src/{common => }/cob/inbox.rs (100%) rename src/{common => }/cob/issue.rs (100%) rename src/{common => }/cob/patch.rs (100%) delete mode 100644 src/common.rs rename src/{common => }/context.rs (100%) rename src/{flux => }/event.rs (100%) delete mode 100644 src/flux.rs rename src/{flux => }/git.rs (100%) rename src/{common => }/log.rs (100%) delete mode 100644 src/realm.rs delete mode 100644 src/realm/ui.rs delete mode 100644 src/realm/ui/cob.rs delete mode 100644 src/realm/ui/cob/format.rs delete mode 100644 src/realm/ui/ext.rs delete mode 100644 src/realm/ui/layout.rs delete mode 100644 src/realm/ui/state.rs delete mode 100644 src/realm/ui/subscription.rs delete mode 100644 src/realm/ui/theme.rs delete mode 100644 src/realm/ui/widget.rs delete mode 100644 src/realm/ui/widget/common.rs delete mode 100644 src/realm/ui/widget/container.rs delete mode 100644 src/realm/ui/widget/context.rs delete mode 100644 src/realm/ui/widget/form.rs delete mode 100644 src/realm/ui/widget/label.rs delete mode 100644 src/realm/ui/widget/list.rs delete mode 100644 src/realm/ui/widget/utils.rs rename src/{flux => }/store.rs (100%) rename src/{flux => }/task.rs (100%) rename src/{flux => }/terminal.rs (100%) rename src/{flux => }/ui.rs (100%) rename src/{flux => }/ui/ext.rs (100%) rename src/{flux => }/ui/format.rs (100%) rename src/{flux => }/ui/items.rs (100%) rename src/{flux => }/ui/layout.rs (100%) rename src/{flux => }/ui/span.rs (98%) rename src/{flux => }/ui/theme.rs (100%) rename src/{flux => }/ui/widget.rs (100%) rename src/{flux => }/ui/widget/container.rs (97%) rename src/{flux => }/ui/widget/input.rs (100%) rename src/{flux => }/ui/widget/text.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 96efb365..d3ed0190 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,15 +64,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "aho-corasick" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" -dependencies = [ - "memchr", -] - [[package]] name = "allocator-api2" version = "0.2.16" @@ -914,15 +905,6 @@ dependencies = [ "phf", ] -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.12.1" @@ -965,29 +947,6 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "lazy-regex" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57451d19ad5e289ff6c3d69c2a2424652995c42b79dafa11e9c4d5508c913c01" -dependencies = [ - "lazy-regex-proc_macros", - "once_cell", - "regex", -] - -[[package]] -name = "lazy-regex-proc_macros" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0a1d9139f0ee2e862e08a9c5d0ba0470f2aa21cd1e1aa1b1562f83116c725f" -dependencies = [ - "proc-macro2", - "quote", - "regex", - "syn 2.0.48", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -1655,7 +1614,7 @@ dependencies = [ "radicle", "radicle-surf", "radicle-term", - "ratatui 0.26.1", + "ratatui", "serde", "serde_json", "signal-hook", @@ -1666,8 +1625,6 @@ dependencies = [ "timeago", "tokio", "tokio-stream", - "tui-realm-stdlib", - "tuirealm", ] [[package]] @@ -1699,23 +1656,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "ratatui" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e2e4cd95294a85c3b4446e63ef054eea43e0205b1fd60120c16b74ff7ff96ad" -dependencies = [ - "bitflags 2.4.1", - "cassowary", - "indoc", - "itertools 0.11.0", - "paste", - "strum 0.25.0", - "termion 2.0.1", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "ratatui" version = "0.26.1" @@ -1726,11 +1666,11 @@ dependencies = [ "cassowary", "compact_str", "indoc", - "itertools 0.12.1", + "itertools", "lru", "paste", "stability", - "strum 0.26.1", + "strum", "termion 3.0.0", "time 0.3.34", "unicode-segmentation", @@ -1776,35 +1716,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" -[[package]] -name = "regex" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" - [[package]] name = "rfc6979" version = "0.4.0" @@ -2141,35 +2052,13 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strum" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" -dependencies = [ - "strum_macros 0.25.3", -] - [[package]] name = "strum" version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "723b93e8addf9aa965ebe2d11da6d7540fa2283fcea14b3371ff055f7ba13f5f" dependencies = [ - "strum_macros 0.26.1", -] - -[[package]] -name = "strum_macros" -version = "0.25.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn 2.0.48", + "strum_macros", ] [[package]] @@ -2249,18 +2138,6 @@ dependencies = [ "redox_termios", ] -[[package]] -name = "termion" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90" -dependencies = [ - "libc", - "numtoa", - "redox_syscall 0.2.16", - "redox_termios", -] - [[package]] name = "termion" version = "3.0.0" @@ -2423,56 +2300,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tui" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" -dependencies = [ - "bitflags 1.3.2", - "cassowary", - "termion 1.5.6", - "unicode-segmentation", - "unicode-width", -] - -[[package]] -name = "tui-realm-stdlib" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a14fa5a0376ef64b93b484f811716b73422803df91c9ce7f83c50cc391230426" -dependencies = [ - "textwrap", - "tuirealm", - "unicode-width", -] - -[[package]] -name = "tuirealm" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "412447298ad477c25ff50c4a894ff5077b6ee3e25b913d42db30021d81b1af53" -dependencies = [ - "bitflags 2.4.1", - "lazy-regex", - "ratatui 0.23.0", - "termion 2.0.1", - "thiserror", - "tui", - "tuirealm_derive", -] - -[[package]] -name = "tuirealm_derive" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0adcdaf59881626555558eae08f8a53003c8a1961723b4d7a10c51599abbc81" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "typenum" version = "1.17.0" diff --git a/Cargo.toml b/Cargo.toml index 83e9bae8..b337895b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,6 @@ build = "build.rs" name = "rad-tui" path = "bin/main.rs" -[features] -default = ["flux"] -realm = ["dep:tuirealm", "dep:tui-realm-stdlib"] -flux = ["dep:tokio", "dep:tokio-stream"] - [dependencies] anyhow = { version = "1" } inquire = { version = "0.6.2", default-features = false, features = ["termion", "editor"] } @@ -35,7 +30,5 @@ timeago = { version = "0.4.1" } termion = { version = "3" } textwrap = { version = "0.16.0" } thiserror = { version = "1" } -tokio = { version = "1.32.0", features = ["full"], optional = true } -tokio-stream = { version = "0.1.14", optional = true } -tuirealm = { version = "^1.9.0", default-features = false, features = ["termion", "ratatui", "derive"], optional = true } -tui-realm-stdlib = { version = "1.3.1", default-features = false, features = ["termion", "ratatui"], optional = true } +tokio = { version = "1.32.0", features = ["full"] } +tokio-stream = { version = "0.1.14" } diff --git a/src/common/cob.rs b/src/cob.rs similarity index 100% rename from src/common/cob.rs rename to src/cob.rs diff --git a/src/common/cob/inbox.rs b/src/cob/inbox.rs similarity index 100% rename from src/common/cob/inbox.rs rename to src/cob/inbox.rs diff --git a/src/common/cob/issue.rs b/src/cob/issue.rs similarity index 100% rename from src/common/cob/issue.rs rename to src/cob/issue.rs diff --git a/src/common/cob/patch.rs b/src/cob/patch.rs similarity index 100% rename from src/common/cob/patch.rs rename to src/cob/patch.rs diff --git a/src/common.rs b/src/common.rs deleted file mode 100644 index b1cfeb30..00000000 --- a/src/common.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod cob; -pub mod context; -pub mod log; diff --git a/src/common/context.rs b/src/context.rs similarity index 100% rename from src/common/context.rs rename to src/context.rs diff --git a/src/flux/event.rs b/src/event.rs similarity index 100% rename from src/flux/event.rs rename to src/event.rs diff --git a/src/flux.rs b/src/flux.rs deleted file mode 100644 index 32778ea4..00000000 --- a/src/flux.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod event; -pub mod git; -pub mod store; -pub mod task; -pub mod terminal; -pub mod ui; diff --git a/src/flux/git.rs b/src/git.rs similarity index 100% rename from src/flux/git.rs rename to src/git.rs diff --git a/src/lib.rs b/src/lib.rs index e931ea7a..6df85ae3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,17 @@ +pub mod cob; +pub mod context; +pub mod event; +pub mod git; +pub mod log; +pub mod store; +pub mod task; +pub mod terminal; +pub mod ui; + use anyhow::Result; use serde::ser::{Serialize, SerializeStruct, Serializer}; -pub mod common; - -#[cfg(feature = "realm")] -pub mod realm; - -#[cfg(feature = "flux")] -pub mod flux; - /// An optional return value. #[derive(Clone, Debug)] pub struct Exit { diff --git a/src/common/log.rs b/src/log.rs similarity index 100% rename from src/common/log.rs rename to src/log.rs diff --git a/src/realm.rs b/src/realm.rs deleted file mode 100644 index 46213c0c..00000000 --- a/src/realm.rs +++ /dev/null @@ -1,211 +0,0 @@ -pub mod ui; - -use std::hash::Hash; -use std::time::Duration; - -use anyhow::Result; - -use tuirealm::terminal::TerminalBridge; -use tuirealm::tui::layout::Rect; -use tuirealm::Frame; -use tuirealm::{Application, EventListenerCfg, NoUserEvent}; - -use crate::common::context::Context; -use crate::Exit; -use ui::theme::Theme; - -/// Trait that must be implemented by client applications in order to be run -/// as tui-application using tui-realm. Implementors act as models to the -/// tui-realm application that can be polled for new messages, updated -/// accordingly and rendered with new state. -/// -/// Please see `examples/` for further information on how to use it. -pub trait Tui -where - Id: Eq + PartialEq + Clone + Hash, - Message: Eq, -{ - /// Should initialize an application by mounting and activating components. - fn init(&mut self, app: &mut Application) -> Result<()>; - - /// Should update the current state by handling a message from the view. Returns true - /// if view should be updated (e.g. a message was received and the current state changed). - fn update(&mut self, app: &mut Application) -> Result; - - /// Should draw the application to a frame. - fn view(&mut self, app: &mut Application, frame: &mut Frame); - - /// Should return `Some` if the application is requested to quit. - fn exit(&self) -> Option>; -} - -/// A tui-window using the cross-platform Terminal helper provided -/// by tui-realm. -pub struct Window { - /// Helper around `Terminal` to quickly setup and perform on terminal. - pub terminal: TerminalBridge, -} - -impl Default for Window { - fn default() -> Self { - Self::new() - } -} - -/// Provides a way to create and run a new tui-application. -impl Window { - /// Creates a tui-window using the default cross-platform Terminal - /// helper and panics if its creation fails. - pub fn new() -> Self { - let terminal = TerminalBridge::new().expect("Cannot create terminal bridge"); - - Self { terminal } - } - - /// Runs this tui-window with the tui-application given and performs the - /// following steps: - /// 1. Enter alternative terminal screen - /// 2. Run main loop until application should quit and with each iteration - /// - poll new events (tick or user event) - /// - update application state - /// - redraw view - /// 3. Leave alternative terminal screen - pub fn run( - &mut self, - tui: &mut T, - interval: u64, - ) -> Result> - where - T: Tui, - Id: Eq + PartialEq + Clone + Hash, - Message: Eq, - { - let mut update = true; - let mut resize = false; - let mut size = Rect::default(); - let mut app = Application::init( - EventListenerCfg::default().default_input_listener(Duration::from_millis(interval)), - ); - tui.init(&mut app)?; - - while tui.exit().is_none() { - if update || resize { - self.terminal - .raw_mut() - .draw(|frame| tui.view(&mut app, frame))?; - } - update = tui.update(&mut app)?; - - resize = size != self.terminal.raw_mut().size()?; - size = self.terminal.raw_mut().size()?; - } - - Ok(tui.exit().unwrap().value) - } -} - -/// `tuirealm`'s event and prop system is designed to work with flat component hierarchies. -/// Building deep nested component hierarchies would need a lot more additional effort to -/// properly pass events and props down these hierarchies. This makes it hard to implement -/// full app views (home, patch details etc) as components. -/// -/// View pages take into account these flat component hierarchies, and provide -/// switchable sets of components. -pub trait ViewPage -where - Id: Eq + PartialEq + Clone + Hash, - Message: Eq, -{ - /// Will be called whenever a view page is pushed onto the page stack. Should create and mount all widgets. - fn mount( - &mut self, - app: &mut Application, - context: &Context, - theme: &Theme, - ) -> Result<()>; - - /// Will be called whenever a view page is popped from the page stack. Should unmount all widgets. - fn unmount(&self, app: &mut Application) -> Result<()>; - - /// Will be called whenever a view page is on top of the stack and can be used to update its internal - /// state depending on the message passed. - fn update( - &mut self, - app: &mut Application, - context: &Context, - theme: &Theme, - message: Message, - ) -> Result>; - - /// Will be called whenever a view page is on top of the page stack and needs to be rendered. - fn view(&mut self, app: &mut Application, frame: &mut Frame); - - /// Will be called whenever this view page is pushed to the stack, or it is on top of the stack again - /// after another view page was popped from the stack. - fn subscribe(&self, app: &mut Application) -> Result<()>; - - /// Will be called whenever this view page is on top of the stack and another view page is pushed - /// to the stack, or if this is popped from the stack. - fn unsubscribe(&self, app: &mut Application) -> Result<()>; -} - -/// View pages need to preserve their state (e.g. selected navigation tab, contents -/// and the selected row of a table). Therefor they should not be (re-)created -/// each time they are displayed. -/// Instead the application can push a new page onto the page stack if it needs to -/// be displayed. Its components are then created using the internal state. If a -/// new page needs to be displayed, it will also be pushed onto the stack. Leaving -/// that page again will pop it from the stack. The application can then return to -/// the previously displayed page in the state it was left. -#[derive(Default)] -pub struct PageStack -where - Id: Eq + PartialEq + Clone + Hash, - Message: Eq, -{ - pages: Vec>>, -} - -impl PageStack -where - Id: Eq + PartialEq + Clone + Hash, - Message: Eq, -{ - pub fn push( - &mut self, - mut page: Box>, - app: &mut Application, - context: &Context, - theme: &Theme, - ) -> Result<()> { - if let Some(page) = self.pages.last() { - page.unsubscribe(app)?; - } - - page.mount(app, context, theme)?; - page.subscribe(app)?; - - self.pages.push(page); - - Ok(()) - } - - pub fn pop(&mut self, app: &mut Application) -> Result<()> { - self.peek_mut()?.unsubscribe(app)?; - self.peek_mut()?.unmount(app)?; - self.pages.pop(); - - self.peek_mut()?.subscribe(app)?; - - Ok(()) - } - - pub fn peek_mut(&mut self) -> Result<&mut Box>> { - match self.pages.last_mut() { - Some(page) => Ok(page), - None => Err(anyhow::anyhow!( - "Could not peek active page. Page stack is empty." - )), - } - } -} diff --git a/src/realm/ui.rs b/src/realm/ui.rs deleted file mode 100644 index a9a75602..00000000 --- a/src/realm/ui.rs +++ /dev/null @@ -1,164 +0,0 @@ -pub mod cob; -pub mod ext; -pub mod layout; -pub mod state; -pub mod subscription; -pub mod theme; -pub mod widget; - -use tuirealm::props::{AttrValue, Attribute}; -use tuirealm::MockComponent; - -use widget::container::{ - AppHeader, AppInfo, Container, GlobalListener, Header, LabeledContainer, Popup, Tabs, - VerticalLine, -}; -use widget::context::{Shortcut, Shortcuts}; -use widget::label::{self, Label, Textarea}; -use widget::list::{ColumnWidth, Property, PropertyList, PropertyTable}; -use widget::Widget; - -use theme::{style, Theme}; - -use crate::common::context::Context; - -pub fn global_listener() -> Widget { - Widget::new(GlobalListener::default()) -} - -pub fn container_header(theme: &Theme, label: Widget