diff --git a/mkdocs.yml b/.github/mkdocs.yml similarity index 64% rename from mkdocs.yml rename to .github/mkdocs.yml index 11ca622d1..c8f530e95 100644 --- a/mkdocs.yml +++ b/.github/mkdocs.yml @@ -1,16 +1,18 @@ site_name: Chris Titus LinUtil Official Documentation repo_url: https://github.com/ChrisTitusTech/linutil +docs_dir: '../docs' nav: - Introduction: 'index.md' - User Guide: 'userguide.md' - - Contribute: 'contribute.md' - - Known Issues: 'KnownIssues.md' + - Contributing Guide: 'contribute.md' + - Documentation: + - Known Issues: 'KnownIssues.md' - FAQ: 'faq.md' theme: name: material - custom_dir: 'overrides' + custom_dir: '../overrides' features: - navigation.tabs - navigation.sections @@ -25,20 +27,28 @@ theme: logo: assets/favicon.png favicon: assets/favicon.png palette: + # Palette toggle for automatic mode + - media: "(prefers-color-scheme)" + toggle: + icon: material/brightness-auto + name: Switch to light mode + + # Palette toggle for light mode - media: "(prefers-color-scheme: light)" scheme: default + accent: blue toggle: - icon: material/toggle-switch-off-outline + icon: material/brightness-7 name: Switch to dark mode - primary: black - accent: purple + + # Palette toggle for dark mode - media: "(prefers-color-scheme: dark)" scheme: slate + primary: black + accent: blue toggle: - icon: material/toggle-switch + icon: material/weather-night name: Switch to light mode - primary: teal - accent: lime markdown_extensions: - admonition - pymdownx.details @@ -62,4 +72,16 @@ markdown_extensions: - pymdownx.inlinehilite - def_list - pymdownx.tasklist: - custom_checkbox: true \ No newline at end of file + custom_checkbox: true + - toc: + permalink: true + +plugins: + - search + - awesome-pages + - git-revision-date-localized + - minify: + minify_html: true + htmlmin_opts: + remove_comments: true + cache_safe: true \ No newline at end of file diff --git a/.github/requirements.txt b/.github/requirements.txt new file mode 100644 index 000000000..295ed6807 --- /dev/null +++ b/.github/requirements.txt @@ -0,0 +1,51 @@ +Babel==2.15.0 +bracex==2.5 +cairocffi==1.7.1 +CairoSVG==2.7.1 +certifi==2024.7.4 +cffi==1.17.0 +charset-normalizer==3.3.2 +click==8.1.7 +colorama==0.4.6 +csscompressor==0.9.5 +cssselect2==0.7.0 +defusedxml==0.7.1 +ghp-import==2.1.0 +gitdb==4.0.11 +GitPython==3.1.43 +htmlmin2==0.1.13 +idna==3.7 +Jinja2==3.1.4 +jsmin==3.0.1 +Markdown==3.6 +MarkupSafe==2.1.5 +mergedeep==1.3.4 +mkdocs==1.6.0 +mkdocs-awesome-pages-plugin==2.9.3 +mkdocs-get-deps==0.2.0 +mkdocs-git-revision-date-localized-plugin==1.2.6 +mkdocs-material==9.5.31 +mkdocs-material-extensions==1.3.1 +mkdocs-minify-plugin==0.8.0 +natsort==8.4.0 +packaging==24.1 +paginate==0.5.6 +pathspec==0.12.1 +pillow==10.4.0 +platformdirs==4.2.2 +pycparser==2.22 +Pygments==2.18.0 +pymdown-extensions==10.9 +python-dateutil==2.9.0.post0 +pytz==2024.1 +PyYAML==6.0.2 +pyyaml_env_tag==0.1 +regex==2024.7.24 +requests==2.32.3 +six==1.16.0 +smmap==5.0.1 +tinycss2==1.3.0 +urllib3==2.2.2 +watchdog==4.0.1 +wcmatch==9.0 +webencodings==0.5.1 diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 486d1ed96..75bf243dc 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -1,22 +1,32 @@ name: GitHub Pages Deploy + on: - release: - types: [published, prereleased] - workflow_dispatch: -permissions: - contents: write + push: + paths: + - 'mkdocs.yml' + - 'docs/**' + - 'overrides/**' + - 'CONTRIBUTING.md' + workflow_dispatch: + jobs: - deploy: + build-and-deploy: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - name: Checkout Repository + uses: actions/checkout@v4 with: - python-version: 3.x - - uses: actions/cache@v4 + fetch-depth: '0' # Fetch all commit history for all branches as well as tags. + + - name: Setup Python + uses: actions/setup-python@v5 with: - key: ${{ github.ref }} - path: .cache - - run: pip install mkdocs-material - - run: pip install pillow cairosvg - - run: mkdocs gh-deploy --force + python-version: 3.x # Install latest Stable release of Python 3 + cache: 'pip' # Caching pip dependencies + + - name: Install Necessary Dependencies + run: pip install -r .github/requirements.txt + + - name: Build & Deploy using mkdocs + run: mkdocs gh-deploy --force -f .github/mkdocs.yml diff --git a/Cargo.lock b/Cargo.lock index bc6b5eebb..c3798ede0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,9 +86,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" [[package]] name = "arrayvec" @@ -450,6 +450,34 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[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" @@ -678,9 +706,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" dependencies = [ "bitflags 2.6.0", ] @@ -696,9 +724,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.36" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", @@ -972,26 +1000,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "tui" -version = "0.1.0" -dependencies = [ - "chrono", - "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.13" @@ -1004,9 +1012,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-segmentation" diff --git a/Cargo.toml b/Cargo.toml index 1d10db9ea..551f0bc4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,34 +1,16 @@ -[package] -name = "tui" +[workspace.package] +license = "MIT" version = "0.1.0" -edition = "2021" -[dependencies] -clap = { version = "4.5.16", features = ["derive"] } -crossterm = "0.28.1" +[workspace.dependencies] ego-tree = "0.6.2" -oneshot = "0.1.8" -portable-pty = "0.8.1" -ratatui = "0.28.1" -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 diff --git a/README.md b/README.md index 54d2f21bd..b892afc11 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Version](https://img.shields.io/github/v/release/ChrisTitusTech/linutil?color=%230567ff&label=Latest%20Release&style=for-the-badge)](https://github.com/ChrisTitusTech/linutil/releases/latest) ![GitHub Downloads (specific asset, all releases)](https://img.shields.io/github/downloads/ChrisTitusTech/linutil/linutil?label=Total%20Downloads&style=for-the-badge) +[![](https://dcbadge.limes.pink/api/server/https://discord.gg/bujFYKAHSp)](https://discord.gg/bujFYKAHSp) ![Preview](docs/assets/preview.png) diff --git a/build.rs b/build.rs deleted file mode 100644 index ee7af0661..000000000 --- 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/build/linutil b/build/linutil deleted file mode 100755 index 251883750..000000000 Binary files a/build/linutil and /dev/null differ diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 000000000..ebe1091df --- /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 88% rename from src/tabs.rs rename to core/src/inner.rs index 970884a0e..4713235f9 100644 --- a/src/tabs.rs +++ b/core/src/inner.rs @@ -1,7 +1,55 @@ -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, + multi_selectable, + }, + 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, + multi_selectable, + } + }, + ) + .collect(); + + if tabs.is_empty() { + panic!("No tabs found"); + } + tabs +} #[derive(Deserialize)] struct TabList { @@ -85,63 +133,6 @@ enum SystemDataType { CommandExists, } -#[derive(Hash, Eq, PartialEq)] -pub struct Tab { - pub name: String, - pub tree: Tree, - pub multi_selectable: bool, -} - -#[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, - multi_selectable, - }, - 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, - multi_selectable, - } - }, - ) - .collect(); - - if tabs.is_empty() { - panic!("No tabs found"); - } - tabs -} - fn filter_entries(entries: &mut Vec) { entries.retain_mut(|entry| { if !entry.is_supported() { @@ -196,15 +187,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 000000000..b3745eaa5 --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,26 @@ +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, + pub multi_selectable: bool, +} + +#[derive(Clone, Hash, Eq, PartialEq)] +pub struct ListNode { + pub name: String, + pub command: Command, +} diff --git a/docs/index.md b/docs/index.md index 2493dc82e..d947deedd 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,6 +2,7 @@ [![Version](https://img.shields.io/github/v/release/ChrisTitusTech/linutil?color=%230567ff&label=Latest%20Release&style=for-the-badge)](https://github.com/ChrisTitusTech/linutil/releases/latest) ![GitHub Downloads (specific asset, all releases)](https://img.shields.io/github/downloads/ChrisTitusTech/linutil/start.sh?label=Total%20Downloads&style=for-the-badge) +[![Discord Community Server](https://dcbadge.limes.pink/api/server/https://discord.gg/bujFYKAHSp)](https://discord.gg/bujFYKAHSp) ## Running the latest release of LinUtil diff --git a/roadmap.md b/roadmap.md new file mode 100644 index 000000000..8f41056e1 --- /dev/null +++ b/roadmap.md @@ -0,0 +1,23 @@ +# Roadmap + +## Vision +- To simplify linux tasks for all users for all distributions; Easily, efficiently, and effortlessly. + +## Goals +- [ ] Focus on tasks that take time in Linux and automate them. (Example: Removing a user, adding a user, etc. - but mostly BASH scripts with POSIX compliance.) +- [ ] Remove Binary linutil from being tracked in git and make it a github action. +- [ ] Document every function and feature of linutil. (Preview panel description addition) +- [x] Create a discord server for linutil and invite the community. +- [ ] Power Optimizations for Laptops + +## Milestones +### Q3 2024 +- [ ] Finish the foundation of the project in CLI mode. +- [ ] DENY ALL GUI Pull Requests while CLI and foundation is being established. + +### Q4 2024 +- [ ] GUI Brainstorming and Planning +- [ ] GUI Implementation towards the end of Q4 + +## Community Feedback +- Encourage community input and suggestions for future development. 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 000000000..383dd1548 --- /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.28.1" +ego-tree = { workspace = true } +oneshot = "0.1.8" +portable-pty = "0.8.1" +ratatui = "0.28.1" +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 000000000..121931c16 --- /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 89d15a70f..e6ff2cc2b 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::{Position, 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 99% rename from src/floating_text.rs rename to tui/src/floating_text.rs index e1d8deb35..ccf796ee1 100644 --- a/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -1,9 +1,9 @@ use crate::{ float::FloatContent, hint::{Shortcut, ShortcutList}, - running_command::Command, }; use crossterm::event::{KeyCode, KeyEvent}; +use linutil_core::Command; use ratatui::{ layout::Rect, style::{Style, Stylize}, diff --git a/src/hint.rs b/tui/src/hint.rs similarity index 100% rename from src/hint.rs rename to tui/src/hint.rs 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 1759435cc..4355a9107 100644 --- a/src/main.rs +++ b/tui/src/main.rs @@ -4,7 +4,6 @@ mod floating_text; mod hint; mod running_command; pub mod state; -mod tabs; mod theme; use std::{ @@ -21,13 +20,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)] @@ -44,13 +41,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 9742e53a0..956acaf23 100644 --- a/src/running_command.rs +++ b/tui/src/running_command.rs @@ -3,6 +3,7 @@ use crate::{ hint::{Shortcut, ShortcutList}, }; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; +use linutil_core::Command; use oneshot::{channel, Receiver}; use portable_pty::{ ChildKiller, CommandBuilder, ExitStatus, MasterPty, NativePtySystem, PtySize, PtySystem, @@ -16,7 +17,6 @@ use ratatui::{ }; use std::{ io::Write, - path::PathBuf, sync::{Arc, Mutex}, thread::JoinHandle, }; @@ -25,13 +25,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>>, @@ -187,7 +180,7 @@ impl RunningCommand { child.wait().unwrap() }); - let mut reader = pair.master.try_clone_reader().unwrap(); + let mut reader = pair.master.try_clone_reader().unwrap(); // This is a reader, this is where we // A buffer, shared between the thread that reads the command output, and the main tread. // The main thread only reads the contents diff --git a/src/state.rs b/tui/src/state.rs similarity index 98% rename from src/state.rs rename to tui/src/state.rs index b744f660b..c9d71cfbc 100644 --- a/src/state.rs +++ b/tui/src/state.rs @@ -3,12 +3,12 @@ use crate::{ float::{Float, FloatContent}, floating_text::FloatingText, hint::{draw_shortcuts, SHORTCUT_LINES}, - 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::{Alignment, Constraint, Direction, Layout}, style::{Style, Stylize}, @@ -16,7 +16,6 @@ use ratatui::{ widgets::{Block, Borders, List, ListState, Paragraph}, Frame, }; -use std::path::Path; pub struct AppState { /// Selected theme @@ -52,8 +51,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