mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Merge pull request #5636 from gibfahn/styles_const
refactor(styles): make styles example use a const
This commit is contained in:
commit
6fb49d08bb
4 changed files with 14 additions and 14 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -101,9 +101,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle"
|
name = "anstyle"
|
||||||
version = "1.0.7"
|
version = "1.0.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
|
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-parse"
|
name = "anstyle-parse"
|
||||||
|
@ -1432,7 +1432,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
|
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"windows-targets 0.48.5",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -63,7 +63,7 @@ clap_lex = { path = "../clap_lex", version = "0.7.0" }
|
||||||
unicase = { version = "2.6.0", optional = true }
|
unicase = { version = "2.6.0", optional = true }
|
||||||
strsim = { version = "0.11.0", optional = true }
|
strsim = { version = "0.11.0", optional = true }
|
||||||
anstream = { version = "0.6.7", optional = true }
|
anstream = { version = "0.6.7", optional = true }
|
||||||
anstyle = "1.0.0"
|
anstyle = "1.0.8"
|
||||||
terminal_size = { version = "0.3.0", optional = true }
|
terminal_size = { version = "0.3.0", optional = true }
|
||||||
backtrace = { version = "0.3.73", optional = true }
|
backtrace = { version = "0.3.73", optional = true }
|
||||||
unicode-width = { version = "0.1.9", optional = true }
|
unicode-width = { version = "0.1.9", optional = true }
|
||||||
|
|
|
@ -1199,13 +1199,13 @@ impl Command {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use clap_builder as clap;
|
/// # use clap_builder as clap;
|
||||||
/// # use clap::{Command, ColorChoice, builder::styling};
|
/// # use clap::{Command, ColorChoice, builder::styling};
|
||||||
/// let styles = styling::Styles::styled()
|
/// const STYLES: styling::Styles = styling::Styles::styled()
|
||||||
/// .header(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
|
/// .header(styling::AnsiColor::Green.on_default().bold())
|
||||||
/// .usage(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
|
/// .usage(styling::AnsiColor::Green.on_default().bold())
|
||||||
/// .literal(styling::AnsiColor::Blue.on_default() | styling::Effects::BOLD)
|
/// .literal(styling::AnsiColor::Blue.on_default().bold())
|
||||||
/// .placeholder(styling::AnsiColor::Cyan.on_default());
|
/// .placeholder(styling::AnsiColor::Cyan.on_default());
|
||||||
/// Command::new("myprog")
|
/// Command::new("myprog")
|
||||||
/// .styles(styles)
|
/// .styles(STYLES)
|
||||||
/// .get_matches();
|
/// .get_matches();
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(feature = "color")]
|
#[cfg(feature = "color")]
|
||||||
|
|
|
@ -15,12 +15,12 @@ fn main() {
|
||||||
#[cfg(feature = "color")]
|
#[cfg(feature = "color")]
|
||||||
{
|
{
|
||||||
use clap::builder::styling;
|
use clap::builder::styling;
|
||||||
let styles = styling::Styles::styled()
|
const STYLES: styling::Styles = styling::Styles::styled()
|
||||||
.header(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
|
.header(styling::AnsiColor::Green.on_default().bold())
|
||||||
.usage(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
|
.usage(styling::AnsiColor::Green.on_default().bold())
|
||||||
.literal(styling::AnsiColor::Blue.on_default() | styling::Effects::BOLD)
|
.literal(styling::AnsiColor::Blue.on_default().bold())
|
||||||
.placeholder(styling::AnsiColor::Cyan.on_default());
|
.placeholder(styling::AnsiColor::Cyan.on_default());
|
||||||
cmd = cmd.styles(styles);
|
cmd = cmd.styles(STYLES);
|
||||||
}
|
}
|
||||||
cmd.get_matches();
|
cmd.get_matches();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue