Skip to content

Commit

Permalink
Bump yansi from 0.5.1 to 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
acuteenvy committed Apr 5, 2024
1 parent 7669fc0 commit 07128a3
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 84 deletions.
38 changes: 11 additions & 27 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 @@ -22,7 +22,7 @@ ring = "0.17.8"
serde = { version = "1.0.197", features = ["derive"] }
toml = "0.8.12"
ureq = { version = "2.9.6", default-features = false, features = ["tls"] }
yansi = "0.5.1"
yansi = "1.0.1"
zip = { version = "0.6.6", default-features = false, features = ["deflate"] }

[dev-dependencies]
Expand Down
33 changes: 14 additions & 19 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::path::{Path, PathBuf};
use std::time::Duration;

use once_cell::unsync::OnceCell;
use yansi::Color::{Green, Red};
use yansi::Paint;
use zip::ZipArchive;

Expand Down Expand Up @@ -60,9 +59,9 @@ impl<'a> Cache<'a> {
#[allow(clippy::cast_precision_loss)]
let dl_kib = buf.len() as f64 / 1024.0;
if dl_kib < 1024.0 {
info_end!("{:.02} KiB", Paint::new(dl_kib).fg(Green).bold());
info_end!("{:.02} KiB", dl_kib.green().bold());
} else {
info_end!("{:.02} MiB", Paint::new(dl_kib / 1024.0).fg(Green).bold());
info_end!("{:.02} MiB", (dl_kib / 1024.0).green().bold());
}

Ok(buf)
Expand Down Expand Up @@ -107,15 +106,15 @@ impl<'a> Cache<'a> {
let actual_sum = util::sha256_hexdigest(&archive);

if sum != &actual_sum {
info_end!(" {}", Paint::new("FAILED").fg(Red).bold());
info_end!(" {}", "FAILED".red().bold());
return Err(Error::new(format!(
"SHA256 sum mismatch!\n\
expected : {sum}\n\
got : {actual_sum}"
)));
}

info_end!(" {}", Paint::new("OK").fg(Green).bold());
info_end!(" {}", "OK".green().bold());

langdir_archive_map.insert(lang_dir, ZipArchive::new(Cursor::new(archive))?);
}
Expand Down Expand Up @@ -199,8 +198,8 @@ impl<'a> Cache<'a> {

info_end!(
" {} pages, {} new",
Paint::new(n_downloaded).fg(Green).bold(),
Paint::new(n_new).fg(Green).bold()
n_downloaded.green().bold(),
n_new.green().bold()
);

Ok(())
Expand Down Expand Up @@ -246,8 +245,8 @@ impl<'a> Cache<'a> {

infoln!(
"cache update successful (total: {} pages, {} new).",
Paint::new(all_downloaded).fg(Green).bold(),
Paint::new(all_new).fg(Green).bold(),
all_downloaded.green().bold(),
all_new.green().bold(),
);

Ok(())
Expand Down Expand Up @@ -303,7 +302,7 @@ impl<'a> Cache<'a> {
if platforms.iter().all(|x| x != platform) {
Err(Error::new(format!(
"platform '{platform}' does not exist.\n{} {}.",
Paint::new("Possible values:").bold(),
"Possible values:".bold(),
platforms.join(", ".as_ref()).to_string_lossy()
)))
} else {
Expand Down Expand Up @@ -506,8 +505,8 @@ impl<'a> Cache<'a> {
writeln!(
stdout,
"Cache: {} (last update: {} ago)",
Paint::new(self.dir.display()).fg(Red),
Paint::new(util::duration_fmt(age)).fg(Green).bold()
self.dir.display().red(),
util::duration_fmt(age).green().bold()
)?;

if cfg.cache.auto_update {
Expand All @@ -516,7 +515,7 @@ impl<'a> Cache<'a> {
writeln!(
stdout,
"Automatic update in {}",
Paint::new(util::duration_fmt(age_diff)).fg(Green).bold()
util::duration_fmt(age_diff).green().bold()
)?;
} else {
writeln!(stdout, "Automatic updates are disabled")?;
Expand All @@ -529,15 +528,11 @@ impl<'a> Cache<'a> {
stdout,
// Language codes are at most 5 characters (ll_CC).
"{lang:5} : {}",
Paint::new(n).fg(Green).bold(),
n.green().bold(),
)?;
}

writeln!(
stdout,
"total : {} pages",
Paint::new(n_total).fg(Green).bold(),
)?;
writeln!(stdout, "total : {} pages", n_total.green().bold())?;

Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ impl From<OutputColor> for yansi::Color {
OutputColor::Magenta => Color::Magenta,
OutputColor::Cyan => Color::Cyan,
OutputColor::White => Color::White,
OutputColor::Default => Color::Default,
OutputColor::Default => Color::Primary,
OutputColor::Color256(c) => Color::Fixed(c),
OutputColor::Rgb(rgb) => Color::RGB(rgb[0], rgb[1], rgb[2]),
OutputColor::Rgb(rgb) => Color::Rgb(rgb[0], rgb[1], rgb[2]),
}
}
}
Expand All @@ -60,7 +60,7 @@ pub struct OutputStyle {

impl From<OutputStyle> for yansi::Style {
fn from(s: OutputStyle) -> Self {
let mut style = Style::new(s.color.into()).bg(s.background.into());
let mut style = Style::new().fg(s.color.into()).bg(s.background.into());

if s.bold {
style = style.bold();
Expand All @@ -72,10 +72,10 @@ impl From<OutputStyle> for yansi::Style {
style = style.underline();
}
if s.dim {
style = style.dimmed();
style = style.dim();
}
if s.strikethrough {
style = style.strikethrough();
style = style.strike();
}

style
Expand Down
13 changes: 4 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::path::Path;
use std::process::ExitCode;
use std::result::Result as StdResult;

use yansi::Color::Red;
use yansi::Paint;

pub enum ErrorKind {
Expand Down Expand Up @@ -67,7 +66,7 @@ impl Error {
"'{}' is not a valid tldr page. (line {}):\n\n {}",
page_path.display(),
i,
Paint::new(line).bold(),
line.bold(),
))
.kind(ErrorKind::ParsePage)
}
Expand All @@ -83,8 +82,8 @@ impl Error {
{}\n\
or document it yourself and create a pull request here:\n\
{}",
Paint::new("https://github.com/tldr-pages/tldr/issues").bold(),
Paint::new("https://github.com/tldr-pages/tldr/pulls").bold()
"https://github.com/tldr-pages/tldr/issues".bold(),
"https://github.com/tldr-pages/tldr/pulls".bold()
)
}

Expand All @@ -95,11 +94,7 @@ impl Error {

/// Print the error message to stderr and return an appropriate `ExitCode`.
pub fn exit_code(self) -> ExitCode {
let _ = writeln!(
io::stderr(),
"{} {self}",
Paint::new("error:").fg(Red).bold()
);
let _ = writeln!(io::stderr(), "{} {self}", "error:".red().bold());

match self.kind {
ErrorKind::Other | ErrorKind::Io => 1,
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::process::ExitCode;
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};

use clap::Parser;
use yansi::Color::Green;
use yansi::Paint;

use crate::args::Cli;
Expand Down Expand Up @@ -77,7 +76,7 @@ fn run() -> Result<()> {
cache.update(&cfg.cache.mirror, &mut cfg.cache.languages)?;
} else if cfg.cache.auto_update && cache.age()? > cfg.cache_max_age() {
let age = util::duration_fmt(cache.age()?.as_secs());
let age = Paint::new(age).fg(Green).bold();
let age = age.green().bold();

if cli.offline {
warnln!(
Expand Down

0 comments on commit 07128a3

Please sign in to comment.