Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade yansi: 0.5.1 -> 1.0.1 #389

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Comment on lines -252 to -253
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose by https://docs.rs/yansi/1.0.1/yansi/index.html#windows we can omit this. Fair enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the commit message explained ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't see that, I'll make sure to include it in the merged commit

#[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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nc7s Sorry to bother you again, but how do you feel about this change I added? It should now be exactly the previous behavior right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know enough to judge this, from a glance LGTM?

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,
};
Expand Down
11 changes: 6 additions & 5 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::io::{self, BufRead, Write};

use anyhow::{Context, Result};
use yansi::Paint;

use crate::{
cache::PageLookupResult,
Expand Down Expand Up @@ -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),
}
}
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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}");
}
Expand Down