~callum/barszcz

f3f868f95a57a10d374def0907beb6cb2dbe997a — Callum Brown 1 year, 10 months ago eb88de5
Add `more` command
2 files changed, 41 insertions(+), 0 deletions(-)

M README.md
M beetsplug/barszcz.py
M README.md => README.md +2 -0
@@ 49,6 49,7 @@ Required arguments are CAPITALISED.
| focus [INDEX] |            | Change focus to the thing at the given [INDEX]. A negative [INDEX] focuses the last thing. |
| up [n]        |            | Change focus up [n] things (wraps). Default: [n] = 1. |
| down [n]      |            | Change focus down [n] things (wraps). Default: [n] = 1. |
| more          |            | Show more information about the focused thing. If an album or item is focused, its attributes will be listed. If an attribute is focused, albums and items with that attribute will be listed. |
|               |            | Blank command clears input line. |




@@ 133,5 134,6 @@ barszcz:
		f: focus {}
		gg: focus 0
		G: focus -1
		KEY_ENTER: more
		KEY_ESCAPE: ""
```

M beetsplug/barszcz.py => beetsplug/barszcz.py +39 -0
@@ 45,6 45,7 @@ config["barszcz"].add(
            "f": "focus {}",
            "gg": "focus 0",
            "G": "focus -1",
            "KEY_ENTER": "more",
            "KEY_ESCAPE": "", # Clears input line
        },
    }


@@ 208,6 209,18 @@ class HeadingThing(Thing):
        self.height = len(self.info)


class AttributeThing(Thing):
    """A Thing for displaying the attributes of Items and Albums."""
    # Don't leave big gaps between the attributes
    gap = gap_lines("small")

    def __init__(self, key, value):
        self.key = key
        self.value = value
        self.info = [[key, value, 0.5]]
        self.height = 1


class LibModelThing(Thing):
    """A Thing representing a beets LibModel (Item or Album) object."""



@@ 383,6 396,10 @@ class Group:
        # Refresh so the change in focus can be seen
        self.refresh()

    def focused_thing(self):
        """Return the focused Thing."""
        return self.things[self.focus]


class Barszcz:
    running = True


@@ 459,6 476,25 @@ class Barszcz:
        current_focus = self.current_group.focus
        self.focus(current_focus + n)

    def more(self):
        """Display more information about the focused `Thing`.

        If the focused `Thing` is a `LibModelThing`, display its attributes.
        If it is an `AttributeThing`, list `Item`s and `Album`s with that
        attribute
        """
        thing = self.current_group.focused_thing()
        if isinstance(thing, LibModelThing):
            lm = thing.libmodel
            # Get all fields, including computed ones
            attributes = [AttributeThing(k, str(lm.get(k))) for k in lm.keys()]
            self.current_group = Group(
                [thing] + attributes,
                *self.group_dimensions,
            )
        elif isinstance(thing, AttributeThing):
            return self.ls(f"{thing.key}:{thing.value}")

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



@@ 513,6 549,9 @@ class Barszcz:
            # List only items
            return self.ls(" ".join(split[1:]), albums=False)

        elif split[0] == "more":
            return self.more()

        else:
            return f"Unrecognised command '{split[0]}'"