-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Remove asni term dependency #4116
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3540c6d
Migrated ansi_term use to termcolor
jsouto18 2fdfd8c
Migrated ansi_term use to termcolor
jsouto18 ba1eb63
Merge
jsouto18 763731e
Fixed termial not reseting after color print
jsouto18 561af27
Ansi enable for windows 10
jsouto18 bea6efb
More explicit comment
jsouto18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
use ansi_term::Color::Black; | ||
use ansi_term::Color::Fixed; | ||
use ansi_term::Color::Red; | ||
use ansi_term::Color::White; | ||
use ansi_term::Style; | ||
use regex::Regex; | ||
use std::env; | ||
use std::fmt; | ||
use std::io::Write; | ||
use termcolor::Color::{Ansi256, Black, Red, White}; | ||
use termcolor::{Ansi, ColorSpec, WriteColor}; | ||
|
||
#[cfg(windows)] | ||
use termcolor::{BufferWriter, ColorChoice}; | ||
|
||
lazy_static! { | ||
// STRIP_ANSI_RE and strip_ansi_codes are lifted from the "console" crate. | ||
// Copyright 2017 Armin Ronacher <[email protected]>. MIT License. | ||
static ref STRIP_ANSI_RE: Regex = Regex::new( | ||
r"[\x1b\x9b][\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]" | ||
).unwrap(); | ||
static ref NO_COLOR: bool = { | ||
env::var_os("NO_COLOR").is_some() | ||
}; | ||
// STRIP_ANSI_RE and strip_ansi_codes are lifted from the "console" crate. | ||
// Copyright 2017 Armin Ronacher <[email protected]>. MIT License. | ||
static ref STRIP_ANSI_RE: Regex = Regex::new( | ||
r"[\x1b\x9b][\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]" | ||
).unwrap(); | ||
static ref NO_COLOR: bool = { | ||
env::var_os("NO_COLOR").is_some() | ||
}; | ||
} | ||
|
||
/// Helper function to strip ansi codes. | ||
|
@@ -28,68 +29,66 @@ pub fn use_color() -> bool { | |
!(*NO_COLOR) | ||
} | ||
|
||
pub fn red_bold(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
#[cfg(windows)] | ||
pub fn enable_ansi() { | ||
BufferWriter::stdout(ColorChoice::AlwaysAnsi); | ||
} | ||
|
||
fn style(s: &str, colorspec: ColorSpec) -> impl fmt::Display { | ||
let mut v = Vec::new(); | ||
let mut ansi_writer = Ansi::new(&mut v); | ||
if use_color() { | ||
style = style.bold().fg(Red); | ||
ansi_writer.set_color(&colorspec).unwrap(); | ||
} | ||
style.paint(s) | ||
ansi_writer.write_all(s.as_bytes()).unwrap(); | ||
ansi_writer.reset().unwrap(); | ||
String::from_utf8_lossy(&v).into_owned() | ||
} | ||
|
||
pub fn red_bold(s: String) -> impl fmt::Display { | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_fg(Some(Red)).set_bold(true); | ||
style(&s, style_spec) | ||
} | ||
|
||
pub fn italic_bold(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
if use_color() { | ||
style = style.italic().bold(); | ||
} | ||
style.paint(s) | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_bold(true).set_italic(true); | ||
style(&s, style_spec) | ||
} | ||
|
||
pub fn black_on_white(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
if use_color() { | ||
style = style.on(White).fg(Black); | ||
} | ||
style.paint(s) | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_bg(Some(White)).set_fg(Some(Black)); | ||
style(&s, style_spec) | ||
} | ||
|
||
pub fn yellow(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
if use_color() { | ||
// matches TypeScript's ForegroundColorEscapeSequences.Yellow | ||
style = style.fg(Fixed(11)); | ||
} | ||
style.paint(s) | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_fg(Some(Ansi256(11))); | ||
style(&s, style_spec) | ||
} | ||
|
||
pub fn cyan(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
if use_color() { | ||
// matches TypeScript's ForegroundColorEscapeSequences.Cyan | ||
style = style.fg(Fixed(14)); | ||
} | ||
style.paint(s) | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_fg(Some(Ansi256(14))); | ||
style(&s, style_spec) | ||
} | ||
|
||
pub fn red(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
if use_color() { | ||
style = style.fg(Red); | ||
} | ||
style.paint(s) | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_fg(Some(Red)); | ||
style(&s, style_spec) | ||
} | ||
|
||
pub fn green(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
if use_color() { | ||
style = style.fg(Fixed(10)).bold(); | ||
} | ||
style.paint(s) | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_fg(Some(Ansi256(10))); | ||
style(&s, style_spec) | ||
} | ||
|
||
pub fn bold(s: String) -> impl fmt::Display { | ||
let mut style = Style::new(); | ||
if use_color() { | ||
style = style.bold(); | ||
} | ||
style.paint(s) | ||
let mut style_spec = ColorSpec::new(); | ||
style_spec.set_bold(true); | ||
style(&s, style_spec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍