Simplify textview match (#2024)

* simplify textview match code

* Math median tests and documentation additions (#2018)

* Add math median example and unit tests

* Update output of other all math ls command examples to keep consistent with math median output

* Fix output of math max example

* Update output of other math commands using pwd examples to keep data consistent
This commit is contained in:
Darren Schroeder 2020-06-20 12:16:36 -05:00 committed by GitHub
parent 853d7e7120
commit de6d8738c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,62 +35,62 @@ pub fn view_text_value(value: &Value) {
if let Ok(config) = nu_cli::data::config::config(Tag::unknown()) {
if let Some(batvars) = config.get("textview") {
for (idx, value) in batvars.row_entries() {
match idx {
x if x == "term_width" => {
match idx.as_ref() {
"term_width" => {
term_width = match value.as_u64() {
Ok(n) => n,
_ => textwrap::termwidth() as u64,
}
}
x if x == "tab_width" => {
"tab_width" => {
tab_width = match value.as_u64() {
Ok(n) => n,
_ => 4u64,
}
}
x if x == "colored_output" => {
"colored_output" => {
colored_output = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "true_color" => {
"true_color" => {
true_color = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "header" => {
"header" => {
header = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "line_numbers" => {
"line_numbers" => {
line_numbers = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "grid" => {
"grid" => {
grid = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "vcs_modification_markers" => {
"vcs_modification_markers" => {
vcs_modification_markers = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "snip" => {
"snip" => {
snip = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "wrapping_mode" => {
"wrapping_mode" => {
wrapping_mode = match value.as_string() {
Ok(s) if s.to_lowercase() == "nowrapping" => {
bat::WrappingMode::NoWrapping
@ -101,13 +101,13 @@ pub fn view_text_value(value: &Value) {
_ => bat::WrappingMode::NoWrapping,
}
}
x if x == "use_italics" => {
"use_italics" => {
use_italics = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
x if x == "paging_mode" => {
"paging_mode" => {
paging_mode = match value.as_string() {
Ok(s) if s.to_lowercase() == "always" => bat::PagingMode::Always,
Ok(s) if s.to_lowercase() == "never" => bat::PagingMode::Never,
@ -117,15 +117,15 @@ pub fn view_text_value(value: &Value) {
_ => bat::PagingMode::QuitIfOneScreen,
}
}
x if x == "pager" => {
"pager" => {
pager = match value.as_string() {
Ok(s) => s,
_ => "less".to_string(),
}
}
x if x == "line_ranges" => line_ranges = bat::line_range::LineRanges::all(), // not real sure what to do with this
x if x == "highlight_range" => _highlight_range = "0,0", //ignore config value for now
x if x == "theme" => {
"line_ranges" => line_ranges = bat::line_range::LineRanges::all(), // not real sure what to do with this
"highlight_range" => _highlight_range = "0,0", //ignore config value for now
"theme" => {
theme = match value.as_string() {
Ok(s) => s,
_ => "OneDarkHalf".to_string(),