From 27d92f87db8da602064a5bb3e44754b5ff93cdb9 Mon Sep 17 00:00:00 2001 From: Jamy Golden Date: Fri, 12 Jul 2024 22:46:51 +0200 Subject: [PATCH] Add `--custom-schemes` flag support for `info` subcommand and bug fixes --- CHANGELOG.md | 16 +++++++++++++++- Cargo.lock | 14 +++++++------- Cargo.toml | 6 +++--- README.md | 4 ++-- THIRD_PARTY_LICENSES.md | 11 ++++++----- src/cli.rs | 17 ++++++++++++----- src/main.rs | 6 +++++- src/operations/info.rs | 40 +++++++++++++++++++++++++--------------- src/operations/list.rs | 20 +++++++++++++++----- 9 files changed, 90 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d45ea4..4e31178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [0.18.0] - 2024-07-12 + +### Added + +- Add `--custom-schemes` flag support for `tinty info` + +### Fixed + +- Fix bug where `tinty generate-scheme` would generate schemes without + scheme values being wrapped in double quotes +- Fix error message when `tinty list --custom-schemes` when no custom + schemes exist + ## [0.17.0] - 2024-07-03 ### Added @@ -7,7 +20,7 @@ - Add `tinty generate-scheme` command to generate a scheme based on provided image input, with the included functionality of saving this scheme file and applying it with `tinty apply`. -- Add `--custom-schemes` flag for `tinty lint` subcommand to list custom +- Add `--custom-schemes` flag for `tinty list` subcommand to list custom schemes saved with `tinnty generate-scheme`. ## [0.16.0] - 2024-07-02 @@ -136,6 +149,7 @@ - Initial release +[0.18.0]: https://github.com/tinted-theming/tinty/compare/v0.17.0...v0.18.0 [0.17.0]: https://github.com/tinted-theming/tinty/compare/v0.16.0...v0.17.0 [0.16.0]: https://github.com/tinted-theming/tinty/compare/v0.15.0...v0.16.0 [0.15.0]: https://github.com/tinted-theming/tinty/compare/v0.14.0...v0.15.0 diff --git a/Cargo.lock b/Cargo.lock index e626a04..9199666 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1286,9 +1286,9 @@ dependencies = [ [[package]] name = "tinted-builder" -version = "0.4.4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2785011c35e7f575d4a92dbf8de55f64fcfc874e2dd9ba760a64e06a2e8c473" +checksum = "8e66036f08d47c5ff9b652101fb6e97bcee5210648d33e92404d2cc88ac2d443" dependencies = [ "anyhow", "clap", @@ -1302,9 +1302,9 @@ dependencies = [ [[package]] name = "tinted-builder-rust" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11894f65c737aeb1150ca4d42f0f98a4037994f0a0dd057134affd63d4042583" +checksum = "3db9ba45390f39eb492e2e83f8e7538ec53b9e378569cb58badc27bf4a2d89e2" dependencies = [ "anyhow", "clap", @@ -1316,9 +1316,9 @@ dependencies = [ [[package]] name = "tinted-scheme-extractor" -version = "0.2.2" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e65c7ca5c92de53b069910855697c9b0f73b8bb28bb9c551d510d9637441440" +checksum = "614f71a79f6b826a2fa3e8f7d5f07c588123f0dcd97d652ee552d84e548edbc4" dependencies = [ "color-thief", "image", @@ -1329,7 +1329,7 @@ dependencies = [ [[package]] name = "tinty" -version = "0.17.0" +version = "0.18.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index a671aab..9266284 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tinty" description = "Change the theme of your terminal, text editor and anything else with one command!" -version = "0.17.0" +version = "0.18.0" edition = "2021" license = "MIT" readme = "README.md" @@ -21,7 +21,7 @@ serde = { version = "1.0.202", features = ["derive"] } serde_yaml = "0.9.31" shell-words = "1.1.0" strip-ansi-escapes = "0.2.0" -tinted-builder-rust = "0.9.1" -tinted-scheme-extractor = "0.2.2" +tinted-builder-rust = "0.9.3" +tinted-scheme-extractor = "0.3.2" toml = "0.8.13" url = "2.5.0" diff --git a/README.md b/README.md index 2b97cbe..3a372ce 100644 --- a/README.md +++ b/README.md @@ -160,13 +160,13 @@ The following is a table of the available subcommands for the CLI tool (Tinty), | Subcommand | Description | Arguments | Example Usage | |------------|-----------------------------------------------------|----------------------|--------------------------------------------| | `install` | Installs requirements for the configuration. | - | `tinty install` | -| `list` | Lists all available themes. | `--custom-schemes` to list saved custom theme files using `tinty generate-scheme` | `tinty list` | +| `list` | Lists all available themes. | Optional argument `--custom-schemes` to list saved custom theme files using `tinty generate-scheme` | `tinty list` | | `apply` | Applies a specific theme. | `-`: Name of the system and scheme to apply. | `tinty apply base16-mocha` | | `update` | Updates the templates and schemes. | - | `tinty update` | | `init` | Initializes the tool with the last applied theme otherwise `default-scheme` from `config.toml`. | - | `tinty init` | | `current` | Displays the currently applied theme. | - | `tinty current` | | `config` | Displays config related information currently in use by Tinty. Without flags it returns `config.yml` content. | - | `tinty config` | -| `info` | Provides information about themes. | `[-]`: Optional argument to specify a theme for detailed info. | `tinty info base16-mocha` | +| `info` | Provides information about themes. | `[-]`: Optional argument `--custom-schemes` to provide information on any custom schemes | `tinty info base16-mocha` | | `build` | Builds the provided base16 or base24 template using [tinted-builder-rust]. | ``: Path to the base16 or base24 template directory. | `tinty build path/to/tinted-tmux` | | `generate-completion` | Generates a shell completion file to source in your shell startup file (`*rc`). | ``: Name of the shell to generate a completion script for. Supports `bash`, `elvish`, `fish`, `powershell`, `zsh` | `tinty generate-completion bash` | | `generate-scheme` | Generates a yaml scheme file with colors inferred from provided image. | ``: Path to image. Either `` (`-` value to print to stdout) or `--save` to save for use within `tinty` | `tinty generate-completion bash` | diff --git a/THIRD_PARTY_LICENSES.md b/THIRD_PARTY_LICENSES.md index 9c539f5..139019d 100644 --- a/THIRD_PARTY_LICENSES.md +++ b/THIRD_PARTY_LICENSES.md @@ -4,7 +4,7 @@ This page lists the licenses of the projects used in cargo-about. ## Overview of licenses -- Apache License 2.0 (116) +- Apache License 2.0 (117) - MIT License (32) - BSD 3-Clause "New" or "Revised" License (4) - BSD 2-Clause "Simplified" License (3) @@ -3998,8 +3998,9 @@ limitations under the License. - [profiling 1.0.15](https://github.com/aclysma/profiling) - [ribboncurls 0.2.1](https://github.com/tinted-theming/ribboncurls) - [siphasher 0.3.11](https://github.com/jedisct1/rust-siphash) -- [tinted-builder-rust 0.9.1](https://github.com/tinted-theming/tinted-builder-rust) -- [tinted-builder 0.4.4](https://github.com/tinted-theming/tinted-builder-rust) +- [tinted-builder-rust 0.9.2](https://github.com/tinted-theming/tinted-builder-rust) +- [tinted-builder 0.4.5](https://github.com/tinted-theming/tinted-builder-rust) +- [tinted-builder 0.5.0](https://github.com/tinted-theming/tinted-builder-rust) - [zune-core 0.4.12](https://crates.io/crates/zune-core) - [zune-inflate 0.2.54](https://crates.io/crates/zune-inflate) - [zune-jpeg 0.4.11](https://github.com/etemesi254/zune-image/tree/dev/crates/zune-jpeg) @@ -4783,7 +4784,7 @@ SOFTWARE. #### Used by -- [tinty 0.17.0](https://github.com/tinted-theming/tinty) +- [tinty 0.18.0](https://github.com/tinted-theming/tinty) ``` MIT License @@ -5149,7 +5150,7 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I #### Used by -- [tinted-scheme-extractor 0.2.2](https://github.com/tinted-theming/tinted-scheme-extractor-rs) +- [tinted-scheme-extractor 0.3.2](https://github.com/tinted-theming/tinted-scheme-extractor-rs) ``` Mozilla Public License Version 2.0 diff --git a/src/cli.rs b/src/cli.rs index 544da8f..5f5c03d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -115,11 +115,18 @@ pub fn build_cli() -> Command { .required(true)), ) .subcommand( - Command::new("info").about(format!("Shows scheme colors for all schemes matching - (Eg: {} info base16-mocha)", REPO_NAME)).arg( - Arg::new("scheme_name") - .help("The scheme you want to get information about") - .required(false), - ) + Command::new("info").about(format!("Shows scheme colors for all schemes matching - (Eg: {} info base16-mocha)", REPO_NAME)) + .arg( + Arg::new("scheme_name") + .help("The scheme you want to get information about") + .required(false), + ) + .arg( + Arg::new("custom-schemes") + .help("Lists availabile custom schemes") + .long("custom-schemes") + .action(ArgAction::SetTrue) + ) ) .subcommand( Command::new("init").about("Initializes with the exising config. Used to Initialize exising theme for when your shell starts up") diff --git a/src/main.rs b/src/main.rs index 28225f0..dac2a2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,9 +97,13 @@ fn main() -> Result<()> { }; } Some(("info", sub_matches)) => { + let is_custom = sub_matches + .get_one::("custom-schemes") + .map(|b| b.to_owned()) + .unwrap_or(false); let scheme_name_option = sub_matches.get_one::("scheme_name"); - operations::info::info(&data_path, scheme_name_option)?; + operations::info::info(&data_path, scheme_name_option, is_custom)?; } Some(("init", _)) => { operations::init::init(&config_path, &data_path)?; diff --git a/src/operations/info.rs b/src/operations/info.rs index 3b75708..883b919 100644 --- a/src/operations/info.rs +++ b/src/operations/info.rs @@ -1,6 +1,6 @@ use crate::{ config::SupportedSchemeSystems, - constants::{REPO_DIR, REPO_NAME, REPO_URL, SCHEMES_REPO_NAME}, + constants::{CUSTOM_SCHEMES_DIR_NAME, REPO_DIR, REPO_NAME, REPO_URL, SCHEMES_REPO_NAME}, }; use anyhow::{anyhow, Result}; use hex_color::HexColor; @@ -239,22 +239,32 @@ fn print_all_schemes(files: Vec) -> Result<()> { Ok(()) } -pub fn info(data_path: &Path, scheme_name_option: Option<&String>) -> Result<()> { - let schemes_repo_path = data_path.join(format!("{}/{}", REPO_DIR, SCHEMES_REPO_NAME)); +pub fn info(data_path: &Path, scheme_name_option: Option<&String>, is_custom: bool) -> Result<()> { + let schemes_dir_path = if is_custom { + data_path.join(CUSTOM_SCHEMES_DIR_NAME) + } else { + data_path.join(format!("{}/{}", REPO_DIR, SCHEMES_REPO_NAME)) + }; - if !schemes_repo_path - .join(SupportedSchemeSystems::default().to_string()) - .exists() - { - return Err(anyhow!( - "Scheme repo path does not exist: {}\nRun `{} install` and try again", - schemes_repo_path.display(), - REPO_NAME - )); + match (schemes_dir_path.exists(), is_custom) { + (false, true) => { + return Err(anyhow!( + "You don't have any local custom schemes at: {}", + schemes_dir_path.display(), + )) + } + (false, false) => { + return Err(anyhow!( + "Scheme repo path does not exist: {}\nRun `{} install` and try again", + schemes_dir_path.display(), + REPO_NAME + )) + } + _ => {} } let files_entries = - fs::read_dir(schemes_repo_path.join(SupportedSchemeSystems::default().as_str()))?; + fs::read_dir(schemes_dir_path.join(SupportedSchemeSystems::default().as_str()))?; let mut files: Vec = files_entries .filter_map(|entry| entry.ok().map(|e| e.path())) .collect(); @@ -266,9 +276,9 @@ pub fn info(data_path: &Path, scheme_name_option: Option<&String>) -> Result<()> // Add other scheme_system schemes to vec for scheme_system in scheme_systems_without_default { - if schemes_repo_path.join(scheme_system).exists() { + if schemes_dir_path.join(scheme_system).exists() { files.extend( - fs::read_dir(schemes_repo_path.join(scheme_system))? + fs::read_dir(schemes_dir_path.join(scheme_system))? .filter_map(|entry| entry.ok().map(|e| e.path())), ); } diff --git a/src/operations/list.rs b/src/operations/list.rs index 460918d..8149df5 100644 --- a/src/operations/list.rs +++ b/src/operations/list.rs @@ -16,11 +16,21 @@ pub fn list(data_path: &Path, is_custom: bool) -> Result<()> { data_path.join(format!("{}/{}", REPO_DIR, SCHEMES_REPO_NAME)) }; - if !schemes_dir_path.exists() { - return Err(anyhow!( - "Schemes are missing, run install and then try again: `{} install`", - REPO_NAME - )); + match (schemes_dir_path.exists(), is_custom) { + (false, true) => { + return Err(anyhow!( + "You don't have any local custom schemes at: {}", + schemes_dir_path.display(), + )) + } + (false, false) => { + return Err(anyhow!( + "Scheme repo path does not exist: {}\nRun `{} install` and try again", + schemes_dir_path.display(), + REPO_NAME + )) + } + _ => {} } let scheme_vec = get_all_scheme_names(&schemes_dir_path, None)?;