Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shortcut to select line and move down #1

Open
muralikodali opened this issue Aug 12, 2023 · 7 comments
Open

shortcut to select line and move down #1

muralikodali opened this issue Aug 12, 2023 · 7 comments
Labels
question Further information is requested

Comments

@muralikodali
Copy link

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?

@urbanogilson
Copy link
Owner

You can go to next and previous page using left ← and right → arrow keys. Is that what you meant?

@urbanogilson urbanogilson added the question Further information is requested label Aug 13, 2023
@muralikodali
Copy link
Author

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.

@urbanogilson
Copy link
Owner

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.

@urbanogilson
Copy link
Owner

Issue asking if they are open to accepting this change console-rs/dialoguer#272

@urbanogilson
Copy link
Owner

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

@muralikodali
Copy link
Author

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

@urbanogilson
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants