diff options
author | Canop <cano.petrole@gmail.com> | 2020-01-22 08:57:17 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-01-22 08:57:17 +0100 |
commit | 2e20f83ed40da81782ef7123f80afe4ae9820f52 (patch) | |
tree | 2302e1b84ea80cef73f0955c1735eb339152fcea | |
parent | 87804b1cf93c0508a51364b773d6858010918a3e (diff) |
fix a panic on "///" input
We decide, for now, that such an unparsable input should be handled
as a fuzzy pattern.
In the case of "///" this isn't terribly useful as such a pattern
can't match on a filename.
We'll change this behaviour when introducing the new input syntax.
Fix #175
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/commands.rs | 37 | ||||
-rw-r--r-- | website/docs/documentation/installation.md | 4 |
3 files changed, 26 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 10cf7f2..53347a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ +### master +- fix panic on input being "///" (Fix #175) + <a name="v0.12.0"></a> ### v0.12.0 - 2020-01-19 - **breaking change:** commands given with `--cmd` must be separated (default separator is `;`) diff --git a/src/commands.rs b/src/commands.rs index fbf3038..34c2ee9 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -28,6 +28,7 @@ pub struct CommandParts { #[derive(Debug, Clone)] pub enum Action { + Unparsed, MoveSelection(i32), // up (neg) or down (positive) in the list OpenSelection, // open the selected line AltOpenSelection, // alternate open the selected line @@ -43,7 +44,6 @@ pub enum Action { Click(u16, u16), // usually a mouse click DoubleClick(u16, u16), // always come after a simple click at same position Resize(u16, u16), // terminal was resized to those dimensions - Unparsed, // or unparsable } impl CommandParts { @@ -66,18 +66,24 @@ impl CommandParts { $ " ) - .captures(raw) - .unwrap(); // all parts optional, so always captures - if let Some(pattern) = c.name("pattern") { - cp.pattern = Some(String::from(pattern.as_str())); - if let Some(rxf) = c.name("regex_flags") { - cp.regex_flags = Some(String::from(rxf.as_str())); - } else if c.name("slash_before").is_some() { - cp.regex_flags = Some("".into()); + .captures(raw); + if let Some(c) = c { + if let Some(pattern) = c.name("pattern") { + cp.pattern = Some(String::from(pattern.as_str())); + if let Some(rxf) = c.name("regex_flags") { + cp.regex_flags = Some(String::from(rxf.as_str())); + } else if c.name("slash_before").is_some() { + cp.regex_flags = Some("".into()); + } } - } - if let Some(verb) = c.name("verb_invocation") { - cp.verb_invocation = Some(VerbInvocation::from(verb.as_str())); + if let Some(verb) = c.name("verb_invocation") { + cp.verb_invocation = Some(VerbInvocation::from(verb.as_str())); + } + } else { + // Non matching pattterns include "///" + // We decide the whole is a fuzzy search pattern, in this case + // (this will change when we release the new input syntax) + cp.pattern = Some(String::from(raw)); } cp } @@ -143,11 +149,8 @@ impl Command { /// using the Enter key in the Gui. pub fn from_raw(raw: String, finished: bool) -> Self { let parts = CommandParts::from(&raw); - Self { - raw, - action: Action::from(&parts, finished), - parts, - } + let action = Action::from(&parts, finished); + Self { raw, action, parts } } /// build a non executed command from a pattern diff --git a/website/docs/documentation/installation.md b/website/docs/documentation/installation.md index 0994731..ae1db31 100644 --- a/website/docs/documentation/installation.md +++ b/website/docs/documentation/installation.md @@ -1,11 +1,13 @@ The current version of broot works on linux, mac and windows (win 10+). -While the linux version is quite well tested the other versions are lacking testers and maybe involved developpers. !!! Note Windows users: broot may need additional rights at first use in order to write its configuration file +!!! Note + If you use cargo and there's a compilation error, it usually means you have an old version of the compiler, and you should update it (for example with `rustup update`). + # From precompiled binaries Binaries are made available at every release in [download](https://dystroy.org/broot/download). |