From da3aa4e2fdbe905bf74aea2922297206af3277a8 Mon Sep 17 00:00:00 2001 From: Constantin Nickel Date: Thu, 23 Mar 2023 10:47:38 +0100 Subject: [PATCH] Use `nu-ansi-term` instead of `ansi_term` The `nu-ansi-term` crate is a fork of `ansi_term` which is maintained by the Nushell project. --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- src/bin/bat/app.rs | 2 +- src/bin/bat/main.rs | 4 ++-- src/decorations.rs | 2 +- src/error.rs | 2 +- src/macros.rs | 2 +- src/printer.rs | 4 ++-- src/terminal.rs | 8 ++++---- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4ab9190..b41ae49c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,15 +26,6 @@ dependencies = [ "rgb", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "assert_cmd" version = "2.0.8" @@ -77,7 +68,6 @@ name = "bat" version = "0.22.1" dependencies = [ "ansi_colours", - "ansi_term", "assert_cmd", "atty", "bincode", @@ -95,6 +85,7 @@ dependencies = [ "globset", "grep-cli", "nix", + "nu-ansi-term", "once_cell", "path_abs", "plist", @@ -747,6 +738,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "nu-ansi-term" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df031e117bca634c262e9bd3173776844b6c17a90b3741c9163663b4385af76" +dependencies = [ + "windows-sys 0.45.0", +] + [[package]] name = "num-traits" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 4a73f36b..ff679e3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ regex-fancy = ["syntect/regex-fancy"] # Use the rust-only "fancy-regex" engine [dependencies] atty = { version = "0.2.14", optional = true } -ansi_term = "^0.12.1" +nu-ansi-term = "0.47.0" ansi_colours = "^1.2" bincode = "1.0" console = "0.15.5" diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index fb408d9b..0dbb91c2 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -38,7 +38,7 @@ pub struct App { impl App { pub fn new() -> Result { #[cfg(windows)] - let _ = ansi_term::enable_ansi_support(); + let _ = nu_ansi_term::enable_ansi_support(); let interactive_output = atty::is(Stream::Stdout); diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 7a5fb27c..65eb6f53 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -14,8 +14,8 @@ use std::io::{BufReader, Write}; use std::path::Path; use std::process; -use ansi_term::Colour::Green; -use ansi_term::Style; +use nu_ansi_term::Color::Green; +use nu_ansi_term::Style; use crate::{ app::App, diff --git a/src/decorations.rs b/src/decorations.rs index 2647b0f8..d3ed9b34 100644 --- a/src/decorations.rs +++ b/src/decorations.rs @@ -1,7 +1,7 @@ #[cfg(feature = "git")] use crate::diff::LineChange; use crate::printer::{Colors, InteractivePrinter}; -use ansi_term::Style; +use nu_ansi_term::Style; #[derive(Debug, Clone)] pub(crate) struct DecorationText { diff --git a/src/error.rs b/src/error.rs index f9845138..af0b9121 100644 --- a/src/error.rs +++ b/src/error.rs @@ -43,7 +43,7 @@ impl From for Error { pub type Result = std::result::Result; pub fn default_error_handler(error: &Error, output: &mut dyn Write) { - use ansi_term::Colour::Red; + use nu_ansi_term::Color::Red; match error { Error::Io(ref io_error) if io_error.kind() == ::std::io::ErrorKind::BrokenPipe => { diff --git a/src/macros.rs b/src/macros.rs index beb63ea7..e3b01b8c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,7 +1,7 @@ #[macro_export] macro_rules! bat_warning { ($($arg:tt)*) => ({ - use ansi_term::Colour::Yellow; + use nu_ansi_term::Color::Yellow; eprintln!("{}: {}", Yellow.paint("[bat warning]"), format!($($arg)*)); }) } diff --git a/src/printer.rs b/src/printer.rs index 6ec96cd4..d46b23d1 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -1,8 +1,8 @@ use std::io::Write; use std::vec::Vec; -use ansi_term::Colour::{Fixed, Green, Red, Yellow}; -use ansi_term::Style; +use nu_ansi_term::Color::{Fixed, Green, Red, Yellow}; +use nu_ansi_term::Style; use bytesize::ByteSize; diff --git a/src/terminal.rs b/src/terminal.rs index b7159347..28808e3e 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -1,9 +1,9 @@ -use ansi_term::Color::{self, Fixed, RGB}; -use ansi_term::{self, Style}; +use nu_ansi_term::Color::{self, Fixed, Rgb}; +use nu_ansi_term::{self, Style}; use syntect::highlighting::{self, FontStyle}; -pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> Option { +pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> Option { if color.a == 0 { // Themes can specify one of the user-configurable terminal colors by // encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set @@ -38,7 +38,7 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> Option