mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-09 09:49:10 +02:00
Upgrade yansi: 0.5.1 -> 1.0.1 (#389)
- Adapt to `thing.paint(style)` API; was `style.paint(thing)` - Remove `yansi::Paint::enable_windows_ascii()` in style usage decision; removed in yansi commit b186eb5bfb, which introduced "automatic" support for Windows: "If support is not available, styling is disabled and no styling sequences are emitted", fitting the `Auto` option - Respect `--color=always` even if we know it won't work --------- Co-authored-by: Niklas Mohrin <dev@niklasmohrin.de>
This commit is contained in:
parent
d44613cf59
commit
fb7492b0b5
6 changed files with 17 additions and 20 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -2009,9 +2009,9 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
|
|||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "0.5.1"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ serde = "1.0.21"
|
|||
serde_derive = "1.0.21"
|
||||
toml = "0.8.19"
|
||||
walkdir = "2.0.1"
|
||||
yansi = "0.5"
|
||||
yansi = "1"
|
||||
zip = { version = "2.1.6", default-features = false, features = ["deflate"] }
|
||||
|
||||
[target.'cfg(not(windows))'.dependencies]
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ impl From<RawColor> for Color {
|
|||
RawColor::Cyan => Self::Cyan,
|
||||
RawColor::White => Self::White,
|
||||
RawColor::Ansi(num) => Self::Fixed(num),
|
||||
RawColor::Rgb { r, g, b } => Self::RGB(r, g, b),
|
||||
RawColor::Rgb { r, g, b } => Self::Rgb(r, g, b),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
src/main.rs
14
src/main.rs
|
|
@ -249,20 +249,16 @@ fn main() {
|
|||
let args = Cli::parse();
|
||||
|
||||
// Determine the usage of styles
|
||||
#[cfg(target_os = "windows")]
|
||||
let ansi_support = yansi::Paint::enable_windows_ascii();
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let ansi_support = true;
|
||||
let enable_styles = match args.color.unwrap_or_default() {
|
||||
// Attempt to use styling if instructed
|
||||
ColorOptions::Always => true,
|
||||
ColorOptions::Always => {
|
||||
yansi::enable(); // disable yansi's automatic detection for ANSI support on Windows
|
||||
true
|
||||
}
|
||||
// Enable styling if:
|
||||
// * There is `ansi_support`
|
||||
// * NO_COLOR env var isn't set: https://no-color.org/
|
||||
// * The output stream is stdout (not being piped)
|
||||
ColorOptions::Auto => {
|
||||
ansi_support && env::var_os("NO_COLOR").is_none() && io::stdout().is_terminal()
|
||||
}
|
||||
ColorOptions::Auto => env::var_os("NO_COLOR").is_none() && io::stdout().is_terminal(),
|
||||
// Disable styling
|
||||
ColorOptions::Never => false,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
use std::io::{self, BufRead, Write};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use yansi::Paint;
|
||||
|
||||
use crate::{
|
||||
cache::PageLookupResult,
|
||||
|
|
@ -86,11 +87,11 @@ fn print_snippet(
|
|||
use PageSnippet::*;
|
||||
|
||||
match snip {
|
||||
CommandName(s) => write!(writer, "{}", style.command_name.paint(s)),
|
||||
Variable(s) => write!(writer, "{}", style.example_variable.paint(s)),
|
||||
NormalCode(s) => write!(writer, "{}", style.example_code.paint(s)),
|
||||
Description(s) => writeln!(writer, " {}", style.description.paint(s)),
|
||||
Text(s) => writeln!(writer, " {}", style.example_text.paint(s)),
|
||||
CommandName(s) => write!(writer, "{}", s.paint(style.command_name)),
|
||||
Variable(s) => write!(writer, "{}", s.paint(style.example_variable)),
|
||||
NormalCode(s) => write!(writer, "{}", s.paint(style.example_code)),
|
||||
Description(s) => writeln!(writer, " {}", s.paint(style.description)),
|
||||
Text(s) => writeln!(writer, " {}", s.paint(style.example_text)),
|
||||
Linebreak => writeln!(writer),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use yansi::Color;
|
||||
use yansi::{Color, Paint};
|
||||
|
||||
/// Print a warning to stderr. If `enable_styles` is true, then a yellow
|
||||
/// message will be printed.
|
||||
|
|
@ -14,7 +14,7 @@ pub fn print_error(enable_styles: bool, error: &anyhow::Error) {
|
|||
|
||||
fn print_msg(enable_styles: bool, message: &str, prefix: &'static str, color: Color) {
|
||||
if enable_styles {
|
||||
eprintln!("{}{}", color.paint(prefix), color.paint(message));
|
||||
eprintln!("{}{}", prefix.paint(color), message.paint(color));
|
||||
} else {
|
||||
eprintln!("{message}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue