Campbell colors (#2219)

* added campbell theme to html colors

* updated test results. had to make change for ci.

* hopefully the last changes for this stupid test :)

* moved tests to html.rs

* remove unnecessary using statement.

* still fighting with tests and tests are winning.
This commit is contained in:
Darren Schroeder 2020-07-20 07:57:29 -05:00 committed by GitHub
parent 836efd237c
commit 7b1a15b223
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 177 additions and 103 deletions

View file

@ -15,6 +15,7 @@ pub struct ToHTMLArgs {
html_color: bool, html_color: bool,
no_color: bool, no_color: bool,
dark_bg: bool, dark_bg: bool,
use_campbell: bool,
} }
#[async_trait] #[async_trait]
@ -32,6 +33,11 @@ impl WholeStreamCommand for ToHTML {
"indicate your background color is a darker color", "indicate your background color is a darker color",
Some('d'), Some('d'),
) )
.switch(
"use_campbell",
"use microsoft's windows terminal color scheme named campell",
Some('c'),
)
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -47,43 +53,60 @@ impl WholeStreamCommand for ToHTML {
} }
} }
fn get_colors(is_dark: bool) -> HashMap<&'static str, String> { fn get_campbell_theme(is_dark: bool) -> HashMap<&'static str, String> {
// Currently now using bold_white and bold_black.
// This is not theming but it is kind of a start. The intent here is to use the
// regular terminal colors which appear on black for most people and are very
// high contrast. But when there's a light background, use something that works
// better for it.
// for reference here is Microsoft's Campbell Theme // for reference here is Microsoft's Campbell Theme
// taken from here // taken from here
// https://docs.microsoft.com/en-us/windows/terminal/customize-settings/color-schemes // https://docs.microsoft.com/en-us/windows/terminal/customize-settings/color-schemes
// { let mut hm: HashMap<&str, String> = HashMap::new();
// "name" : "Campbell",
// "cursorColor": "#FFFFFF", if is_dark {
// "selectionBackground": "#FFFFFF", hm.insert("bold_black", "#767676".to_string());
hm.insert("bold_red", "#E74856".to_string());
hm.insert("bold_green", "#16C60C".to_string());
hm.insert("bold_yellow", "#F9F1A5".to_string());
hm.insert("bold_blue", "#3B78FF".to_string());
hm.insert("bold_magenta", "#B4009E".to_string());
hm.insert("bold_cyan", "#61D6D6".to_string());
hm.insert("bold_white", "#F2F2F2".to_string());
// "background" : "#0C0C0C", hm.insert("black", "#0C0C0C".to_string());
// "foreground" : "#CCCCCC", hm.insert("red", "#C50F1F".to_string());
hm.insert("green", "#13A10E".to_string());
hm.insert("yellow", "#C19C00".to_string());
hm.insert("blue", "#0037DA".to_string());
hm.insert("magenta", "#881798".to_string());
hm.insert("cyan", "#3A96DD".to_string());
hm.insert("white", "#CCCCCC".to_string());
// "black" : "#0C0C0C", hm.insert("background", "#0C0C0C".to_string());
// "blue" : "#0037DA", hm.insert("foreground", "#CCCCCC".to_string());
// "cyan" : "#3A96DD", } else {
// "green" : "#13A10E", hm.insert("bold_black", "#767676".to_string());
// "purple" : "#881798", hm.insert("bold_red", "#E74856".to_string());
// "red" : "#C50F1F", hm.insert("bold_green", "#16C60C".to_string());
// "white" : "#CCCCCC", hm.insert("bold_yellow", "#F9F1A5".to_string());
// "yellow" : "#C19C00", hm.insert("bold_blue", "#3B78FF".to_string());
// "brightBlack" : "#767676", hm.insert("bold_magenta", "#B4009E".to_string());
// "brightBlue" : "#3B78FF", hm.insert("bold_cyan", "#61D6D6".to_string());
// "brightCyan" : "#61D6D6", hm.insert("bold_white", "#F2F2F2".to_string());
// "brightGreen" : "#16C60C",
// "brightPurple" : "#B4009E",
// "brightRed" : "#E74856",
// "brightWhite" : "#F2F2F2",
// "brightYellow" : "#F9F1A5"
// },
hm.insert("black", "#0C0C0C".to_string());
hm.insert("red", "#C50F1F".to_string());
hm.insert("green", "#13A10E".to_string());
hm.insert("yellow", "#C19C00".to_string());
hm.insert("blue", "#0037DA".to_string());
hm.insert("magenta", "#881798".to_string());
hm.insert("cyan", "#3A96DD".to_string());
hm.insert("white", "#CCCCCC".to_string());
hm.insert("background", "#CCCCCC".to_string());
hm.insert("foreground", "#0C0C0C".to_string());
}
hm
}
fn get_default_theme(is_dark: bool) -> HashMap<&'static str, String> {
let mut hm: HashMap<&str, String> = HashMap::new(); let mut hm: HashMap<&str, String> = HashMap::new();
if is_dark { if is_dark {
@ -133,6 +156,20 @@ fn get_colors(is_dark: bool) -> HashMap<&'static str, String> {
hm hm
} }
fn get_colors(is_dark: bool, use_campbell: bool) -> HashMap<&'static str, String> {
// Currently now using bold_white and bold_black.
// This is not theming but it is kind of a start. The intent here is to use the
// regular terminal colors which appear on black for most people and are very
// high contrast. But when there's a light background, use something that works
// better for it.
if use_campbell {
get_campbell_theme(is_dark)
} else {
get_default_theme(is_dark)
}
}
async fn to_html( async fn to_html(
args: CommandArgs, args: CommandArgs,
registry: &CommandRegistry, registry: &CommandRegistry,
@ -144,22 +181,26 @@ async fn to_html(
html_color, html_color,
no_color, no_color,
dark_bg, dark_bg,
use_campbell,
}, },
input, input,
) = args.process(&registry).await?; ) = args.process(&registry).await?;
let input: Vec<Value> = input.collect().await; let input: Vec<Value> = input.collect().await;
let headers = nu_protocol::merge_descriptors(&input); let headers = nu_protocol::merge_descriptors(&input);
let mut output_string = "<html>".to_string(); let mut output_string = "<html>".to_string();
let mut hm: HashMap<u32, (&str, String)> = HashMap::new(); let mut regex_hm: HashMap<u32, (&str, String)> = HashMap::new();
let color_hm = get_colors(dark_bg, use_campbell);
// if the user wants a dark background, that means the background will be black // change the color of the page
// and the foreground will be white, otherwise it's the reverse. I think this output_string.push_str(&format!(
// is the best we can do until we get to color themes. r"<style>body {{ background-color:{};color:{}; }}</style><body>",
if dark_bg { color_hm
output_string.push_str("<style>body { background-color:black;color:white; }</style><body>"); .get("background")
} else { .expect("Error getting background color"),
output_string.push_str("<style>body { background-color:white;color:black; }</style><body>"); color_hm
} .get("foreground")
.expect("Error getting foreground color")
));
// Add grid lines to html // Add grid lines to html
// let mut output_string = "<html><head><style>".to_string(); // let mut output_string = "<html><head><style>".to_string();
@ -170,11 +211,15 @@ async fn to_html(
// output_string.push_str("<table>"); // output_string.push_str("<table>");
// change the color of tables // change the color of tables
if dark_bg { output_string.push_str(&format!(
output_string.push_str("<table style=\"background-color:black;color:white;\">"); r"<table style='background-color:{};color:{};'>",
} else { color_hm
output_string.push_str("<table style=\"background-color:white;color:black;\">"); .get("background")
} .expect("Error getting background color"),
color_hm
.get("foreground")
.expect("Error getting foreground color")
));
output_string.push_str("<tr>"); output_string.push_str("<tr>");
@ -270,11 +315,11 @@ async fn to_html(
// Check to see if we want to remove all color or change ansi to html colors // Check to see if we want to remove all color or change ansi to html colors
if html_color { if html_color {
setup_html_color_regexes(&mut hm, dark_bg); setup_html_color_regexes(&mut regex_hm, dark_bg, use_campbell);
output_string = run_regexes(&hm, &output_string); output_string = run_regexes(&regex_hm, &output_string);
} else if no_color { } else if no_color {
setup_no_color_regexes(&mut hm); setup_no_color_regexes(&mut regex_hm);
output_string = run_regexes(&hm, &output_string); output_string = run_regexes(&regex_hm, &output_string);
} }
Ok(OutputStream::one(ReturnSuccess::value( Ok(OutputStream::one(ReturnSuccess::value(
@ -282,8 +327,12 @@ async fn to_html(
))) )))
} }
fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_dark: bool) { fn setup_html_color_regexes(
let color_hm = get_colors(is_dark); hash: &mut HashMap<u32, (&'static str, String)>,
is_dark: bool,
use_campbell: bool,
) {
let color_hm = get_colors(is_dark, use_campbell);
// All the bold colors // All the bold colors
hash.insert( hash.insert(
@ -537,7 +586,6 @@ fn run_regexes(hash: &HashMap<u32, (&'static str, String)>, contents: &str) -> S
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::collections::HashMap;
#[test] #[test]
fn examples_work_as_expected() { fn examples_work_as_expected() {
@ -545,53 +593,4 @@ mod tests {
test_examples(ToHTML {}) test_examples(ToHTML {})
} }
#[test]
fn test_cd_html_color_flag_dark_false() {
let mut hm: HashMap<u32, (&str, String)> = HashMap::new();
let cd_help = r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; cd dirname<br><br> Change to your home directory<br> &gt; cd<br><br> Change to your home directory (alternate version)<br> &gt; cd ~<br><br> Change to the previous directory<br> &gt; cd -<br><br></body></html>".to_string();
let cd_help_expected_result = r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; <span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>dirname<span style='color:black;font-weight:normal;'><br><br> Change to your home directory<br> &gt; </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'><br><br> Change to your home directory (alternate version)<br> &gt; </span></span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>~<span style='color:black;font-weight:normal;'><br><br> Change to the previous directory<br> &gt; </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>-<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>".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<u32, (&str, String)> = HashMap::new();
let cd_help = r"<html><style>body { background-color:black;color:white; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; cd dirname<br><br> Change to your home directory<br> &gt; cd<br><br> Change to your home directory (alternate version)<br> &gt; cd ~<br><br> Change to the previous directory<br> &gt; cd -<br><br></body></html>".to_string();
let cd_help_expected_result = r"<html><style>body { background-color:black;color:white; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; <span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:cyan;'>dirname<span style='color:white;font-weight:normal;'><br><br> Change to your home directory<br> &gt; </span><span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'><br><br> Change to your home directory (alternate version)<br> &gt; </span></span><span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:cyan;'>~<span style='color:white;font-weight:normal;'><br><br> Change to the previous directory<br> &gt; </span><span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:cyan;'>-<span style='color:white;font-weight:normal;'><br><br></body></html></span></span></span>".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<u32, (&str, String)> = HashMap::new();
let cd_help = r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; cd dirname<br><br> Change to your home directory<br> &gt; cd<br><br> Change to your home directory (alternate version)<br> &gt; cd ~<br><br> Change to the previous directory<br> &gt; cd -<br><br></body></html>".to_string();
let cd_help_expected_result = r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; cd dirname<br><br> Change to your home directory<br> &gt; cd<br><br> Change to your home directory (alternate version)<br> &gt; cd ~<br><br> Change to the previous directory<br> &gt; cd -<br><br></body></html>".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_dark_true() {
let mut hm: HashMap<u32, (&str, String)> = HashMap::new();
let where_help = r"<html><style>body { background-color:black;color:white; }</style><body>Filter table to match the condition.<br><br>Usage:<br> &gt; where &lt;condition&gt; {flags} <br><br>Parameters:<br> &lt;condition&gt; the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> &gt; ls | where size &gt; 2kb<br><br> List only the files in the current directory<br> &gt; ls | where type == File<br><br> List all files with names that contain &quot;Car&quot;<br> &gt; ls | where name =~ &quot;Car&quot;<br><br> List all files that were modified in the last two months<br> &gt; ls | where modified &lt;= 2M<br><br></body></html>".to_string();
let where_help_exptected_results = r"<html><style>body { background-color:black;color:white; }</style><body>Filter table to match the condition.<br><br>Usage:<br> &gt; where &lt;condition&gt; {flags} <br><br>Parameters:<br> &lt;condition&gt; the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> &gt; <span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>size<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>&gt;<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:magenta;font-weight:bold;'>2<span style='color:white;font-weight:normal;'></span></span><span style='color:cyan;font-weight:bold;'>kb<span style='color:white;font-weight:normal;'><br><br> List only the files in the current directory<br> &gt; </span></span><span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>type<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>==<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:green;'>File<span style='color:white;font-weight:normal;'><br><br> List all files with names that contain &quot;Car&quot;<br> &gt; </span><span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>name<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>=~<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:green;'>&quot;Car&quot;<span style='color:white;font-weight:normal;'><br><br> List all files that were modified in the last two months<br> &gt; </span><span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>modified<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>&lt;=<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:magenta;font-weight:bold;'>2<span style='color:white;font-weight:normal;'></span></span><span style='color:cyan;font-weight:bold;'>M<span style='color:white;font-weight:normal;'><br><br></body></html></span></span></span>".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<u32, (&str, String)> = HashMap::new();
let where_help = r"<html><style>body { background-color:white;color:black; }</style><body>Filter table to match the condition.<br><br>Usage:<br> &gt; where &lt;condition&gt; {flags} <br><br>Parameters:<br> &lt;condition&gt; the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> &gt; ls | where size &gt; 2kb<br><br> List only the files in the current directory<br> &gt; ls | where type == File<br><br> List all files with names that contain &quot;Car&quot;<br> &gt; ls | where name =~ &quot;Car&quot;<br><br> List all files that were modified in the last two months<br> &gt; ls | where modified &lt;= 2M<br><br></body></html>".to_string();
let where_help_exptected_results = r"<html><style>body { background-color:white;color:black; }</style><body>Filter table to match the condition.<br><br>Usage:<br> &gt; where &lt;condition&gt; {flags} <br><br>Parameters:<br> &lt;condition&gt; the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> &gt; <span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>size<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>&gt;<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>kb<span style='color:black;font-weight:normal;'><br><br> List only the files in the current directory<br> &gt; </span></span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>type<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>==<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>File<span style='color:black;font-weight:normal;'><br><br> List all files with names that contain &quot;Car&quot;<br> &gt; </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>name<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>=~<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>&quot;Car&quot;<span style='color:black;font-weight:normal;'><br><br> List all files that were modified in the last two months<br> &gt; </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>modified<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>&lt;=<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>M<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>".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));
}
} }

View file

@ -11,7 +11,7 @@ fn out_html_simple() {
assert_eq!( assert_eq!(
actual.out, actual.out,
"<html><style>body { background-color:white;color:black; }</style><body>3</body></html>" r"<html><style>body { background-color:white;color:black; }</style><body>3</body></html>"
); );
} }
@ -20,12 +20,87 @@ fn out_html_table() {
let actual = nu!( let actual = nu!(
cwd: ".", pipeline( cwd: ".", pipeline(
r#" r#"
echo '{"name": "jason"}' | from json | to html echo '{"name": "darren"}' | from json | to html
"# "#
)); ));
assert_eq!( assert_eq!(
actual.out, actual.out,
"<html><style>body { background-color:white;color:black; }</style><body><table style=\"background-color:white;color:black;\"><tr><th>name</th></tr><tr><td>jason</td></tr></table></body></html>" r"<html><style>body { background-color:white;color:black; }</style><body><table style='background-color:white;color:black;'><tr><th>name</th></tr><tr><td>darren</td></tr></table></body></html>"
);
}
#[test]
fn test_cd_html_color_flag_dark_false() {
let actual = nu!(
cwd: ".", pipeline(
r#"
cd --help | to html --html_color
"#
)
);
assert_eq!(
actual.out,
r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; <span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>dirname<span style='color:black;font-weight:normal;'><br><br> Change to your home directory<br> &gt; </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'><br><br> Change to your home directory (alternate version)<br> &gt; </span></span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>~<span style='color:black;font-weight:normal;'><br><br> Change to the previous directory<br> &gt; </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>-<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>"
);
}
#[test]
fn test_cd_html_color_flag_dark_true() {
let actual = nu!(
cwd: ".", pipeline(
r#"
cd --help | to html --html_color --dark_bg
"#
)
);
assert_eq!(
actual.out,
r"<html><style>body { background-color:black;color:white; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; <span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:cyan;'>dirname<span style='color:white;font-weight:normal;'><br><br> Change to your home directory<br> &gt; </span><span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'><br><br> Change to your home directory (alternate version)<br> &gt; </span></span><span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:cyan;'>~<span style='color:white;font-weight:normal;'><br><br> Change to the previous directory<br> &gt; </span><span style='color:cyan;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:cyan;'>-<span style='color:white;font-weight:normal;'><br><br></body></html></span></span></span>"
);
}
#[test]
fn test_no_color_flag() {
let actual = nu!(
cwd: ".", pipeline(
r#"
cd --help | to html --no_color
"#
)
);
assert_eq!(
actual.out,
r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> &gt; cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called &#x27;dirname&#x27;<br> &gt; cd dirname<br><br> Change to your home directory<br> &gt; cd<br><br> Change to your home directory (alternate version)<br> &gt; cd ~<br><br> Change to the previous directory<br> &gt; cd -<br><br></body></html>"
);
}
#[test]
fn test_html_color_where_flag_dark_true() {
let actual = nu!(
cwd: ".", pipeline(
r#"
where --help | to html --html_color --dark_bg
"#
)
);
assert_eq!(
actual.out,
r"<html><style>body { background-color:black;color:white; }</style><body>Filter table to match the condition.<br><br>Usage:<br> &gt; where &lt;condition&gt; {flags} <br><br>Parameters:<br> &lt;condition&gt; the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> &gt; <span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>size<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>&gt;<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:magenta;font-weight:bold;'>2<span style='color:white;font-weight:normal;'></span></span><span style='color:cyan;font-weight:bold;'>kb<span style='color:white;font-weight:normal;'><br><br> List only the files in the current directory<br> &gt; </span></span><span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>type<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>==<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:green;'>File<span style='color:white;font-weight:normal;'><br><br> List all files with names that contain &quot;Car&quot;<br> &gt; </span><span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>name<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>=~<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:green;'>&quot;Car&quot;<span style='color:white;font-weight:normal;'><br><br> List all files that were modified in the last two months<br> &gt; </span><span style='color:cyan;font-weight:bold;'>ls<span style='color:white;font-weight:normal;'></span></span></span></span><span style='color:white;'> | <span style='color:white;font-weight:normal;'></span><span style='color:cyan;font-weight:bold;'>where<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;font-weight:bold;'>modified<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:yellow;'>&lt;=<span style='color:white;font-weight:normal;'></span></span></span><span style='color:white;'> <span style='color:white;font-weight:normal;'></span><span style='color:magenta;font-weight:bold;'>2<span style='color:white;font-weight:normal;'></span></span><span style='color:cyan;font-weight:bold;'>M<span style='color:white;font-weight:normal;'><br><br></body></html></span></span></span>"
);
}
#[test]
fn test_html_color_where_flag_dark_false() {
let actual = nu!(
cwd: ".", pipeline(
r#"
where --help | to html --html_color
"#
)
);
assert_eq!(
actual.out,
r"<html><style>body { background-color:white;color:black; }</style><body>Filter table to match the condition.<br><br>Usage:<br> &gt; where &lt;condition&gt; {flags} <br><br>Parameters:<br> &lt;condition&gt; the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> &gt; <span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>size<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>&gt;<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>kb<span style='color:black;font-weight:normal;'><br><br> List only the files in the current directory<br> &gt; </span></span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>type<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>==<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>File<span style='color:black;font-weight:normal;'><br><br> List all files with names that contain &quot;Car&quot;<br> &gt; </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>name<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>=~<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>&quot;Car&quot;<span style='color:black;font-weight:normal;'><br><br> List all files that were modified in the last two months<br> &gt; </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>modified<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>&lt;=<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>M<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>"
); );
} }