mirror of
https://github.com/nushell/nushell
synced 2024-12-29 14:33:13 +00:00
made it easier to change colors (#2212)
* made it easier to change colors and the beginning of html theming * fmt
This commit is contained in:
parent
5e722181cb
commit
d0712a00f4
1 changed files with 176 additions and 24 deletions
|
@ -47,6 +47,92 @@ impl WholeStreamCommand for ToHTML {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_colors(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
|
||||
// taken from here
|
||||
// https://docs.microsoft.com/en-us/windows/terminal/customize-settings/color-schemes
|
||||
// {
|
||||
// "name" : "Campbell",
|
||||
|
||||
// "cursorColor": "#FFFFFF",
|
||||
// "selectionBackground": "#FFFFFF",
|
||||
|
||||
// "background" : "#0C0C0C",
|
||||
// "foreground" : "#CCCCCC",
|
||||
|
||||
// "black" : "#0C0C0C",
|
||||
// "blue" : "#0037DA",
|
||||
// "cyan" : "#3A96DD",
|
||||
// "green" : "#13A10E",
|
||||
// "purple" : "#881798",
|
||||
// "red" : "#C50F1F",
|
||||
// "white" : "#CCCCCC",
|
||||
// "yellow" : "#C19C00",
|
||||
// "brightBlack" : "#767676",
|
||||
// "brightBlue" : "#3B78FF",
|
||||
// "brightCyan" : "#61D6D6",
|
||||
// "brightGreen" : "#16C60C",
|
||||
// "brightPurple" : "#B4009E",
|
||||
// "brightRed" : "#E74856",
|
||||
// "brightWhite" : "#F2F2F2",
|
||||
// "brightYellow" : "#F9F1A5"
|
||||
// },
|
||||
|
||||
let mut hm: HashMap<&str, String> = HashMap::new();
|
||||
|
||||
if is_dark {
|
||||
hm.insert("bold_black", "black".to_string());
|
||||
hm.insert("bold_red", "red".to_string());
|
||||
hm.insert("bold_green", "green".to_string());
|
||||
hm.insert("bold_yellow", "yellow".to_string());
|
||||
hm.insert("bold_blue", "blue".to_string());
|
||||
hm.insert("bold_magenta", "magenta".to_string());
|
||||
hm.insert("bold_cyan", "cyan".to_string());
|
||||
hm.insert("bold_white", "white".to_string());
|
||||
|
||||
hm.insert("black", "black".to_string());
|
||||
hm.insert("red", "red".to_string());
|
||||
hm.insert("green", "green".to_string());
|
||||
hm.insert("yellow", "yellow".to_string());
|
||||
hm.insert("blue", "blue".to_string());
|
||||
hm.insert("magenta", "magenta".to_string());
|
||||
hm.insert("cyan", "cyan".to_string());
|
||||
hm.insert("white", "white".to_string());
|
||||
|
||||
hm.insert("background", "black".to_string());
|
||||
hm.insert("foreground", "white".to_string());
|
||||
} else {
|
||||
hm.insert("bold_black", "black".to_string());
|
||||
hm.insert("bold_red", "red".to_string());
|
||||
hm.insert("bold_green", "green".to_string());
|
||||
hm.insert("bold_yellow", "#717100".to_string());
|
||||
hm.insert("bold_blue", "blue".to_string());
|
||||
hm.insert("bold_magenta", "#c800c8".to_string());
|
||||
hm.insert("bold_cyan", "#037979".to_string());
|
||||
hm.insert("bold_white", "white".to_string());
|
||||
|
||||
hm.insert("black", "black".to_string());
|
||||
hm.insert("red", "red".to_string());
|
||||
hm.insert("green", "green".to_string());
|
||||
hm.insert("yellow", "#717100".to_string());
|
||||
hm.insert("blue", "blue".to_string());
|
||||
hm.insert("magenta", "#c800c8".to_string());
|
||||
hm.insert("cyan", "#037979".to_string());
|
||||
hm.insert("white", "white".to_string());
|
||||
|
||||
hm.insert("background", "white".to_string());
|
||||
hm.insert("foreground", "black".to_string());
|
||||
}
|
||||
|
||||
hm
|
||||
}
|
||||
|
||||
async fn to_html(
|
||||
args: CommandArgs,
|
||||
registry: &CommandRegistry,
|
||||
|
@ -185,11 +271,7 @@ async fn to_html(
|
|||
}
|
||||
|
||||
fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_dark: bool) {
|
||||
let text_color = if is_dark {
|
||||
"white".to_string()
|
||||
} else {
|
||||
"black".to_string()
|
||||
};
|
||||
let color_hm = get_colors(is_dark);
|
||||
|
||||
// All the bold colors
|
||||
hash.insert(
|
||||
|
@ -199,7 +281,9 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
// Reset the text color, normal weight font
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:normal;'>$word</span>",
|
||||
text_color
|
||||
color_hm
|
||||
.get("foreground")
|
||||
.expect("Error getting reset text color")
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -210,7 +294,9 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
r"(?P<bb>\[1;30m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
text_color
|
||||
color_hm
|
||||
.get("foreground")
|
||||
.expect("Error getting bold black text color")
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -219,7 +305,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Bold Red
|
||||
r"(?P<br>\[1;31m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:red;font-weight:bold;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
color_hm
|
||||
.get("bold_red")
|
||||
.expect("Error getting bold red text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -227,7 +318,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Bold Green
|
||||
r"(?P<bg>\[1;32m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:green;font-weight:bold;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
color_hm
|
||||
.get("bold_green")
|
||||
.expect("Error getting bold green text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -235,7 +331,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Bold Yellow
|
||||
r"(?P<by>\[1;33m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:#717100;font-weight:bold;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
color_hm
|
||||
.get("bold_yellow")
|
||||
.expect("Error getting bold yellow text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -243,7 +344,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Bold Blue
|
||||
r"(?P<bu>\[1;34m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:blue;font-weight:bold;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
color_hm
|
||||
.get("bold_blue")
|
||||
.expect("Error getting bold blue text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -251,7 +357,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Bold Magenta
|
||||
r"(?P<bm>\[1;35m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:#c800c8;font-weight:bold;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
color_hm
|
||||
.get("bold_magenta")
|
||||
.expect("Error getting bold magenta text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -259,7 +370,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Bold Cyan
|
||||
r"(?P<bc>\[1;36m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:#037979;font-weight:bold;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
color_hm
|
||||
.get("bold_cyan")
|
||||
.expect("Error getting bold cyan text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -271,7 +387,9 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
r"(?P<bw>\[1;37m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
format!(
|
||||
r"<span style='color:{};font-weight:bold;'>$word</span>",
|
||||
text_color
|
||||
color_hm
|
||||
.get("foreground")
|
||||
.expect("Error getting bold bold white text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -281,7 +399,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Black
|
||||
r"(?P<b>\[30m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
format!(r"<span style='color:{};'>$word</span>", text_color),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm
|
||||
.get("foreground")
|
||||
.expect("Error getting black text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -289,7 +412,10 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Red
|
||||
r"(?P<r>\[31m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:red;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm.get("red").expect("Error getting red text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -297,7 +423,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Green
|
||||
r"(?P<g>\[32m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:green;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm
|
||||
.get("green")
|
||||
.expect("Error getting green text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -305,7 +436,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Yellow
|
||||
r"(?P<y>\[33m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:#717100;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm
|
||||
.get("yellow")
|
||||
.expect("Error getting yellow text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -313,7 +449,10 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Blue
|
||||
r"(?P<u>\[34m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:blue;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm.get("blue").expect("Error getting blue text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -321,7 +460,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Magenta
|
||||
r"(?P<m>\[35m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:#c800c8;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm
|
||||
.get("magenta")
|
||||
.expect("Error getting magenta text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -329,7 +473,10 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
(
|
||||
// Cyan
|
||||
r"(?P<c>\[36m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
r"<span style='color:#037979;'>$word</span>".to_string(),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm.get("cyan").expect("Error getting cyan text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
hash.insert(
|
||||
|
@ -339,7 +486,12 @@ fn setup_html_color_regexes(hash: &mut HashMap<u32, (&'static str, String)>, is_
|
|||
// Let's change this to black since the html background
|
||||
// is white. White on white = no bueno.
|
||||
r"(?P<w>\[37m)(?P<word>[[:alnum:][:space:][:punct:]]*)",
|
||||
format!(r"<span style='color:{};'>$word</span>", text_color),
|
||||
format!(
|
||||
r"<span style='color:{};'>$word</span>",
|
||||
color_hm
|
||||
.get("foreground")
|
||||
.expect("Error getting white text color"),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -396,7 +548,7 @@ mod tests {
|
|||
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> > 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 'dirname'<br> > [1;36mcd[0m[37m [0m[36mdirname[0m<br><br> Change to your home directory<br> > [1;36mcd[0m<br><br> Change to your home directory (alternate version)<br> > [1;36mcd[0m[37m [0m[36m~[0m<br><br> Change to the previous directory<br> > [1;36mcd[0m[37m [0m[36m-[0m<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> > 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 'dirname'<br> > <span style='color:#037979;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:#037979;'>dirname<span style='color:white;font-weight:normal;'><br><br> Change to your home directory<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:white;font-weight:normal;'><br><br> Change to your home directory (alternate version)<br> > </span></span><span style='color:#037979;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:#037979;'>~<span style='color:white;font-weight:normal;'><br><br> Change to the previous directory<br> > </span><span style='color:#037979;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:#037979;'>-<span style='color:white;font-weight:normal;'><br><br></body></html></span></span></span>".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> > 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 'dirname'<br> > <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> > </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> > </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> > </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));
|
||||
|
@ -415,7 +567,7 @@ mod tests {
|
|||
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> > where <condition> {flags} <br><br>Parameters:<br> <condition> 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> > [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<br><br> List only the files in the current directory<br> > [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mtype[0m[37m [0m[33m==[0m[37m [0m[32mFile[0m<br><br> List all files with names that contain "Car"<br> > [1;36mls[0m[37m | [0m[1;36mwhere[0m[37m [0m[1;33mname[0m[37m [0m[33m=~[0m[37m [0m[32m"Car"[0m<br><br> List all files that were modified in the last two months<br> > [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<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> > where <condition> {flags} <br><br>Parameters:<br> <condition> 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> > <span style='color:#037979;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:#037979;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:#717100;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:#717100;'>><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:#c800c8;font-weight:bold;'>2<span style='color:white;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>kb<span style='color:white;font-weight:normal;'><br><br> List only the files in the current directory<br> > </span></span><span style='color:#037979;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:#037979;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:#717100;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:#717100;'>==<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 "Car"<br> > </span><span style='color:#037979;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:#037979;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:#717100;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:#717100;'>=~<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;'>"Car"<span style='color:white;font-weight:normal;'><br><br> List all files that were modified in the last two months<br> > </span><span style='color:#037979;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:#037979;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:#717100;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:#717100;'><=<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:#c800c8;font-weight:bold;'>2<span style='color:white;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>M<span style='color:white;font-weight:normal;'><br><br></body></html></span></span></span>".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> > where <condition> {flags} <br><br>Parameters:<br> <condition> 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> > <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;'>><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> > </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 "Car"<br> > </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;'>"Car"<span style='color:white;font-weight:normal;'><br><br> List all files that were modified in the last two months<br> > </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;'><=<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));
|
||||
|
|
Loading…
Reference in a new issue