@@ -7,6 +7,7 @@ use std::process::Command;
77use directories:: BaseDirs ;
88use regex:: Regex ;
99use serde:: { Serialize , Deserialize } ;
10+ use std:: collections:: HashSet ;
1011
1112use 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