Skip to content

Commit

Permalink
Add --custom-schemes flag support for info subcommand and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden committed Jul 12, 2024
1 parent 51179a8 commit 27d92f8
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 44 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# 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

- 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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | `<scheme_system>-<scheme_name>`: 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. | `[<scheme_system>-<scheme_name>]`: Optional argument to specify a theme for detailed info. | `tinty info base16-mocha` |
| `info` | Provides information about themes. | `[<scheme_system>-<scheme_name>]`: 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]. | `<DIR>`: 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`). | `<shell_name>`: 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. | `<image_path>`: Path to image. Either `<outpath>` (`-` value to print to stdout) or `--save` to save for use within `tinty` | `tinty generate-completion bash` |
Expand Down
11 changes: 6 additions & 5 deletions THIRD_PARTY_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 &quot;New&quot; or &quot;Revised&quot; License (4)
- BSD 2-Clause &quot;Simplified&quot; License (3)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,18 @@ pub fn build_cli() -> Command {
.required(true)),
)
.subcommand(
Command::new("info").about(format!("Shows scheme colors for all schemes matching <scheme_system>-<scheme_name> (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 <scheme_system>-<scheme_name> (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")
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ fn main() -> Result<()> {
};
}
Some(("info", sub_matches)) => {
let is_custom = sub_matches
.get_one::<bool>("custom-schemes")
.map(|b| b.to_owned())
.unwrap_or(false);
let scheme_name_option = sub_matches.get_one::<String>("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)?;
Expand Down
40 changes: 25 additions & 15 deletions src/operations/info.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -239,22 +239,32 @@ fn print_all_schemes(files: Vec<PathBuf>) -> 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<PathBuf> = files_entries
.filter_map(|entry| entry.ok().map(|e| e.path()))
.collect();
Expand All @@ -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())),
);
}
Expand Down
20 changes: 15 additions & 5 deletions src/operations/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit 27d92f8

Please sign in to comment.