Skip to content

Commit 84ddb1a

Browse files
Merge branch 'main' into feat/new-ci-process
2 parents f2f56b8 + be7fead commit 84ddb1a

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Anna Singleton
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ fn select_new_runner(runners_path: Option<String>) -> Option<Runner> {
5555
}
5656
}
5757

58+
if let Some(r) = &mut chosen_runner {
59+
r.get_quit_fast();
60+
}
61+
62+
5863
chosen_runner
5964
}
6065

src/runner.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::process::Command;
77
use directories::BaseDirs;
88
use regex::Regex;
99
use serde::{Serialize, Deserialize};
10+
use std::collections::HashSet;
1011

1112
use skim::*;
1213

@@ -57,24 +58,52 @@ impl Runner {
5758
/// process choose time arguments, and do corresponding string replacements
5859
pub fn get_args(&mut self) {
5960
let re = Regex::new(r"\{\s*(.*?)\s*\}").unwrap();
60-
let handlebar_matches = re.find_iter(&self.cmd);
61+
let handlebar_matches = re.captures_iter(&self.cmd);
6162

62-
let keys:Vec<_> = handlebar_matches.map(|m| m.as_str()).collect();
63+
let keys:HashSet<_> = handlebar_matches.map(|m| m[1].to_string()).collect();
6364

6465
if keys.is_empty() {
6566
return;
6667
}
6768

6869
let mut newcmd = self.cmd.clone();
70+
71+
println!("Command is: {}", &newcmd);
72+
6973
for key in keys {
70-
let value = Self::get_arg(key);
74+
let value = Self::get_arg(&key);
75+
// yes this regex is horrid.
76+
// breakdown of it is:
77+
// the \ are just literal \
78+
// the centre {} is where key is put
79+
// the {{ and }} are escaped { and } respectively
80+
let s = format!(r"\{{{}\}}", key);
81+
let re = Regex::new(&s).unwrap();
7182
newcmd = re.replace_all(&newcmd, value).to_string();
7283
println!("Command is now: {}", newcmd);
7384
}
7485

7586
self.cmd = newcmd;
7687
}
7788

89+
pub fn get_quit_fast(&mut self) {
90+
let mut choice = String::new();
91+
92+
if self.quit_fast {
93+
println!("Require an ENTER press after the runner exits? [y/N]?");
94+
} else {
95+
println!("Require an ENTER press after the runner exits? [Y/n]?")
96+
}
97+
98+
std::io::stdin().read_line(&mut choice).expect("error reading from stdin");
99+
100+
self.quit_fast = match choice.trim().to_uppercase().as_str() {
101+
"Y" => false,
102+
"N" => true,
103+
_ => self.quit_fast,
104+
}
105+
}
106+
78107
fn get_arg(name: &str) -> String {
79108
println!("Enter value for {}", name);
80109

0 commit comments

Comments
 (0)