PowerShell / ConsoleGuiTools

Modules that mix PowerShell and GUIs/CUIs!
https://www.powershellgallery.com/packages/Microsoft.PowerShell.ConsoleGuiTools
MIT License
776 stars 59 forks source link

OCGV: Feature-Request: Out-ConsoleGridView Skip to next element on select #148

Closed MrFly72 closed 1 year ago

MrFly72 commented 2 years ago

It would be great if Out-ConsoleGridView could have a parameter somehow like -skiptonextelementonselect Or whatever makes sense as parameter name. Basically with this set after a selection of an element, the cursor will move to the next line instead of staying at the same.

MrFly72 commented 2 years ago

@andschwa maybe this one is easy to implement? and it would be a huge comfort improvement, especially as Out-ConsoleGridView might be used a lot with keyboard.

tig commented 2 years ago

Why not have what you suggest be the default behavior?

I'm not a fan of adding more and more options.

MrFly72 commented 2 years ago

In my eyes it can also be the default. I was just curious because changing a current because is also not nice sometimes as others might complain.

andyleejordan commented 2 years ago

No idea if it's easy or not, try it!

tig commented 2 years ago

@andschwa please edit this title to prefix with "OCGV: ". Gracias.

tig commented 2 years ago

The reason I didn't push to get this in quickly is it's more complicated than I originally thought.

I now believe this functionality should be optional and propose -MoveToNextOnSelect:

    -MoveToNextOnSelect
        If specified, pressing SPACE to select an item (when '-OutputMode Multiple' is enabled) will toggle the state of the item and move the selection to the next item in the list.

        Required?                    false
        Position?                    Named
        Accept pipeline input?       false
        Parameter set name           (All)
        Aliases                      None
        Dynamic?                     false
        Accept wildcard characters?  false

Without resorting to some hackery, the right way to implement this is by implementing a new feature in Terminal.Gui's ListView that turns on off/this behavior.

The code in ocgv would thus, be


// in OutConsoleGridviewCmdletCommand.cs:

        /// <summary>
        /// If specified, pressing SPACE to select an item (when '-OutputMode Multiple' is enabled) will toggle the state of the item and move the selection to the next item in the list.
        /// </summary>
        [Parameter(HelpMessage = "If specified, pressing SPACE to select an item (when '-OutputMode Multiple' is enabled) will toggle the state of the item and move the selection to the next item in the list.")]
        public SwitchParameter MoveToNextOnSelect { set; get; }

// In ConsoleGui.cs @ line 387, before the call to win.Add(_listView):

      _listView.MoveToNextOnToggleKey

The reason this is tricky is ListView doesn't currently distinguish between a toggle happening via keypress (SPACE) or some other means.

I've created an issue in Terminal.Gui for this new feature: https://github.com/gui-cs/Terminal.Gui/issues/1962