mirror of
https://github.com/denoland/deno.git
synced 2025-01-09 15:48:16 -05:00
Remove ansi_term dependency (#4106)
This commit is contained in:
parent
c080d7fba3
commit
c250778704
7 changed files with 48 additions and 67 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -433,7 +433,6 @@ dependencies = [
|
||||||
name = "deno"
|
name = "deno"
|
||||||
version = "0.34.0"
|
version = "0.34.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
|
||||||
"atty",
|
"atty",
|
||||||
"base64 0.11.0",
|
"base64 0.11.0",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
|
|
@ -26,7 +26,6 @@ deno_typescript = { path = "../deno_typescript", version = "0.34.0" }
|
||||||
deno_core = { path = "../core", version = "0.34.0" }
|
deno_core = { path = "../core", version = "0.34.0" }
|
||||||
deno_typescript = { path = "../deno_typescript", version = "0.34.0" }
|
deno_typescript = { path = "../deno_typescript", version = "0.34.0" }
|
||||||
|
|
||||||
ansi_term = "0.11.0"
|
|
||||||
atty = "0.2.13"
|
atty = "0.2.13"
|
||||||
base64 = "0.11.0"
|
base64 = "0.11.0"
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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 regex::Regex;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::io::Write;
|
||||||
|
use termcolor::Color::{Ansi256, Black, Red, White};
|
||||||
|
use termcolor::{Ansi, ColorSpec, WriteColor};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
// STRIP_ANSI_RE and strip_ansi_codes are lifted from the "console" crate.
|
// STRIP_ANSI_RE and strip_ansi_codes are lifted from the "console" crate.
|
||||||
// Copyright 2017 Armin Ronacher <armin.ronacher@active-4.com>. MIT License.
|
// Copyright 2017 Armin Ronacher <armin.ronacher@active-4.com>. MIT License.
|
||||||
static ref STRIP_ANSI_RE: Regex = Regex::new(
|
static ref STRIP_ANSI_RE: Regex = Regex::new(
|
||||||
r"[\x1b\x9b][\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]"
|
r"[\x1b\x9b][\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
static ref NO_COLOR: bool = {
|
static ref NO_COLOR: bool = {
|
||||||
env::var_os("NO_COLOR").is_some()
|
env::var_os("NO_COLOR").is_some()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to strip ansi codes.
|
/// Helper function to strip ansi codes.
|
||||||
|
@ -28,68 +26,60 @@ pub fn use_color() -> bool {
|
||||||
!(*NO_COLOR)
|
!(*NO_COLOR)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn red_bold(s: String) -> impl fmt::Display {
|
fn style(s: &str, colorspec: ColorSpec) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut v = Vec::new();
|
||||||
|
let mut ansi_writer = Ansi::new(&mut v);
|
||||||
if use_color() {
|
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();
|
||||||
|
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 {
|
pub fn italic_bold(s: String) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut style_spec = ColorSpec::new();
|
||||||
if use_color() {
|
style_spec.set_bold(true).set_italic(true);
|
||||||
style = style.italic().bold();
|
style(&s, style_spec)
|
||||||
}
|
|
||||||
style.paint(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn black_on_white(s: String) -> impl fmt::Display {
|
pub fn black_on_white(s: String) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut style_spec = ColorSpec::new();
|
||||||
if use_color() {
|
style_spec.set_bg(Some(White)).set_fg(Some(Black));
|
||||||
style = style.on(White).fg(Black);
|
style(&s, style_spec)
|
||||||
}
|
|
||||||
style.paint(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn yellow(s: String) -> impl fmt::Display {
|
pub fn yellow(s: String) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut style_spec = ColorSpec::new();
|
||||||
if use_color() {
|
style_spec.set_fg(Some(Ansi256(11)));
|
||||||
// matches TypeScript's ForegroundColorEscapeSequences.Yellow
|
style(&s, style_spec)
|
||||||
style = style.fg(Fixed(11));
|
|
||||||
}
|
|
||||||
style.paint(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cyan(s: String) -> impl fmt::Display {
|
pub fn cyan(s: String) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut style_spec = ColorSpec::new();
|
||||||
if use_color() {
|
style_spec.set_fg(Some(Ansi256(14)));
|
||||||
// matches TypeScript's ForegroundColorEscapeSequences.Cyan
|
style(&s, style_spec)
|
||||||
style = style.fg(Fixed(14));
|
|
||||||
}
|
|
||||||
style.paint(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn red(s: String) -> impl fmt::Display {
|
pub fn red(s: String) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut style_spec = ColorSpec::new();
|
||||||
if use_color() {
|
style_spec.set_fg(Some(Red));
|
||||||
style = style.fg(Red);
|
style(&s, style_spec)
|
||||||
}
|
|
||||||
style.paint(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn green(s: String) -> impl fmt::Display {
|
pub fn green(s: String) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut style_spec = ColorSpec::new();
|
||||||
if use_color() {
|
style_spec.set_fg(Some(Ansi256(10)));
|
||||||
style = style.fg(Fixed(10)).bold();
|
style(&s, style_spec)
|
||||||
}
|
|
||||||
style.paint(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bold(s: String) -> impl fmt::Display {
|
pub fn bold(s: String) -> impl fmt::Display {
|
||||||
let mut style = Style::new();
|
let mut style_spec = ColorSpec::new();
|
||||||
if use_color() {
|
style_spec.set_bold(true);
|
||||||
style = style.bold();
|
style(&s, style_spec)
|
||||||
}
|
|
||||||
style.paint(s)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,9 +388,6 @@ async fn test_command(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
#[cfg(windows)]
|
|
||||||
ansi_term::enable_ansi_support().ok(); // For Windows 10
|
|
||||||
|
|
||||||
log::set_logger(&LOGGER).unwrap();
|
log::set_logger(&LOGGER).unwrap();
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let flags = flags::flags_from_vec(args);
|
let flags = flags::flags_from_vec(args);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
use crate::colors;
|
||||||
use crate::flags::DenoFlags;
|
use crate::flags::DenoFlags;
|
||||||
use crate::op_error::OpError;
|
use crate::op_error::OpError;
|
||||||
use ansi_term::Style;
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
use atty;
|
use atty;
|
||||||
use log;
|
use log;
|
||||||
|
@ -305,7 +305,7 @@ fn permission_prompt(message: &str) -> bool {
|
||||||
PERMISSION_EMOJI, message
|
PERMISSION_EMOJI, message
|
||||||
);
|
);
|
||||||
// print to stderr so that if deno is > to a file this is still displayed.
|
// print to stderr so that if deno is > to a file this is still displayed.
|
||||||
eprint!("{}", Style::new().bold().paint(msg));
|
eprint!("{}", colors::bold(msg));
|
||||||
loop {
|
loop {
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
@ -321,7 +321,7 @@ fn permission_prompt(message: &str) -> bool {
|
||||||
// If we don't get a recognized option try again.
|
// If we don't get a recognized option try again.
|
||||||
let msg_again =
|
let msg_again =
|
||||||
format!("Unrecognized option '{}' [g/d (g = grant, d = deny)] ", ch);
|
format!("Unrecognized option '{}' [g/d (g = grant, d = deny)] ", ch);
|
||||||
eprint!("{}", Style::new().bold().paint(msg_again));
|
eprint!("{}", colors::bold(msg_again));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -352,9 +352,7 @@ fn log_perm_access(message: &str) {
|
||||||
if log_enabled!(log::Level::Info) {
|
if log_enabled!(log::Level::Info) {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}",
|
"{}",
|
||||||
Style::new()
|
colors::bold(format!("{}️ Granted {}", PERMISSION_EMOJI, message))
|
||||||
.bold()
|
|
||||||
.paint(format!("{}️ Granted {}", PERMISSION_EMOJI, message))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
std/encoding/testdata/cargo.toml
vendored
1
std/encoding/testdata/cargo.toml
vendored
|
@ -23,7 +23,6 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deno_core = { path = "./core" }
|
deno_core = { path = "./core" }
|
||||||
|
|
||||||
ansi_term = "0.11.0"
|
|
||||||
atty = "0.2.11"
|
atty = "0.2.11"
|
||||||
dirs = "1.0.5"
|
dirs = "1.0.5"
|
||||||
flatbuffers = "0.5.0"
|
flatbuffers = "0.5.0"
|
||||||
|
|
|
@ -260,7 +260,6 @@ Deno.test({
|
||||||
package: { name: "deno", version: "0.3.4", edition: "2018" },
|
package: { name: "deno", version: "0.3.4", edition: "2018" },
|
||||||
dependencies: {
|
dependencies: {
|
||||||
deno_core: { path: "./core" },
|
deno_core: { path: "./core" },
|
||||||
ansi_term: "0.11.0",
|
|
||||||
atty: "0.2.11",
|
atty: "0.2.11",
|
||||||
dirs: "1.0.5",
|
dirs: "1.0.5",
|
||||||
flatbuffers: "0.5.0",
|
flatbuffers: "0.5.0",
|
||||||
|
|
Loading…
Reference in a new issue