lineselect
lineselect copied to clipboard
shortcut to select line and move down
to select larger area of text, it will be better to have option to select the line and move down rather than moving to each line and selecting it. is there any option to do so?
You can go to next and previous page using left ←
and right →
arrow keys. Is that what you meant?
what i mean is, we have to select each line in two steps. first we get down to next line by pressing 'j'. After that we need to press 'space' key to select that line. If a shortcut key (like 'tab' key) is provided to move and select at the same time, we can select multiple lines with ease.
I'd like to see this feature implemented in the console-rs/dialoguer library, but the Tab
behavior is already defined in multi_select.rs#L249, and I'm not sure the maintainers want to change that.
The change would be probably in match term.read_key()
redefining the behavior of Key::Tab
and Key::BackTab
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;
}
}
...
}
We can ask them if this change would be accepted there.
Issue asking if they are open to accepting this change https://github.com/console-rs/dialoguer/issues/272
I modified the library to test how this feature would work and it is available in the https://github.com/urbanogilson/lineselect/tree/1-shortcut-to-select-line-and-move-down branch. You can see if this is what you expect ls | cargo run
tab behaviour working as intended. terminal output is showing output '? Pick some lines: [Page 1/4]' many times.
text file showing output of terminal is attached. 1508-194437.txt
It's great to hear that the behavior is as expected! However, please keep in mind that there might still be some corner cases that the current implementation might not cover.
I'm eagerly awaiting input from the maintainers of dialoguer before making a final decision here.