pms icon indicating copy to clipboard operation
pms copied to clipboard

Support counts in commands

Open tremby opened this issue 6 years ago • 8 comments

I imagine this will be quite an undertaking, but if we want PMS to be more vim-like (and I certainly do) it needs to support counts before commands. For example 4j to move the cursor down four times, 2gt to go to the second tab.

tremby avatar Aug 09 '17 17:08 tremby

Absolutely. I support this idea. I don't imagine it will be an enormous amount of work, since all commands already support operating on a selection of tracks.

kimtore avatar Aug 10 '17 07:08 kimtore

I'm wondering how this would work. Would the system dispatch a single command which now has a new concept of the count being passed to it, or would it dispatch the regular command count times?

I imagine it'd have to be the former, because gt gt is not the same as 2gt.

tremby avatar Aug 10 '17 23:08 tremby

Each command would have to define what the count means to it, I think.

From an architecture point of view, what about this?

Command stays as it is. Things which directly implement Command don't support counts, and you get an error if you try to call them with a count.

A new class CountableCommand (or something) descends from Command an accepts a count, and it is passed to the handler method as an extra argument. The command decides what to do with this.

For convenience, a new class RepeatableCommand (or something) descends from CountableCommand and handles the count by simply running its handler count times.

(I don't know Go -- totally likely a different architecture is better!)

tremby avatar Aug 10 '17 23:08 tremby

The Command class should definitely be aware of the count, and execute as needed. Otherwise, e.g. 1000x would send thousand commands to the MPD server, instead of issuing a single command.

Is there anything to be gained from separating "one-off" commands from countable commands on a class level? In my opinion, it gains nothing except adding complexity. If the command explicitly does not support counting, it could just return an error.

kimtore avatar Aug 11 '17 07:08 kimtore

Fair enough. I just thought it might be nice for convenience, reducing code duplication in writing the same boilerplate error code for several commands.

tremby avatar Aug 11 '17 15:08 tremby

I'm not really certain it would be boilerplate code. As every command would have to handle the count, they might as well implement their functions to be countable from the start. As for the commands that doesn't support count or it doesn't make sense (such as play, pause, stop, single, repeat, etc.) they could also possibly silently ignore the counter?

kimtore avatar Aug 11 '17 17:08 kimtore

I wonder how commands in vim which don't support a count work. (Can't check just now; off camping)

tremby avatar Aug 11 '17 17:08 tremby

This is related to #92.

kimtore avatar Sep 09 '17 11:09 kimtore