From ad35bbb1b433d428afdb328d1f0d4d99b24e206b Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Thu, 12 Mar 2020 18:57:49 -0300 Subject: [PATCH 1/2] Fix delimiter --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cheat.rs | 17 ++++++++++++----- src/cmds/core.rs | 5 +++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1874236b..0e2176b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "navi" -version = "2.0.7" +version = "2.0.8" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "raw_tty 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 5be37a16..5f6dc142 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "navi" -version = "2.0.7" +version = "2.0.8" authors = ["Denis Isidoro "] edition = "2018" diff --git a/src/cheat.rs b/src/cheat.rs index 5789894f..a06cbf56 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -24,6 +24,10 @@ fn gen_snippet(snippet: &str, line: &str) -> String { } } +fn remove_quote(txt: &str) -> String { + txt.replace('"', "").replace('\'', "") +} + fn parse_opts(text: &str) -> SuggestionOpts { let mut header_lines: u8 = 0; let mut column: Option = None; @@ -36,10 +40,10 @@ fn parse_opts(text: &str) -> SuggestionOpts { match p { "--multi" => multi = true, "--header" | "--headers" | "--header-lines" => { - header_lines = parts.next().unwrap().parse::().unwrap() + header_lines = remove_quote(parts.next().unwrap()).parse::().unwrap() } - "--column" => column = Some(parts.next().unwrap().parse::().unwrap()), - "--delimiter" => delimiter = Some(parts.next().unwrap().to_string()), + "--column" => column = Some(remove_quote(parts.next().unwrap()).parse::().unwrap()), + "--delimiter" => delimiter = Some(remove_quote(parts.next().unwrap()).to_string()), _ => (), } } @@ -134,8 +138,11 @@ fn read_file( pub fn read_all(config: &Config, stdin: &mut std::process::ChildStdin) -> HashMap { let mut variables: HashMap = HashMap::new(); - let fallback = filesystem::pathbuf_to_string(filesystem::cheat_pathbuf().unwrap()); - let folders_str = config.path.as_ref().unwrap_or(&fallback); + let mut fallback: String = String::from(""); + let folders_str = config.path.as_ref().unwrap_or_else(|| { + fallback = filesystem::pathbuf_to_string(filesystem::cheat_pathbuf().unwrap()); + &fallback + }); let folders = folders_str.split(':'); for folder in folders { diff --git a/src/cmds/core.rs b/src/cmds/core.rs index 0a69367d..7401de0f 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -92,8 +92,9 @@ fn prompt_with_suggestions(config: &Config, suggestion: &cheat::Value) -> String if let Some(c) = column { let re = regex::Regex::new(delimiter).unwrap(); let mut parts = re.split(output.as_str()); - for _ in 0..(c - 1) { - parts.next().unwrap(); + format!("re {:#?}", re); + for i in 0..(c - 1) { + format!("part {}: {}", i, parts.next().unwrap()); } parts.next().unwrap().to_string() } else { From a9940a7d93a9030c81954359298d58ef1a180320 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Thu, 12 Mar 2020 18:58:55 -0300 Subject: [PATCH 2/2] wip --- src/cheat.rs | 2 +- src/cmds/core.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cheat.rs b/src/cheat.rs index a06cbf56..9aeafeec 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -138,7 +138,7 @@ fn read_file( pub fn read_all(config: &Config, stdin: &mut std::process::ChildStdin) -> HashMap { let mut variables: HashMap = HashMap::new(); - let mut fallback: String = String::from(""); + let mut fallback: String = String::from(""); let folders_str = config.path.as_ref().unwrap_or_else(|| { fallback = filesystem::pathbuf_to_string(filesystem::cheat_pathbuf().unwrap()); &fallback diff --git a/src/cmds/core.rs b/src/cmds/core.rs index 7401de0f..0a69367d 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -92,9 +92,8 @@ fn prompt_with_suggestions(config: &Config, suggestion: &cheat::Value) -> String if let Some(c) = column { let re = regex::Regex::new(delimiter).unwrap(); let mut parts = re.split(output.as_str()); - format!("re {:#?}", re); - for i in 0..(c - 1) { - format!("part {}: {}", i, parts.next().unwrap()); + for _ in 0..(c - 1) { + parts.next().unwrap(); } parts.next().unwrap().to_string() } else {