");
@@ -154,7 +172,7 @@ async fn to_html(
// Check to see if we want to remove all color or change ansi to html colors
if html_color {
- setup_html_color_regexes(&mut hm);
+ setup_html_color_regexes(&mut hm, dark_bg);
output_string = run_regexes(&hm, &output_string);
} else if no_color {
setup_no_color_regexes(&mut hm);
@@ -166,14 +184,24 @@ async fn to_html(
)))
}
-fn setup_html_color_regexes(hash: &mut HashMap \[1;31m)(?P 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(); - setup_html_color_regexes(&mut hm); + fn test_cd_html_color_flag_dark_false() { + let mut hm: HashMap 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 is_dark = false; + setup_html_color_regexes(&mut hm, is_dark); + assert_eq!(cd_help_expected_result, run_regexes(&hm, &cd_help)); + } + + #[test] + fn test_cd_html_color_flag_dark_true() { + let mut hm: HashMap 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 is_dark = true; + setup_html_color_regexes(&mut hm, is_dark); assert_eq!(cd_help_expected_result, run_regexes(&hm, &cd_help)); } #[test] fn test_no_color_flag() { - let mut hm = 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 mut hm: HashMap 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(); setup_no_color_regexes(&mut hm); assert_eq!(cd_help_expected_result, run_regexes(&hm, &cd_help)); } #[test] - fn test_html_color_where_flag() { - let mut hm = 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(); - setup_html_color_regexes(&mut hm); + fn test_html_color_where_flag_dark_true() { + let mut hm: HashMap 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 is_dark = true; + setup_html_color_regexes(&mut hm, is_dark); + assert_eq!(where_help_exptected_results, run_regexes(&hm, &where_help)); + } + + #[test] + fn test_html_color_where_flag_dark_false() { + let mut hm: HashMap 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 is_dark = false; + setup_html_color_regexes(&mut hm, is_dark); assert_eq!(where_help_exptected_results, run_regexes(&hm, &where_help)); } } diff --git a/crates/nu-cli/tests/format_conversions/html.rs b/crates/nu-cli/tests/format_conversions/html.rs index 06b642c637..c892130aef 100644 --- a/crates/nu-cli/tests/format_conversions/html.rs +++ b/crates/nu-cli/tests/format_conversions/html.rs @@ -9,7 +9,10 @@ fn out_html_simple() { "# )); - assert_eq!(actual.out, "3"); + assert_eq!( + actual.out, + "3" + ); } #[test] @@ -23,6 +26,6 @@ fn out_html_table() { assert_eq!( actual.out, - "
|
---|