From 87869593a570071e01b4633888762aaa61259051 Mon Sep 17 00:00:00 2001 From: Liam <33645555+lj3954@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:39:10 -0700 Subject: [PATCH] refactor: Split linutil into TUI and Core crates --- Cargo.lock | 208 ++++++++++++++++-- Cargo.toml | 35 +-- build.rs | 12 - core/Cargo.toml | 13 ++ src/tabs.rs => core/src/inner.rs | 96 ++++---- core/src/lib.rs | 25 +++ .../applications-setup/alacritty-setup.sh | 0 .../applications-setup/dwmtitus-setup.sh | 0 .../applications-setup/kitty-setup.sh | 0 .../applications-setup/rofi-setup.sh | 0 .../applications-setup/tab_data.toml | 0 .../applications-setup/zsh-setup.sh | 0 {src/commands => tabs}/common-script.sh | 0 .../gaming/diablo-ii/d2r-loot-filters.sh | 0 {src/commands => tabs}/gaming/tab_data.toml | 0 .../security/firewall-baselines.sh | 0 {src/commands => tabs}/security/tab_data.toml | 0 .../system-setup/1-compile-setup.sh | 0 .../system-setup/2-gaming-setup.sh | 0 .../system-setup/3-global-theme.sh | 0 .../system-setup/4-remove-snaps.sh | 0 .../system-setup/arch/paru-setup.sh | 0 .../system-setup/arch/server-setup.sh | 0 .../system-setup/arch/yay-setup.sh | 0 .../system-setup/fedora/rpm-fusion-setup.sh | 0 .../system-setup/system-update.sh | 0 .../system-setup/tab_data.toml | 0 {src/commands => tabs}/tabs.toml | 0 {src/commands => tabs}/test/lib.sh | 0 {src/commands => tabs}/test/main.sh | 0 .../utils/bluetooth-control.sh | 0 .../monitor-control/auto_detect_displays.sh | 0 .../monitor-control/change_orientation.sh | 0 .../utils/monitor-control/disable_monitor.sh | 0 .../monitor-control/duplicate_displays.sh | 0 .../utils/monitor-control/enable_monitor.sh | 0 .../utils/monitor-control/extend_displays.sh | 0 .../monitor-control/manage_arrangement.sh | 0 .../utils/monitor-control/reset_scaling.sh | 0 .../utils/monitor-control/scale_monitor.sh | 0 .../monitor-control/set_primary_monitor.sh | 0 .../utils/monitor-control/set_resolutions.sh | 0 .../monitor-control/utility_functions.sh | 0 {src/commands => tabs}/utils/numlock.sh | 0 {src/commands => tabs}/utils/tab_data.toml | 0 {src/commands => tabs}/utils/wifi-control.sh | 0 tui/Cargo.toml | 23 ++ tui/build.rs | 7 + {src => tui/src}/filter.rs | 3 +- {src => tui/src}/float.rs | 0 {src => tui/src}/floating_text.rs | 3 +- {src => tui/src}/main.rs | 11 +- {src => tui/src}/running_command.rs | 9 +- {src => tui/src}/state.rs | 9 +- {src => tui/src}/theme.rs | 0 55 files changed, 323 insertions(+), 131 deletions(-) delete mode 100644 build.rs create mode 100644 core/Cargo.toml rename src/tabs.rs => core/src/inner.rs (87%) create mode 100644 core/src/lib.rs rename {src/commands => tabs}/applications-setup/alacritty-setup.sh (100%) rename {src/commands => tabs}/applications-setup/dwmtitus-setup.sh (100%) rename {src/commands => tabs}/applications-setup/kitty-setup.sh (100%) rename {src/commands => tabs}/applications-setup/rofi-setup.sh (100%) rename {src/commands => tabs}/applications-setup/tab_data.toml (100%) rename {src/commands => tabs}/applications-setup/zsh-setup.sh (100%) rename {src/commands => tabs}/common-script.sh (100%) rename {src/commands => tabs}/gaming/diablo-ii/d2r-loot-filters.sh (100%) rename {src/commands => tabs}/gaming/tab_data.toml (100%) rename {src/commands => tabs}/security/firewall-baselines.sh (100%) rename {src/commands => tabs}/security/tab_data.toml (100%) rename {src/commands => tabs}/system-setup/1-compile-setup.sh (100%) rename {src/commands => tabs}/system-setup/2-gaming-setup.sh (100%) rename {src/commands => tabs}/system-setup/3-global-theme.sh (100%) rename {src/commands => tabs}/system-setup/4-remove-snaps.sh (100%) rename {src/commands => tabs}/system-setup/arch/paru-setup.sh (100%) rename {src/commands => tabs}/system-setup/arch/server-setup.sh (100%) rename {src/commands => tabs}/system-setup/arch/yay-setup.sh (100%) rename {src/commands => tabs}/system-setup/fedora/rpm-fusion-setup.sh (100%) rename {src/commands => tabs}/system-setup/system-update.sh (100%) rename {src/commands => tabs}/system-setup/tab_data.toml (100%) rename {src/commands => tabs}/tabs.toml (100%) rename {src/commands => tabs}/test/lib.sh (100%) rename {src/commands => tabs}/test/main.sh (100%) rename {src/commands => tabs}/utils/bluetooth-control.sh (100%) rename {src/commands => tabs}/utils/monitor-control/auto_detect_displays.sh (100%) rename {src/commands => tabs}/utils/monitor-control/change_orientation.sh (100%) rename {src/commands => tabs}/utils/monitor-control/disable_monitor.sh (100%) rename {src/commands => tabs}/utils/monitor-control/duplicate_displays.sh (100%) rename {src/commands => tabs}/utils/monitor-control/enable_monitor.sh (100%) rename {src/commands => tabs}/utils/monitor-control/extend_displays.sh (100%) rename {src/commands => tabs}/utils/monitor-control/manage_arrangement.sh (100%) rename {src/commands => tabs}/utils/monitor-control/reset_scaling.sh (100%) rename {src/commands => tabs}/utils/monitor-control/scale_monitor.sh (100%) rename {src/commands => tabs}/utils/monitor-control/set_primary_monitor.sh (100%) rename {src/commands => tabs}/utils/monitor-control/set_resolutions.sh (100%) rename {src/commands => tabs}/utils/monitor-control/utility_functions.sh (100%) rename {src/commands => tabs}/utils/numlock.sh (100%) rename {src/commands => tabs}/utils/tab_data.toml (100%) rename {src/commands => tabs}/utils/wifi-control.sh (100%) create mode 100644 tui/Cargo.toml create mode 100644 tui/build.rs rename {src => tui/src}/filter.rs (98%) rename {src => tui/src}/float.rs (100%) rename {src => tui/src}/floating_text.rs (98%) rename {src => tui/src}/main.rs (85%) rename {src => tui/src}/running_command.rs (98%) rename {src => tui/src}/state.rs (97%) rename {src => tui/src}/theme.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index a87ca14f..3d3828bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,21 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.14" @@ -99,6 +114,12 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "cassowary" version = "0.3.0" @@ -114,12 +135,35 @@ dependencies = [ "rustversion", ] +[[package]] +name = "cc" +version = "1.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.5", +] + [[package]] name = "clap" version = "4.5.16" @@ -179,6 +223,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crossterm" version = "0.27.0" @@ -280,6 +330,29 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "include_dir" version = "0.7.4" @@ -339,6 +412,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -351,6 +433,34 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "linutil_core" +version = "0.1.0" +dependencies = [ + "ego-tree", + "include_dir", + "serde", + "tempdir", + "toml", + "which", +] + +[[package]] +name = "linutil_tui" +version = "0.1.0" +dependencies = [ + "chrono", + "clap", + "crossterm", + "ego-tree", + "linutil_core", + "oneshot", + "portable-pty", + "ratatui", + "tui-term", + "unicode-width", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -423,6 +533,15 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -703,6 +822,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook" version = "0.3.17" @@ -867,25 +992,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "tui" -version = "0.1.0" -dependencies = [ - "clap", - "crossterm", - "ego-tree", - "include_dir", - "oneshot", - "portable-pty", - "ratatui", - "serde", - "tempdir", - "toml", - "tui-term", - "unicode-width", - "which", -] - [[package]] name = "tui-term" version = "0.1.12" @@ -976,6 +1082,61 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + [[package]] name = "which" version = "6.0.3" @@ -1010,6 +1171,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index f146e377..e9d90e64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,37 +1,20 @@ -[package] -name = "tui" +[workspace.package] +license = "MIT" version = "0.1.0" -edition = "2021" -[dependencies] -clap = { version = "4.5.16", features = ["derive"] } -crossterm = "0.27.0" +# Use workspace dependencies for anything public in linutil_core to avoid versioning conflicts +[workspace.dependencies] ego-tree = "0.6.2" -oneshot = "0.1.8" -portable-pty = "0.8.1" -ratatui = "0.27.0" -tui-term = "0.1.12" -include_dir = "0.7.4" -tempdir = "0.3.7" -serde = { version = "1.0.205", features = ["derive"] } -toml = "0.8.19" -which = "6.0.3" -unicode-width = "0.1.13" - -[build-dependencies] -chrono = "0.4.33" - -[[bin]] -name = "linutil" -path = "src/main.rs" - +[workspace] +members = ["tui", "core"] +resolver = "2" [profile.release] -opt-level = 3 +opt-level = "z" debug = false lto = true codegen-units = 1 panic = "abort" strip = true -incremental = false \ No newline at end of file +incremental = false diff --git a/build.rs b/build.rs deleted file mode 100644 index ee7af066..00000000 --- a/build.rs +++ /dev/null @@ -1,12 +0,0 @@ -fn main() { - // Rebuild program if any file in commands directory changes. - println!("cargo:rerun-if-changed=src/commands"); - // Rerun build script if any code is modified - println!("cargo:rerun-if-changed=src"); - - // Add current date as a variable to be displayed in the 'Linux Toolbox' text. - println!( - "cargo:rustc-env=BUILD_DATE={}", - chrono::Local::now().format("%Y-%m-%d") - ); -} diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 00000000..ebe1091d --- /dev/null +++ b/core/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "linutil_core" +edition = "2021" +version.workspace = true +license.workspace = true + +[dependencies] +include_dir = "0.7.4" +tempdir = "0.3.7" +serde = { version = "1.0.205", features = ["derive"] } +toml = "0.8.19" +which = "6.0.3" +ego-tree = { workspace = true } diff --git a/src/tabs.rs b/core/src/inner.rs similarity index 87% rename from src/tabs.rs rename to core/src/inner.rs index 97969326..f23d2104 100644 --- a/src/tabs.rs +++ b/core/src/inner.rs @@ -1,7 +1,42 @@ -use crate::running_command::Command; +use crate::{Command, ListNode, Tab}; use ego_tree::{NodeMut, Tree}; +use include_dir::{include_dir, Dir}; use serde::Deserialize; use std::path::{Path, PathBuf}; +use tempdir::TempDir; + +const TAB_DATA: Dir = include_dir!("$CARGO_MANIFEST_DIR/../tabs"); + +pub fn get_tabs(validate: bool) -> Vec { + let tab_files = TabList::get_tabs(); + let tabs = tab_files.into_iter().map(|path| { + let directory = path.parent().unwrap().to_owned(); + let data = std::fs::read_to_string(path).expect("Failed to read tab data"); + let mut tab_data: TabEntry = toml::from_str(&data).expect("Failed to parse tab data"); + + if validate { + filter_entries(&mut tab_data.data); + } + (tab_data, directory) + }); + + let tabs: Vec = tabs + .map(|(TabEntry { name, data }, directory)| { + let mut tree = Tree::new(ListNode { + name: "root".to_string(), + command: Command::None, + }); + let mut root = tree.root_mut(); + create_directory(data, &mut root, &directory); + Tab { name, tree } + }) + .collect(); + + if tabs.is_empty() { + panic!("No tabs found"); + } + tabs +} #[derive(Deserialize)] struct TabList { @@ -79,49 +114,6 @@ enum SystemDataType { CommandExists, } -#[derive(Hash, Eq, PartialEq)] -pub struct Tab { - pub name: String, - pub tree: Tree, -} - -#[derive(Clone, Hash, Eq, PartialEq)] -pub struct ListNode { - pub name: String, - pub command: Command, -} - -pub fn get_tabs(command_dir: &Path, validate: bool) -> Vec { - let tab_files = TabList::get_tabs(command_dir); - let tabs = tab_files.into_iter().map(|path| { - let directory = path.parent().unwrap().to_owned(); - let data = std::fs::read_to_string(path).expect("Failed to read tab data"); - let mut tab_data: TabEntry = toml::from_str(&data).expect("Failed to parse tab data"); - - if validate { - filter_entries(&mut tab_data.data); - } - (tab_data, directory) - }); - - let tabs: Vec = tabs - .map(|(TabEntry { name, data }, directory)| { - let mut tree = Tree::new(ListNode { - name: "root".to_string(), - command: Command::None, - }); - let mut root = tree.root_mut(); - create_directory(data, &mut root, &directory); - Tab { name, tree } - }) - .collect(); - - if tabs.is_empty() { - panic!("No tabs found"); - } - tabs -} - fn filter_entries(entries: &mut Vec) { entries.retain_mut(|entry| { if !entry.is_supported() { @@ -176,15 +168,21 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: } } } + impl TabList { - fn get_tabs(command_dir: &Path) -> Vec { - let tab_files = std::fs::read_to_string(command_dir.join("tabs.toml")) - .expect("Failed to read tabs.toml"); + fn get_tabs() -> Vec { + let temp_dir = TempDir::new("linutil_scripts").unwrap().into_path(); + TAB_DATA + .extract(&temp_dir) + .expect("Failed to extract the saved directory"); + + let tab_files = + std::fs::read_to_string(temp_dir.join("tabs.toml")).expect("Failed to read tabs.toml"); let data: Self = toml::from_str(&tab_files).expect("Failed to parse tabs.toml"); data.directories - .into_iter() - .map(|path| command_dir.join(path).join("tab_data.toml")) + .iter() + .map(|path| temp_dir.join(path).join("tab_data.toml")) .collect() } } diff --git a/core/src/lib.rs b/core/src/lib.rs new file mode 100644 index 00000000..93ce0619 --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,25 @@ +mod inner; + +use ego_tree::Tree; +use std::path::PathBuf; + +pub use inner::get_tabs; + +#[derive(Clone, Hash, Eq, PartialEq)] +pub enum Command { + Raw(String), + LocalFile(PathBuf), + None, // Directory +} + +#[derive(Clone, Hash, Eq, PartialEq)] +pub struct Tab { + pub name: String, + pub tree: Tree, +} + +#[derive(Clone, Hash, Eq, PartialEq)] +pub struct ListNode { + pub name: String, + pub command: Command, +} diff --git a/src/commands/applications-setup/alacritty-setup.sh b/tabs/applications-setup/alacritty-setup.sh similarity index 100% rename from src/commands/applications-setup/alacritty-setup.sh rename to tabs/applications-setup/alacritty-setup.sh diff --git a/src/commands/applications-setup/dwmtitus-setup.sh b/tabs/applications-setup/dwmtitus-setup.sh similarity index 100% rename from src/commands/applications-setup/dwmtitus-setup.sh rename to tabs/applications-setup/dwmtitus-setup.sh diff --git a/src/commands/applications-setup/kitty-setup.sh b/tabs/applications-setup/kitty-setup.sh similarity index 100% rename from src/commands/applications-setup/kitty-setup.sh rename to tabs/applications-setup/kitty-setup.sh diff --git a/src/commands/applications-setup/rofi-setup.sh b/tabs/applications-setup/rofi-setup.sh similarity index 100% rename from src/commands/applications-setup/rofi-setup.sh rename to tabs/applications-setup/rofi-setup.sh diff --git a/src/commands/applications-setup/tab_data.toml b/tabs/applications-setup/tab_data.toml similarity index 100% rename from src/commands/applications-setup/tab_data.toml rename to tabs/applications-setup/tab_data.toml diff --git a/src/commands/applications-setup/zsh-setup.sh b/tabs/applications-setup/zsh-setup.sh similarity index 100% rename from src/commands/applications-setup/zsh-setup.sh rename to tabs/applications-setup/zsh-setup.sh diff --git a/src/commands/common-script.sh b/tabs/common-script.sh similarity index 100% rename from src/commands/common-script.sh rename to tabs/common-script.sh diff --git a/src/commands/gaming/diablo-ii/d2r-loot-filters.sh b/tabs/gaming/diablo-ii/d2r-loot-filters.sh similarity index 100% rename from src/commands/gaming/diablo-ii/d2r-loot-filters.sh rename to tabs/gaming/diablo-ii/d2r-loot-filters.sh diff --git a/src/commands/gaming/tab_data.toml b/tabs/gaming/tab_data.toml similarity index 100% rename from src/commands/gaming/tab_data.toml rename to tabs/gaming/tab_data.toml diff --git a/src/commands/security/firewall-baselines.sh b/tabs/security/firewall-baselines.sh similarity index 100% rename from src/commands/security/firewall-baselines.sh rename to tabs/security/firewall-baselines.sh diff --git a/src/commands/security/tab_data.toml b/tabs/security/tab_data.toml similarity index 100% rename from src/commands/security/tab_data.toml rename to tabs/security/tab_data.toml diff --git a/src/commands/system-setup/1-compile-setup.sh b/tabs/system-setup/1-compile-setup.sh similarity index 100% rename from src/commands/system-setup/1-compile-setup.sh rename to tabs/system-setup/1-compile-setup.sh diff --git a/src/commands/system-setup/2-gaming-setup.sh b/tabs/system-setup/2-gaming-setup.sh similarity index 100% rename from src/commands/system-setup/2-gaming-setup.sh rename to tabs/system-setup/2-gaming-setup.sh diff --git a/src/commands/system-setup/3-global-theme.sh b/tabs/system-setup/3-global-theme.sh similarity index 100% rename from src/commands/system-setup/3-global-theme.sh rename to tabs/system-setup/3-global-theme.sh diff --git a/src/commands/system-setup/4-remove-snaps.sh b/tabs/system-setup/4-remove-snaps.sh similarity index 100% rename from src/commands/system-setup/4-remove-snaps.sh rename to tabs/system-setup/4-remove-snaps.sh diff --git a/src/commands/system-setup/arch/paru-setup.sh b/tabs/system-setup/arch/paru-setup.sh similarity index 100% rename from src/commands/system-setup/arch/paru-setup.sh rename to tabs/system-setup/arch/paru-setup.sh diff --git a/src/commands/system-setup/arch/server-setup.sh b/tabs/system-setup/arch/server-setup.sh similarity index 100% rename from src/commands/system-setup/arch/server-setup.sh rename to tabs/system-setup/arch/server-setup.sh diff --git a/src/commands/system-setup/arch/yay-setup.sh b/tabs/system-setup/arch/yay-setup.sh similarity index 100% rename from src/commands/system-setup/arch/yay-setup.sh rename to tabs/system-setup/arch/yay-setup.sh diff --git a/src/commands/system-setup/fedora/rpm-fusion-setup.sh b/tabs/system-setup/fedora/rpm-fusion-setup.sh similarity index 100% rename from src/commands/system-setup/fedora/rpm-fusion-setup.sh rename to tabs/system-setup/fedora/rpm-fusion-setup.sh diff --git a/src/commands/system-setup/system-update.sh b/tabs/system-setup/system-update.sh similarity index 100% rename from src/commands/system-setup/system-update.sh rename to tabs/system-setup/system-update.sh diff --git a/src/commands/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml similarity index 100% rename from src/commands/system-setup/tab_data.toml rename to tabs/system-setup/tab_data.toml diff --git a/src/commands/tabs.toml b/tabs/tabs.toml similarity index 100% rename from src/commands/tabs.toml rename to tabs/tabs.toml diff --git a/src/commands/test/lib.sh b/tabs/test/lib.sh similarity index 100% rename from src/commands/test/lib.sh rename to tabs/test/lib.sh diff --git a/src/commands/test/main.sh b/tabs/test/main.sh similarity index 100% rename from src/commands/test/main.sh rename to tabs/test/main.sh diff --git a/src/commands/utils/bluetooth-control.sh b/tabs/utils/bluetooth-control.sh similarity index 100% rename from src/commands/utils/bluetooth-control.sh rename to tabs/utils/bluetooth-control.sh diff --git a/src/commands/utils/monitor-control/auto_detect_displays.sh b/tabs/utils/monitor-control/auto_detect_displays.sh similarity index 100% rename from src/commands/utils/monitor-control/auto_detect_displays.sh rename to tabs/utils/monitor-control/auto_detect_displays.sh diff --git a/src/commands/utils/monitor-control/change_orientation.sh b/tabs/utils/monitor-control/change_orientation.sh similarity index 100% rename from src/commands/utils/monitor-control/change_orientation.sh rename to tabs/utils/monitor-control/change_orientation.sh diff --git a/src/commands/utils/monitor-control/disable_monitor.sh b/tabs/utils/monitor-control/disable_monitor.sh similarity index 100% rename from src/commands/utils/monitor-control/disable_monitor.sh rename to tabs/utils/monitor-control/disable_monitor.sh diff --git a/src/commands/utils/monitor-control/duplicate_displays.sh b/tabs/utils/monitor-control/duplicate_displays.sh similarity index 100% rename from src/commands/utils/monitor-control/duplicate_displays.sh rename to tabs/utils/monitor-control/duplicate_displays.sh diff --git a/src/commands/utils/monitor-control/enable_monitor.sh b/tabs/utils/monitor-control/enable_monitor.sh similarity index 100% rename from src/commands/utils/monitor-control/enable_monitor.sh rename to tabs/utils/monitor-control/enable_monitor.sh diff --git a/src/commands/utils/monitor-control/extend_displays.sh b/tabs/utils/monitor-control/extend_displays.sh similarity index 100% rename from src/commands/utils/monitor-control/extend_displays.sh rename to tabs/utils/monitor-control/extend_displays.sh diff --git a/src/commands/utils/monitor-control/manage_arrangement.sh b/tabs/utils/monitor-control/manage_arrangement.sh similarity index 100% rename from src/commands/utils/monitor-control/manage_arrangement.sh rename to tabs/utils/monitor-control/manage_arrangement.sh diff --git a/src/commands/utils/monitor-control/reset_scaling.sh b/tabs/utils/monitor-control/reset_scaling.sh similarity index 100% rename from src/commands/utils/monitor-control/reset_scaling.sh rename to tabs/utils/monitor-control/reset_scaling.sh diff --git a/src/commands/utils/monitor-control/scale_monitor.sh b/tabs/utils/monitor-control/scale_monitor.sh similarity index 100% rename from src/commands/utils/monitor-control/scale_monitor.sh rename to tabs/utils/monitor-control/scale_monitor.sh diff --git a/src/commands/utils/monitor-control/set_primary_monitor.sh b/tabs/utils/monitor-control/set_primary_monitor.sh similarity index 100% rename from src/commands/utils/monitor-control/set_primary_monitor.sh rename to tabs/utils/monitor-control/set_primary_monitor.sh diff --git a/src/commands/utils/monitor-control/set_resolutions.sh b/tabs/utils/monitor-control/set_resolutions.sh similarity index 100% rename from src/commands/utils/monitor-control/set_resolutions.sh rename to tabs/utils/monitor-control/set_resolutions.sh diff --git a/src/commands/utils/monitor-control/utility_functions.sh b/tabs/utils/monitor-control/utility_functions.sh similarity index 100% rename from src/commands/utils/monitor-control/utility_functions.sh rename to tabs/utils/monitor-control/utility_functions.sh diff --git a/src/commands/utils/numlock.sh b/tabs/utils/numlock.sh similarity index 100% rename from src/commands/utils/numlock.sh rename to tabs/utils/numlock.sh diff --git a/src/commands/utils/tab_data.toml b/tabs/utils/tab_data.toml similarity index 100% rename from src/commands/utils/tab_data.toml rename to tabs/utils/tab_data.toml diff --git a/src/commands/utils/wifi-control.sh b/tabs/utils/wifi-control.sh similarity index 100% rename from src/commands/utils/wifi-control.sh rename to tabs/utils/wifi-control.sh diff --git a/tui/Cargo.toml b/tui/Cargo.toml new file mode 100644 index 00000000..ad4e2d19 --- /dev/null +++ b/tui/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "linutil_tui" +edition = "2021" +version.workspace = true +license.workspace = true + +[dependencies] +clap = { version = "4.5.16", features = ["derive"] } +crossterm = "0.27.0" +ego-tree = { workspace = true } +oneshot = "0.1.8" +portable-pty = "0.8.1" +ratatui = "0.27.0" +tui-term = "0.1.12" +unicode-width = "0.1.13" +linutil_core = { path = "../core" } + +[build-dependencies] +chrono = "0.4.33" + +[[bin]] +name = "linutil" +path = "src/main.rs" diff --git a/tui/build.rs b/tui/build.rs new file mode 100644 index 00000000..121931c1 --- /dev/null +++ b/tui/build.rs @@ -0,0 +1,7 @@ +fn main() { + // Add current date as a variable to be displayed in the 'Linux Toolbox' text. + println!( + "cargo:rustc-env=BUILD_DATE={}", + chrono::Local::now().format("%Y-%m-%d") + ); +} diff --git a/src/filter.rs b/tui/src/filter.rs similarity index 98% rename from src/filter.rs rename to tui/src/filter.rs index 3e90af8f..caf69502 100644 --- a/src/filter.rs +++ b/tui/src/filter.rs @@ -1,6 +1,7 @@ -use crate::{state::ListEntry, tabs::Tab, theme::Theme}; +use crate::{state::ListEntry, theme::Theme}; use crossterm::event::{KeyCode, KeyEvent}; use ego_tree::NodeId; +use linutil_core::Tab; use ratatui::{ layout::Rect, style::Style, diff --git a/src/float.rs b/tui/src/float.rs similarity index 100% rename from src/float.rs rename to tui/src/float.rs diff --git a/src/floating_text.rs b/tui/src/floating_text.rs similarity index 98% rename from src/floating_text.rs rename to tui/src/floating_text.rs index 482a8822..18ea1812 100644 --- a/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -1,5 +1,6 @@ -use crate::{float::FloatContent, running_command::Command}; +use crate::float::FloatContent; use crossterm::event::{KeyCode, KeyEvent}; +use linutil_core::Command; use ratatui::{ layout::Rect, style::{Style, Stylize}, diff --git a/src/main.rs b/tui/src/main.rs similarity index 85% rename from src/main.rs rename to tui/src/main.rs index 85c0278f..49793338 100644 --- a/src/main.rs +++ b/tui/src/main.rs @@ -3,7 +3,6 @@ mod float; mod floating_text; mod running_command; pub mod state; -mod tabs; mod theme; use std::{ @@ -20,13 +19,11 @@ use crossterm::{ terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, ExecutableCommand, }; -use include_dir::include_dir; use ratatui::{ backend::{Backend, CrosstermBackend}, Terminal, }; use state::AppState; -use tempdir::TempDir; // Linux utility toolbox #[derive(Debug, Parser)] @@ -43,13 +40,7 @@ struct Args { fn main() -> std::io::Result<()> { let args = Args::parse(); - let commands_dir = include_dir!("src/commands"); - let temp_dir: TempDir = TempDir::new("linutil_scripts").unwrap(); - commands_dir - .extract(temp_dir.path()) - .expect("Failed to extract the saved directory"); - - let mut state = AppState::new(args.theme, temp_dir.path(), args.override_validation); + let mut state = AppState::new(args.theme, args.override_validation); stdout().execute(EnterAlternateScreen)?; enable_raw_mode()?; diff --git a/src/running_command.rs b/tui/src/running_command.rs similarity index 98% rename from src/running_command.rs rename to tui/src/running_command.rs index f5041ee4..44021a4b 100644 --- a/src/running_command.rs +++ b/tui/src/running_command.rs @@ -1,5 +1,6 @@ use crate::float::FloatContent; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; +use linutil_core::Command; use oneshot::{channel, Receiver}; use portable_pty::{ ChildKiller, CommandBuilder, ExitStatus, MasterPty, NativePtySystem, PtySize, PtySystem, @@ -13,7 +14,6 @@ use ratatui::{ }; use std::{ io::Write, - path::PathBuf, sync::{Arc, Mutex}, thread::JoinHandle, }; @@ -22,13 +22,6 @@ use tui_term::{ widget::PseudoTerminal, }; -#[derive(Clone, Hash, Eq, PartialEq)] -pub enum Command { - Raw(String), - LocalFile(PathBuf), - None, // Directory -} - pub struct RunningCommand { /// A buffer to save all the command output (accumulates, until the command exits) buffer: Arc>>, diff --git a/src/state.rs b/tui/src/state.rs similarity index 97% rename from src/state.rs rename to tui/src/state.rs index 432a5af2..9bf920f5 100644 --- a/src/state.rs +++ b/tui/src/state.rs @@ -2,12 +2,12 @@ use crate::{ filter::{Filter, SearchAction}, float::{Float, FloatContent}, floating_text::FloatingText, - running_command::{Command, RunningCommand}, - tabs::{ListNode, Tab}, + running_command::RunningCommand, theme::Theme, }; use crossterm::event::{KeyCode, KeyEvent, KeyEventKind}; use ego_tree::NodeId; +use linutil_core::{Command, ListNode, Tab}; use ratatui::{ layout::{Constraint, Direction, Layout}, style::{Style, Stylize}, @@ -15,7 +15,6 @@ use ratatui::{ widgets::{Block, Borders, List, ListState}, Frame, }; -use std::path::Path; pub struct AppState { /// Selected theme @@ -49,8 +48,8 @@ pub struct ListEntry { } impl AppState { - pub fn new(theme: Theme, temp_path: &Path, override_validation: bool) -> Self { - let tabs = crate::tabs::get_tabs(temp_path, !override_validation); + pub fn new(theme: Theme, override_validation: bool) -> Self { + let tabs = linutil_core::get_tabs(!override_validation); let root_id = tabs[0].tree.root().id(); let mut state = Self { theme, diff --git a/src/theme.rs b/tui/src/theme.rs similarity index 100% rename from src/theme.rs rename to tui/src/theme.rs