Merge pull request #240 from snshn/color
Add color to asset download log
This commit is contained in:
commit
fa71f6a42c
4 changed files with 39 additions and 14 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -27,9 +27,9 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"doc-comment 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"doc-comment 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"predicates 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"predicates 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"predicates-core 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"predicates-core 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"predicates-tree 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"predicates-tree 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"wait-timeout 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"wait-timeout 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -608,6 +608,7 @@ name = "monolith"
|
||||||
version = "2.4.0"
|
version = "2.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_cmd 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"assert_cmd 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"base64 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"base64 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -858,24 +859,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates"
|
name = "predicates"
|
||||||
version = "1.0.6"
|
version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"predicates-core 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"predicates-core 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates-core"
|
name = "predicates-core"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates-tree"
|
name = "predicates-tree"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"predicates-core 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"predicates-core 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1755,9 +1756,9 @@ dependencies = [
|
||||||
"checksum pkg-config 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
"checksum pkg-config 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
||||||
"checksum ppv-lite86 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
"checksum ppv-lite86 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||||
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||||
"checksum predicates 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "73dd9b7b200044694dfede9edf907c1ca19630908443e9447e624993700c6932"
|
"checksum predicates 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa"
|
||||||
"checksum predicates-core 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fb3dbeaaf793584e29c58c7e3a82bbb3c7c06b63cea68d13b0e3cddc124104dc"
|
"checksum predicates-core 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451"
|
||||||
"checksum predicates-tree 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aee95d988ee893cb35c06b148c80ed2cd52c8eea927f50ba7a0be1a786aeab73"
|
"checksum predicates-tree 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2"
|
||||||
"checksum proc-macro-hack 0.5.19 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
"checksum proc-macro-hack 0.5.19 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
||||||
"checksum proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
"checksum proc-macro2 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||||
"checksum quote 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
|
"checksum quote 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
|
||||||
|
|
|
@ -22,6 +22,7 @@ include = [
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
atty = "0.2" # Used for highlighting network errors
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
chrono = "0.4.19" # Used for formatting creation timestamp
|
chrono = "0.4.19" # Used for formatting creation timestamp
|
||||||
clap = "2.33.3"
|
clap = "2.33.3"
|
||||||
|
|
12
src/opts.rs
12
src/opts.rs
|
@ -1,4 +1,5 @@
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
|
use std::env;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
|
@ -19,6 +20,7 @@ pub struct Options {
|
||||||
pub user_agent: Option<String>,
|
pub user_agent: Option<String>,
|
||||||
pub no_video: bool,
|
pub no_video: bool,
|
||||||
pub target: String,
|
pub target: String,
|
||||||
|
pub no_color: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ASCII: &str = " \
|
const ASCII: &str = " \
|
||||||
|
@ -33,6 +35,8 @@ const ASCII: &str = " \
|
||||||
const DEFAULT_NETWORK_TIMEOUT: u64 = 120;
|
const DEFAULT_NETWORK_TIMEOUT: u64 = 120;
|
||||||
const DEFAULT_USER_AGENT: &str =
|
const DEFAULT_USER_AGENT: &str =
|
||||||
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0";
|
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0";
|
||||||
|
const ENV_VAR_NO_COLOR: &str = "NO_COLOR";
|
||||||
|
const ENV_VAR_TERM: &str = "TERM";
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
pub fn from_args() -> Options {
|
pub fn from_args() -> Options {
|
||||||
|
@ -98,6 +102,14 @@ impl Options {
|
||||||
}
|
}
|
||||||
options.no_video = app.is_present("no-video");
|
options.no_video = app.is_present("no-video");
|
||||||
|
|
||||||
|
options.no_color =
|
||||||
|
env::var_os(ENV_VAR_NO_COLOR).is_some() || atty::isnt(atty::Stream::Stderr);
|
||||||
|
if let Some(term) = env::var_os(ENV_VAR_TERM) {
|
||||||
|
if term == "dumb" {
|
||||||
|
options.no_color = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
options
|
options
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
src/utils.rs
17
src/utils.rs
|
@ -7,8 +7,9 @@ use std::path::Path;
|
||||||
use crate::opts::Options;
|
use crate::opts::Options;
|
||||||
use crate::url::{clean_url, file_url_to_fs_path, is_data_url, is_file_url, parse_data_url};
|
use crate::url::{clean_url, file_url_to_fs_path, is_data_url, is_file_url, parse_data_url};
|
||||||
|
|
||||||
|
const ANSI_COLOR_RED: &str = "\x1b[31m";
|
||||||
|
const ANSI_COLOR_RESET: &str = "\x1b[0m";
|
||||||
const INDENT: &str = " ";
|
const INDENT: &str = " ";
|
||||||
|
|
||||||
const MAGIC: [[&[u8]; 2]; 18] = [
|
const MAGIC: [[&[u8]; 2]; 18] = [
|
||||||
// Image
|
// Image
|
||||||
[b"GIF87a", b"image/gif"],
|
[b"GIF87a", b"image/gif"],
|
||||||
|
@ -32,7 +33,6 @@ const MAGIC: [[&[u8]; 2]; 18] = [
|
||||||
[b"....moov", b"video/quicktime"],
|
[b"....moov", b"video/quicktime"],
|
||||||
[b"\x1A\x45\xDF\xA3", b"video/webm"],
|
[b"\x1A\x45\xDF\xA3", b"video/webm"],
|
||||||
];
|
];
|
||||||
|
|
||||||
const PLAINTEXT_MEDIA_TYPES: &[&str] = &[
|
const PLAINTEXT_MEDIA_TYPES: &[&str] = &[
|
||||||
"image/svg+xml",
|
"image/svg+xml",
|
||||||
"text/css",
|
"text/css",
|
||||||
|
@ -125,7 +125,18 @@ pub fn retrieve_asset(
|
||||||
Ok(mut response) => {
|
Ok(mut response) => {
|
||||||
if !options.ignore_errors && response.status() != 200 {
|
if !options.ignore_errors && response.status() != 200 {
|
||||||
if !options.silent {
|
if !options.silent {
|
||||||
eprintln!("Unable to retrieve {} ({})", &url, response.status());
|
eprintln!(
|
||||||
|
"{}{}{} ({}){}",
|
||||||
|
indent(depth).as_str(),
|
||||||
|
if options.no_color { "" } else { ANSI_COLOR_RED },
|
||||||
|
&url,
|
||||||
|
response.status(),
|
||||||
|
if options.no_color {
|
||||||
|
""
|
||||||
|
} else {
|
||||||
|
ANSI_COLOR_RESET
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Provoke error
|
// Provoke error
|
||||||
return Err(client.get("").send().unwrap_err());
|
return Err(client.get("").send().unwrap_err());
|
||||||
|
|
Loading…
Reference in a new issue