diff --git a/crates/nu-cli/src/commands/to_html.rs b/crates/nu-cli/src/commands/to_html.rs
index 7a1881613..00273b88e 100644
--- a/crates/nu-cli/src/commands/to_html.rs
+++ b/crates/nu-cli/src/commands/to_html.rs
@@ -184,7 +184,6 @@ async fn to_html(
)))
}
-// fn setup_html_color_regexes(hash: &mut HashMap, is_dark: bool) {
fn setup_html_color_regexes(hash: &mut HashMap, is_dark: bool) {
let text_color = if is_dark {
"white".to_string()
@@ -208,7 +207,6 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
1,
(
// Bold Black
- // r"(?P\[1;30m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[1;30m)(?P[[:alnum:][:space:][:punct:]]*)",
format!(
r"$word",
@@ -220,7 +218,6 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
2,
(
// Bold Red
- // r"(?P
\[1;31m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P
\[1;31m)(?P[[:alnum:][:space:][:punct:]]*)",
r"$word".to_string(),
),
@@ -229,7 +226,6 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
3,
(
// Bold Green
- // r"(?P\[1;32m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[1;32m)(?P[[:alnum:][:space:][:punct:]]*)",
r"$word".to_string(),
),
@@ -238,16 +234,14 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
4,
(
// Bold Yellow
- // r"(?P\[1;33m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[1;33m)(?P[[:alnum:][:space:][:punct:]]*)",
- r"$word".to_string(),
+ r"$word".to_string(),
),
);
hash.insert(
5,
(
// Bold Blue
- // r"(?P\[1;34m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[1;34m)(?P[[:alnum:][:space:][:punct:]]*)",
r"$word".to_string(),
),
@@ -256,18 +250,16 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
6,
(
// Bold Magenta
- // r"(?P\[1;35m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[1;35m)(?P[[:alnum:][:space:][:punct:]]*)",
- r"$word".to_string(),
+ r"$word".to_string(),
),
);
hash.insert(
7,
(
// Bold Cyan
- // r"(?P\[1;36m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[1;36m)(?P[[:alnum:][:space:][:punct:]]*)",
- r"$word".to_string(),
+ r"$word".to_string(),
),
);
hash.insert(
@@ -276,7 +268,6 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
// Bold White
// Let's change this to black since the html background
// is white. White on white = no bueno.
- // r"(?P\[1;37m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[1;37m)(?P[[:alnum:][:space:][:punct:]]*)",
format!(
r"$word",
@@ -289,7 +280,6 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
9,
(
// Black
- // r"(?P\[30m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[30m)(?P[[:alnum:][:space:][:punct:]]*)",
format!(r"$word", text_color),
),
@@ -298,7 +288,6 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
10,
(
// Red
- // r"(?P\[31m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[31m)(?P[[:alnum:][:space:][:punct:]]*)",
r"$word".to_string(),
),
@@ -307,7 +296,6 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
11,
(
// Green
- // r"(?P\[32m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[32m)(?P[[:alnum:][:space:][:punct:]]*)",
r"$word".to_string(),
),
@@ -316,16 +304,14 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
12,
(
// Yellow
- // r"(?P\[33m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[33m)(?P[[:alnum:][:space:][:punct:]]*)",
- r"$word".to_string(),
+ r"$word".to_string(),
),
);
hash.insert(
13,
(
// Blue
- // r"(?P\[34m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[34m)(?P[[:alnum:][:space:][:punct:]]*)",
r"$word".to_string(),
),
@@ -334,18 +320,16 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
14,
(
// Magenta
- // r"(?P\[35m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[35m)(?P[[:alnum:][:space:][:punct:]]*)",
- r"$word".to_string(),
+ r"$word".to_string(),
),
);
hash.insert(
15,
(
// Cyan
- // r"(?P\[36m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[36m)(?P[[:alnum:][:space:][:punct:]]*)",
- r"$word".to_string(),
+ r"$word".to_string(),
),
);
hash.insert(
@@ -354,14 +338,12 @@ fn setup_html_color_regexes(hash: &mut HashMap, is_
// White
// Let's change this to black since the html background
// is white. White on white = no bueno.
- // r"(?P\[37m)(?P[A-Za-z0-9\-'!/_~ &;|=\+\*\.#%:\]$`\(\)]+)",
r"(?P\[37m)(?P[[:alnum:][:space:][:punct:]]*)",
format!(r"$word", text_color),
),
);
}
-// fn setup_no_color_regexes(hash: &mut HashMap, is_dark: bool) {
fn setup_no_color_regexes(hash: &mut HashMap) {
// We can just use one regex here because we're just removing ansi sequences
// and not replacing them with html colors.
@@ -375,7 +357,6 @@ fn setup_no_color_regexes(hash: &mut HashMap) {
);
}
-// fn run_regexes(hash: &HashMap, contents: &str) -> String {
fn run_regexes(hash: &HashMap, contents: &str) -> String {
let mut working_string = contents.to_owned();
let hash_count: u32 = hash.len() as u32;
@@ -383,7 +364,6 @@ fn run_regexes(hash: &HashMap, contents: &str) -> S
let value = hash.get(&n).expect("error getting hash at index");
//println!("{},{}", value.0, value.1);
let re = Regex::new(value.0).expect("problem with color regex");
- // let replace = value.1.to_owned();
let after = re.replace_all(&working_string, &value.1[..]).to_string();
working_string = after.clone();
}
@@ -406,7 +386,7 @@ mod tests {
fn test_cd_html_color_flag_dark_false() {
let mut hm: HashMap = HashMap::new();
let cd_help = r"Change to a new path.
Usage:
> cd (directory) {flags}
Parameters:
(directory) the directory to change to
Flags:
-h, --help: Display this help message
Examples:
Change to a new directory called 'dirname'
> [1;36mcd[0m[37m [0m[36mdirname[0m
Change to your home directory
> [1;36mcd[0m
Change to your home directory (alternate version)
> [1;36mcd[0m[37m [0m[36m~[0m
Change to the previous directory
> [1;36mcd[0m[37m [0m[36m-[0m
".to_string();
- let cd_help_expected_result = r"Change to a new path.
Usage:
> cd (directory) {flags}
Parameters:
(directory) the directory to change to
Flags:
-h, --help: Display this help message
Examples:
Change to a new directory called 'dirname'
> cd dirname
Change to your home directory
> cd
Change to your home directory (alternate version)
> cd ~
Change to the previous directory
> cd -
".to_string();
+ let cd_help_expected_result = r"Change to a new path.
Usage:
> cd (directory) {flags}
Parameters:
(directory) the directory to change to
Flags:
-h, --help: Display this help message
Examples:
Change to a new directory called 'dirname'
> cd dirname
Change to your home directory
> cd
Change to your home directory (alternate version)
> cd ~
Change to the previous directory
> cd -
".to_string();
let is_dark = false;
setup_html_color_regexes(&mut hm, is_dark);
assert_eq!(cd_help_expected_result, run_regexes(&hm, &cd_help));
@@ -416,7 +396,7 @@ mod tests {
fn test_cd_html_color_flag_dark_true() {
let mut hm: HashMap = HashMap::new();
let cd_help = r"Change to a new path.
Usage:
> cd (directory) {flags}
Parameters:
(directory) the directory to change to
Flags:
-h, --help: Display this help message
Examples:
Change to a new directory called 'dirname'
> [1;36mcd[0m[37m [0m[36mdirname[0m
Change to your home directory
> [1;36mcd[0m
Change to your home directory (alternate version)
> [1;36mcd[0m[37m [0m[36m~[0m
Change to the previous directory
> [1;36mcd[0m[37m [0m[36m-[0m
".to_string();
- let cd_help_expected_result = r"Change to a new path.
Usage:
> cd (directory) {flags}
Parameters:
(directory) the directory to change to
Flags:
-h, --help: Display this help message
Examples:
Change to a new directory called 'dirname'
> cd dirname
Change to your home directory
> cd
Change to your home directory (alternate version)
> cd ~
Change to the previous directory
> cd -
".to_string();
+ let cd_help_expected_result = r"Change to a new path.
Usage:
> cd (directory) {flags}
Parameters:
(directory) the directory to change to
Flags:
-h, --help: Display this help message
Examples:
Change to a new directory called 'dirname'
> cd dirname
Change to your home directory
> cd
Change to your home directory (alternate version)
> cd ~
Change to the previous directory
> cd -
".to_string();
let is_dark = true;
setup_html_color_regexes(&mut hm, is_dark);
assert_eq!(cd_help_expected_result, run_regexes(&hm, &cd_help));
@@ -435,7 +415,7 @@ mod tests {
fn test_html_color_where_flag_dark_true() {
let mut hm: HashMap = HashMap::new();
let where_help = r"Filter table to match the condition.
Usage:
> where <condition> {flags}
Parameters:
<condition> the condition that must match
Flags:
-h, --help: Display this help message
Examples:
List all files in the current directory with sizes greater than 2kb
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33msize[0m[37m [0m[33m>[0m[37m [0m[1;35m2[0m[1;36mkb[0m
List only the files in the current directory
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mtype[0m[37m [0m[33m==[0m[37m [0m[32mFile[0m
List all files with names that contain "Car"
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mname[0m[37m [0m[33m=~[0m[37m [0m[32m"Car"[0m
List all files that were modified in the last two months
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mmodified[0m[37m [0m[33m<=[0m[37m [0m[1;35m2[0m[1;36mM[0m
".to_string();
- let where_help_exptected_results = r"Filter table to match the condition.
Usage:
> where <condition> {flags}
Parameters:
<condition> the condition that must match
Flags:
-h, --help: Display this help message
Examples:
List all files in the current directory with sizes greater than 2kb
> ls | where size > 2kb
List only the files in the current directory
> ls | where type == File
List all files with names that contain "Car"
> ls | where name =~ "Car"
List all files that were modified in the last two months
> ls | where modified <= 2M
".to_string();
+ let where_help_exptected_results = r"Filter table to match the condition.
Usage:
> where <condition> {flags}
Parameters:
<condition> the condition that must match
Flags:
-h, --help: Display this help message
Examples:
List all files in the current directory with sizes greater than 2kb
> ls | where size > 2kb
List only the files in the current directory
> ls | where type == File
List all files with names that contain "Car"
> ls | where name =~ "Car"
List all files that were modified in the last two months
> ls | where modified <= 2M
".to_string();
let is_dark = true;
setup_html_color_regexes(&mut hm, is_dark);
assert_eq!(where_help_exptected_results, run_regexes(&hm, &where_help));
@@ -445,7 +425,7 @@ mod tests {
fn test_html_color_where_flag_dark_false() {
let mut hm: HashMap = HashMap::new();
let where_help = r"Filter table to match the condition.
Usage:
> where <condition> {flags}
Parameters:
<condition> the condition that must match
Flags:
-h, --help: Display this help message
Examples:
List all files in the current directory with sizes greater than 2kb
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33msize[0m[37m [0m[33m>[0m[37m [0m[1;35m2[0m[1;36mkb[0m
List only the files in the current directory
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mtype[0m[37m [0m[33m==[0m[37m [0m[32mFile[0m
List all files with names that contain "Car"
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mname[0m[37m [0m[33m=~[0m[37m [0m[32m"Car"[0m
List all files that were modified in the last two months
> [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mmodified[0m[37m [0m[33m<=[0m[37m [0m[1;35m2[0m[1;36mM[0m
".to_string();
- let where_help_exptected_results = r"Filter table to match the condition.
Usage:
> where <condition> {flags}
Parameters:
<condition> the condition that must match
Flags:
-h, --help: Display this help message
Examples:
List all files in the current directory with sizes greater than 2kb
> ls | where size > 2kb
List only the files in the current directory
> ls | where type == File
List all files with names that contain "Car"
> ls | where name =~ "Car"
List all files that were modified in the last two months
> ls | where modified <= 2M
".to_string();
+ let where_help_exptected_results = r"Filter table to match the condition.
Usage:
> where <condition> {flags}
Parameters:
<condition> the condition that must match
Flags:
-h, --help: Display this help message
Examples:
List all files in the current directory with sizes greater than 2kb
> ls | where size > 2kb
List only the files in the current directory
> ls | where type == File
List all files with names that contain "Car"
> ls | where name =~ "Car"
List all files that were modified in the last two months
> ls | where modified <= 2M
".to_string();
let is_dark = false;
setup_html_color_regexes(&mut hm, is_dark);
assert_eq!(where_help_exptected_results, run_regexes(&hm, &where_help));