Skip to content

Commit

Permalink
new: simplified --color option (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus authored Apr 30, 2024
1 parent c0ca897 commit 17544f2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [".", "crate/encstr"]
[workspace.package]
repository = "https://github.com/pamburus/hl"
authors = ["Pavel Ivanov <mr.pavel.ivanov@gmail.com>"]
version = "0.28.1-alpha.3"
version = "0.28.1-alpha.4"
edition = "2021"
license = "MIT"

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,7 @@ Arguments:
[FILE]... Files to process

Options:
--color <COLOR> Color output options [env: HL_COLOR=] [default: auto] [possible values: auto, always, never]
-c Handful alias for --color=always, overrides --color option
-c, --color [<COLOR>] Color output options [env: HL_COLOR=] [default: auto] [possible values: auto, always, never]
--paging <PAGING> Output paging options [env: HL_PAGING=] [default: auto] [possible values: auto, always, never]
-P Handful alias for --paging=never, overrides --paging option
--theme <THEME> Color theme [env: HL_THEME=] [default: universal]
Expand Down
6 changes: 1 addition & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ use crate::{
#[clap(version, disable_help_flag = true)]
pub struct Opt {
/// Color output options.
#[arg(long, default_value = "auto", env = "HL_COLOR", overrides_with = "color")]
#[arg(long, short, default_value = "auto", env = "HL_COLOR", overrides_with = "color", default_missing_value = "always", num_args = 0..=1)]
#[arg(value_enum)]
pub color: ColorOption,

/// Handful alias for --color=always, overrides --color option.
#[arg(short)]
pub color_always: bool,

/// Output paging options.
#[arg(long, default_value = "auto", env = "HL_PAGING", overrides_with = "paging")]
#[arg(value_enum)]
Expand Down
7 changes: 1 addition & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ fn run() -> Result<()> {
};

// Configure color scheme.
let color = if opt.color_always {
cli::ColorOption::Always
} else {
opt.color
};
let use_colors = match color {
let use_colors = match opt.color {
cli::ColorOption::Auto => stdout().is_terminal() && color_supported,
cli::ColorOption::Always => true,
cli::ColorOption::Never => false,
Expand Down

0 comments on commit 17544f2

Please sign in to comment.