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