Implement reverse

This commit is contained in:
Ferran Basora 2019-02-21 14:21:13 +00:00
parent a4d9ffab78
commit 8eef6bc517
3 changed files with 9 additions and 5 deletions

View File

@ -33,8 +33,7 @@ fn app_args<'a> () -> clap::ArgMatches<'a> {
.arg(Arg::with_name("reverse") .arg(Arg::with_name("reverse")
.help("Reverse the order for assigned hints") .help("Reverse the order for assigned hints")
.long("reverse") .long("reverse")
.short("r") .short("r"))
.takes_value(true))
.arg(Arg::with_name("excluded") .arg(Arg::with_name("excluded")
.help("Excluded keys from the alphabet") .help("Excluded keys from the alphabet")
.long("excluded") .long("excluded")
@ -46,6 +45,7 @@ fn app_args<'a> () -> clap::ArgMatches<'a> {
fn main() { fn main() {
let args = app_args(); let args = app_args();
let alphabet = args.value_of("alphabet").unwrap_or("querty"); let alphabet = args.value_of("alphabet").unwrap_or("querty");
let reverse = args.is_present("reverse");
let execution = exec_command(format!("tmux capture-pane -e -J -p")); let execution = exec_command(format!("tmux capture-pane -e -J -p"));
let output = String::from_utf8_lossy(&execution.stdout); let output = String::from_utf8_lossy(&execution.stdout);
@ -70,7 +70,7 @@ fn main() {
} }
let mut typed_hint: String = "".to_owned(); let mut typed_hint: String = "".to_owned();
let matches = state.matches(); let matches = state.matches(reverse);
let longest_hint = matches.last().unwrap().hint.clone().unwrap().len(); let longest_hint = matches.last().unwrap().hint.clone().unwrap().len();
loop { loop {

View File

@ -28,7 +28,7 @@ impl<'a> State<'a> {
} }
} }
pub fn matches(&self) -> Vec<Match<'a>> { pub fn matches(&self, reverse: bool) -> Vec<Match<'a>> {
let mut matches = Vec::new(); let mut matches = Vec::new();
let mut patterns = Vec::new(); let mut patterns = Vec::new();
@ -67,6 +67,10 @@ impl<'a> State<'a> {
let alphabet = super::alphabets::get_alphabet(self.alphabet); let alphabet = super::alphabets::get_alphabet(self.alphabet);
let mut hints = alphabet.hints(matches.len()); let mut hints = alphabet.hints(matches.len());
if reverse {
hints.reverse();
}
for mat in &mut matches { for mat in &mut matches {
if let Some(hint) = hints.pop() { if let Some(hint) = hints.pop() {
mat.hint = Some(hint.to_string().clone()) mat.hint = Some(hint.to_string().clone())

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
/home/ubuntu/dev/tmux-thumbs/target/debug/tmux-thumbs -a qwerty /home/ubuntu/dev/tmux-thumbs/target/debug/tmux-thumbs -a qwerty -r