mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Add a --color
flag (#3060)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
79a41aedbe
commit
4bf16d7acb
@ -2,7 +2,7 @@ use std::fmt::{self, Display, Formatter};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::builder::ValueParser;
|
use clap::builder::ValueParser;
|
||||||
use clap::{ArgAction, Args, Parser, Subcommand, ValueEnum};
|
use clap::{ArgAction, Args, ColorChoice, Parser, Subcommand, ValueEnum};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
|
||||||
/// The character typically used to separate path components
|
/// The character typically used to separate path components
|
||||||
@ -17,6 +17,18 @@ pub struct CliArguments {
|
|||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Command,
|
pub command: Command,
|
||||||
|
|
||||||
|
/// Set when to use color.
|
||||||
|
/// auto = use color if a capable terminal is detected
|
||||||
|
#[clap(
|
||||||
|
long,
|
||||||
|
value_name = "WHEN",
|
||||||
|
require_equals = true,
|
||||||
|
num_args = 0..=1,
|
||||||
|
default_value = "auto",
|
||||||
|
default_missing_value = "always",
|
||||||
|
)]
|
||||||
|
pub color: ColorChoice,
|
||||||
|
|
||||||
/// Path to a custom CA certificate to use when making network requests.
|
/// Path to a custom CA certificate to use when making network requests.
|
||||||
#[clap(long = "cert", env = "TYPST_CERT")]
|
#[clap(long = "cert", env = "TYPST_CERT")]
|
||||||
pub cert: Option<PathBuf>,
|
pub cert: Option<PathBuf>,
|
||||||
|
@ -68,10 +68,16 @@ fn print_error(msg: &str) -> io::Result<()> {
|
|||||||
|
|
||||||
/// Get stderr with color support if desirable.
|
/// Get stderr with color support if desirable.
|
||||||
fn color_stream() -> termcolor::StandardStream {
|
fn color_stream() -> termcolor::StandardStream {
|
||||||
termcolor::StandardStream::stderr(if std::io::stderr().is_terminal() {
|
termcolor::StandardStream::stderr(match ARGS.color {
|
||||||
ColorChoice::Auto
|
clap::ColorChoice::Auto => {
|
||||||
} else {
|
if std::io::stderr().is_terminal() {
|
||||||
ColorChoice::Never
|
ColorChoice::Auto
|
||||||
|
} else {
|
||||||
|
ColorChoice::Never
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clap::ColorChoice::Always => ColorChoice::Always,
|
||||||
|
clap::ColorChoice::Never => ColorChoice::Never,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user