altsem / gitu

A TUI Git client inspired by Magit
MIT License
1.74k stars 89 forks source link

Implement command arguments #36

Closed altsem closed 5 months ago

altsem commented 6 months ago

Build support for passing flags to commands (for example git push --force-with-lease, or P-fp in Magit).

image

frank-lenormand commented 6 months ago

Given v0.6.2, I would recommend the following:

  1. Allow all lettered core commands to be called with the alt modifier.
  2. Display all available optional flags in a new window, similar to the screenshot in the body of this issue:

    • If all available options have a single-letter flag (I think that’s the case), then hitting the associated key should enable that option. For example: -f/--force for git push would be used upon hitting the f key.
    • Otherwise, an arbitrary letter that doesn’t collide with the others on screen could be highlighted and used as trigger, similarly to how btop does it:

  3. If an option requires an argument, a prompt could be displayed (in the case of an arbitrary value) or another window (in the case of a fixed set of choices).

Example:

# Run Gitu
$ gitu

# Push the branch with argument
alt-p

# Select the force flag in the upcoming window
f

# Gitu runs `git push --force`

HTH!

altsem commented 5 months ago

I appreciate the input, think that most people would expect magit-like bindings out of gitu. I'm unfamiliar with btop, perhaps there's a way to design it configurable.

I know alt can be problematic for mac terminal users with non-us layouts.

Perhaps if the dash was included in the bindings table -f (for --force-with-lease).

You'd just have to copy the default keymap and change: -f -> f etc. p -> alt-p

Externalizing keymap configuration becomes a whole other issue it feels like though.

mattgallagher92 commented 5 months ago

I'm excited to see so much activity on this library! I use Magit with vi-style keybindings and would love to have a similar experience outside of Emacs.

Just wanted to note that this issue is the main blocker stopping me (so maybe others too?) from switching to gitu - I fairly regularly amend commits or interactively rebase branches that I've pushed, hence often force-with-lease-push too.

frank-lenormand commented 5 months ago

I realised that the functionality needs to assume that multiple flags might need to be toggled, which the single-modifier proposal doesn’t solve.

Alternatively, here’s a way that e.g. Kitty (and some Vim-type bindings for the browser I can’t remember, whenever jumping to a hyperlink) uses:

  1. In the menu that shows all possible flags to be passed to the underlying command, a special keyboard mapping is hit. Example: shift+ctrl+e

  2. Single letters (or combinations of successive letters, to avoid collisions) are highlighted on screen. They must be already visible prior to hitting the combination above, or be generated and inserted dynamically into view. Examples (brackets = highlighted):

    - `-[f] force push`
    - `[f]orce push`
    - `[0] force push`
    - `[f]orce [p]ush`
    - [00] force push`
  3. The use hits the highlighted letters/combinations associated with the flags to select.

    1. a. If any parameters are required, they are prompted for.
    2. b. If optional parameters are possible, hitting the validation key (enter) and leaving the prompt empty does not pass any value to the optional flag.
  4. Selected flags (or their associated letter) should be shown somewhere on the view. Example: Selected flags: -f

HTH.

Externalizing keymap configuration becomes a whole other issue it feels like though.

Yes, and a ton of work too! If you don’t particularly want to tackle this now, I reckon it’s best to focusing on finding good defaults, first.

altsem commented 5 months ago

Got something working for a starter. It only supports true/false flags, and it only introduces --force-with-lease so far. Should be easy to add more boolean flags now.