kimtore / pms

Practical Music Search is an interactive Vim-like console client for the Music Player Daemon.
https://ambientsound.github.io/pms/
MIT License
250 stars 23 forks source link

Support counts in commands #86

Open tremby opened 7 years ago

tremby commented 7 years ago

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.

kimtore commented 7 years ago

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.

tremby commented 7 years ago

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 commented 7 years ago

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!)

kimtore commented 7 years ago

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.

tremby commented 7 years ago

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

kimtore commented 7 years ago

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?

tremby commented 7 years ago

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

kimtore commented 7 years ago

This is related to #92.