~callum/barszcz

4e0f10ece7b005ef58e5ca384794042d03d90e5d — Callum Brown 1 year, 11 months ago 0351708
Add argument to `up` and `down`.

So can go up/down multiple things at once.
Add shortcut for this.
2 files changed, 32 insertions(+), 13 deletions(-)

M README.md
M beetsplug/barszcz.py
M README.md => README.md +6 -5
@@ 45,20 45,21 @@ Positional arguments of commands are in [brackets].
| lista [query] | lsa        | List albums matching the [query] |
| listi [query] | lsi        | List items matching the [query] |
| focus [index] |            | Change focus to the thing at the given [index]. A negative [index] focuses the last thing. |
| up            |            | Change focus up one thing (wraps) |
| down          |            | Change focus down one thing (wraps) |
| up [n]        |            | Change focus up [n] things (wraps). Default: [n] = 1. |
| down [n]      |            | Change focus down [n] things (wraps). Default: [n] = 1. |


### Shortcuts

Single and multi-character shortcuts can be used to execute commands without
typing them in. An `[n]` preceding a shortcut indicates a sequence of digits.
typing them in.
An `[n]` preceding a shortcut indicates an optional sequence of digits.
The available shortcuts are:

| shortcut   | command |
| ---        | --- |
| KEY_UP     | up |
| KEY_DOWN   | down |
| [n]KEY_UP     | up [n] |
| [n]KEY_DOWN   | down [n] |
| [n]f       | focus [n] |
| gg         | focus 1 |
| G          | focus -1 |

M beetsplug/barszcz.py => beetsplug/barszcz.py +26 -8
@@ 355,8 355,8 @@ class Barszcz:
    running = True
    # Will be moved to configuration at some point
    shortcuts = {
        "KEY_UP": "up",
        "KEY_DOWN": "down",
        "KEY_UP": "up {}",
        "KEY_DOWN": "down {}",
        "f": "focus {}",
        "gg": "focus 1",
        "G": "focus -1",


@@ 425,13 425,15 @@ class Barszcz:
    def focus(self, index):
        self.current_group.change_focus(index)

    def up(self):
    def up(self, n):
        """Change focus up `n` things."""
        current_focus = self.current_group.focus
        self.focus(current_focus - 1)
        self.focus(current_focus - n)

    def down(self):
    def down(self, n):
        """Change focus down `n` things."""
        current_focus = self.current_group.focus
        self.focus(current_focus + 1)
        self.focus(current_focus + n)

    def do_command(self, command):
        """"Attempts to parse a command string and execute it.


@@ 446,10 448,26 @@ class Barszcz:
            return self.quit_barszcz()

        elif split[0] == "up":
            return self.up()
            # `up` takes an optional integer argument, default 1
            if len(split) > 1:
                try:
                    n = int(split[1])
                except ValueError:
                    return f"ERROR: {split[1]} is not an integer!"
            else:
                n = 1
            return self.up(n)

        elif split[0] == "down":
            return self.down()
            # `down` takes an optional integer argument, default 1
            if len(split) > 1:
                try:
                    n = int(split[1])
                except ValueError:
                    return f"ERROR: {split[1]} is not an integer!"
            else:
                n = 1
            return self.down(n)

        elif split[0] == "focus":
            if len(split) != 2: