console-rs / dialoguer

Rust utility library for nice command line prompts and similar things

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Tab to select line and move down

urbanogilson opened this issue · comments

The Tab behavior is already defined in multi_select.rs#L249, but the change would likely be in match term.read_key() redefining the behavior of Key::Tab and Key::BackTab to select and move to the next line or back and unselect respectively e.g.

match term.read_key()? {
    Key::Tab => {
        checked[sel] = !checked[sel];
        if sel == !0 {
            sel = 0;
        } else {
            sel = (sel as u64 + 1).rem(self.items.len() as u64) as usize;
        }
    }
    Key::BackTab => {
        if sel == !0 {
            sel = self.items.len() - 1;
        } else {
            sel = ((sel as i64 - 1 + self.items.len() as i64)
                % (self.items.len() as i64)) as usize;
        }
        checked[sel] = !checked[sel];
    }
    Key::ArrowDown | Key::Char('j') => {
        if sel == !0 {
            sel = 0;
        } else {
            sel = (sel as u64 + 1).rem(self.items.len() as u64) as usize;
        }
    }
    Key::ArrowUp | Key::Char('k') => {
        if sel == !0 {
            sel = self.items.len() - 1;
        } else {
            sel = ((sel as i64 - 1 + self.items.len() as i64)
                % (self.items.len() as i64)) as usize;
        }
    }
...
}

Is the project open to changing this behavior?

That's not how the tab shortcut is generally used AFAIK.