From 6491b455ef2bb93ebbed5c10b91770d0fcce6b8a Mon Sep 17 00:00:00 2001 From: Liam <33645555+lj3954@users.noreply.github.com> Date: Sat, 12 Oct 2024 09:45:03 -0700 Subject: [PATCH 1/2] refactor: Export ego-tree from linutil core, rather than workspace --- Cargo.lock | 5 ++--- Cargo.toml | 3 --- core/Cargo.toml | 8 ++------ core/src/lib.rs | 1 + tui/Cargo.toml | 1 - tui/src/filter.rs | 3 +-- tui/src/state.rs | 3 +-- 7 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 266ed837..82708c29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,9 +291,9 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "ego-tree" -version = "0.6.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12a0bb14ac04a9fcf170d0bbbef949b44cc492f4452bd20c095636956f653642" +checksum = "7c6ba7d4eec39eaa9ab24d44a0e73a7949a1095a8b3f3abb11eddf27dbb56a53" [[package]] name = "either" @@ -504,7 +504,6 @@ dependencies = [ "chrono", "clap", "crossterm", - "ego-tree", "linutil_core", "oneshot", "portable-pty", diff --git a/Cargo.toml b/Cargo.toml index ef31b2a9..2fa6d68d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,9 +3,6 @@ license = "MIT" version = "24.9.28" edition = "2021" -[workspace.dependencies] -ego-tree = "0.6.2" - [workspace] members = ["tui", "core", "xtask"] default-members = ["tui", "core"] diff --git a/core/Cargo.toml b/core/Cargo.toml index d3f42011..f07d4b77 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -5,11 +5,7 @@ repository = "https://github.com/ChrisTitusTech/linutil/tree/main/core" edition = "2021" version.workspace = true license.workspace = true -include = [ - "src/*.rs", - "Cargo.toml", - "tabs/**", -] +include = ["src/*.rs", "Cargo.toml", "tabs/**"] [dependencies] include_dir = "0.7.4" @@ -17,4 +13,4 @@ temp-dir = "0.1.14" serde = { version = "1.0.205", features = ["derive"], default-features = false } toml = { version = "0.8.19", features = ["parse"], default-features = false } which = "6.0.3" -ego-tree = { workspace = true } +ego-tree = "0.9.0" diff --git a/core/src/lib.rs b/core/src/lib.rs index b7cd631e..9a814549 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -2,6 +2,7 @@ mod inner; use std::rc::Rc; +pub use ego_tree; use ego_tree::Tree; use std::path::PathBuf; diff --git a/tui/Cargo.toml b/tui/Cargo.toml index 40d3c357..129bb7dd 100644 --- a/tui/Cargo.toml +++ b/tui/Cargo.toml @@ -17,7 +17,6 @@ tips = ["rand"] [dependencies] clap = { version = "4.5.19", features = ["derive"] } crossterm = "0.28.1" -ego-tree = { workspace = true } oneshot = "0.1.8" portable-pty = "0.8.1" ratatui = "0.28.1" diff --git a/tui/src/filter.rs b/tui/src/filter.rs index e6ff2cc2..7f2e9d0b 100644 --- a/tui/src/filter.rs +++ b/tui/src/filter.rs @@ -1,7 +1,6 @@ use crate::{state::ListEntry, theme::Theme}; use crossterm::event::{KeyCode, KeyEvent}; -use ego_tree::NodeId; -use linutil_core::Tab; +use linutil_core::{ego_tree::NodeId, Tab}; use ratatui::{ layout::{Position, Rect}, style::Style, diff --git a/tui/src/state.rs b/tui/src/state.rs index 9ed61771..e8245809 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -8,8 +8,7 @@ use crate::{ theme::Theme, }; use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; -use ego_tree::NodeId; -use linutil_core::{ListNode, Tab}; +use linutil_core::{ego_tree::NodeId, ListNode, Tab}; #[cfg(feature = "tips")] use rand::Rng; use ratatui::{ From dc38e3e10ef68c9a794c5f0269fc7d65e53ffe21 Mon Sep 17 00:00:00 2001 From: Liam <33645555+lj3954@users.noreply.github.com> Date: Sat, 12 Oct 2024 09:45:22 -0700 Subject: [PATCH 2/2] refactor: Improve code formatting --- tui/src/hint.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tui/src/hint.rs b/tui/src/hint.rs index 8e16e749..33cf62c8 100644 --- a/tui/src/hint.rs +++ b/tui/src/hint.rs @@ -59,9 +59,9 @@ pub fn create_shortcut_list( if rest.is_empty() { break; - } else { - shortcut_spans = rest; } + + shortcut_spans = rest; } lines.into_boxed_slice() @@ -79,8 +79,8 @@ impl Shortcut { } fn to_spans(&self) -> Vec> { - let mut ret: Vec<_> = self - .key_sequences + let description = Span::styled(self.desc, Style::default().italic()); + self.key_sequences .iter() .flat_map(|seq| { [ @@ -89,8 +89,7 @@ impl Shortcut { Span::default().content("] "), ] }) - .collect(); - ret.push(Span::styled(self.desc, Style::default().italic())); - ret + .chain(std::iter::once(description)) + .collect() } }