summaryrefslogtreecommitdiffstats
path: root/src/commands.rs
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2018-11-20 22:00:00 +0100
committerCanop <cano.petrole@gmail.com>2018-11-20 22:00:00 +0100
commit1440ef6b54df649f8159a498863af396396d9052 (patch)
tree1ac5a5a5c1da0ec0405c1eed534f10dd88c6fa09 /src/commands.rs
parent61d54fc5e3f7d36c96e9d449b185c66fedc1d735 (diff)
keys display in tree
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/commands.rs b/src/commands.rs
new file mode 100644
index 0000000..609f00d
--- /dev/null
+++ b/src/commands.rs
@@ -0,0 +1,42 @@
+
+use regex::Regex;
+
+#[derive(Debug)]
+pub struct Command {
+ pub raw: String,
+ pub finished: bool, // user hit <enter>
+ pub key: String,
+}
+
+impl Command {
+ pub fn new() -> Command {
+ Command {
+ raw: String::new(),
+ key: String::from(""),
+ finished: false,
+ }
+ }
+ // analyzes the raw command to fill key, verb
+ pub fn parse(&mut self) {
+ lazy_static! {
+ static ref RE: Regex = Regex::new(r"(?x)
+ ^
+ (?P<key>[0-1a-z]+)?
+ (?:\s+(?P<verb>\w+))?
+ $
+ ").unwrap();
+ }
+ match RE.captures(&self.raw) {
+ Some(c) => {
+ self.key = match c.name("key") {
+ Some(key) => String::from(key.as_str()),
+ None => String::from(""),
+ };
+ },
+ None => {
+ self.key = String::from("");
+ }
+ }
+
+ }
+}