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")
.help("Reverse the order for assigned hints")
.long("reverse")
.short("r")
.takes_value(true))
.short("r"))
.arg(Arg::with_name("excluded")
.help("Excluded keys from the alphabet")
.long("excluded")
@ -46,6 +45,7 @@ fn app_args<'a> () -> clap::ArgMatches<'a> {
fn main() {
let args = app_args();
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 output = String::from_utf8_lossy(&execution.stdout);
@ -70,7 +70,7 @@ fn main() {
}
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();
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 patterns = Vec::new();
@ -67,6 +67,10 @@ impl<'a> State<'a> {
let alphabet = super::alphabets::get_alphabet(self.alphabet);
let mut hints = alphabet.hints(matches.len());
if reverse {
hints.reverse();
}
for mat in &mut matches {
if let Some(hint) = hints.pop() {
mat.hint = Some(hint.to_string().clone())

View File

@ -1,3 +1,3 @@
#!/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