From becc3e2c53aa370ccd30dd3f0cd2561410a4bf7c Mon Sep 17 00:00:00 2001 From: Olezhich Date: Mon, 9 Mar 2026 00:29:28 +0300 Subject: [PATCH] arrow navigation implemented --- audiotagloader/app.py | 47 ++++++++++++++++++++++++++++++++++--------- poetry.lock | 44 +++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 3 files changed, 81 insertions(+), 11 deletions(-) diff --git a/audiotagloader/app.py b/audiotagloader/app.py index 001f893..3b1315d 100644 --- a/audiotagloader/app.py +++ b/audiotagloader/app.py @@ -11,6 +11,16 @@ from .cache import cache +import questionary + +custom_style = questionary.Style( + [ + ("selected", "#ffffff bg:#0066cc"), + ("highlighted", "#ffffff bg:#0066cc"), + ("pointer", "#ff0000 bold"), + ] +) + class App: def __init__(self, target_dir: Path): @@ -134,21 +144,38 @@ def get_track_tags_by_artist( ) -> tuple[Album, Image, Tracklist]: artists = self._get_artists_by_name(artist_name) - for i in range(len(artists)): - print(f"[{i}] {artists[i].name}") + choices = [] + for i, artist in enumerate(artists): + choices.append( + questionary.Choice(title=f"[{i:02d}] {artist.name}", value=artist) + ) - current_artist = artists[ - max(0, min(MAX_PROPOSED_LEN - 1, int(input("select artist: ")))) - ] + current_artist = questionary.select( + "Select artist:", + style=custom_style, + choices=choices, + ).ask() albums = self._get_albums_by_artist(current_artist) - for i in range(len(albums)): - print(f"[{i:02d}] {albums[i].year} - {albums[i].title} {albums[i].id}") + max_title_len = min(max(max(len(a.title) for a in albums), 40), 40) + + choices = [] + for i, album in enumerate(albums): + title = album.title + if len(title) > 40: + title = title[:37] + "..." + title_str = ( + f"[{i:02d}] {album.year:04d} - {title:<{max_title_len}} - {album.id}" + ) + + choices.append(questionary.Choice(title=title_str, value=album)) - current_album = albums[ - max(0, min(len(albums) - 1, int(input("select album: ")))) - ] + current_album = questionary.select( + "Select album:", + style=custom_style, + choices=choices, + ).ask() image = self._get_cover_image(current_album.id) tracks = self._get_tracklist(current_album.id) diff --git a/poetry.lock b/poetry.lock index 4fdc438..efccf12 100644 --- a/poetry.lock +++ b/poetry.lock @@ -451,6 +451,21 @@ optional = ["typing-extensions (>=4)"] re2 = ["google-re2 (>=1.1)"] tests = ["pytest (>=9)", "typing-extensions (>=4.15)"] +[[package]] +name = "prompt-toolkit" +version = "3.0.52" +description = "Library for building powerful interactive command lines in Python" +optional = false +python-versions = ">=3.8" +groups = ["main"] +files = [ + {file = "prompt_toolkit-3.0.52-py3-none-any.whl", hash = "sha256:9aac639a3bbd33284347de5ad8d68ecc044b91a762dc39b7c21095fcd6a19955"}, + {file = "prompt_toolkit-3.0.52.tar.gz", hash = "sha256:28cde192929c8e7321de85de1ddbe736f1375148b02f2e17edd840042b1be855"}, +] + +[package.dependencies] +wcwidth = "*" + [[package]] name = "pydantic" version = "2.12.5" @@ -637,6 +652,21 @@ files = [ [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "questionary" +version = "2.1.1" +description = "Python library to build pretty command line user prompts ⭐️" +optional = false +python-versions = ">=3.9" +groups = ["main"] +files = [ + {file = "questionary-2.1.1-py3-none-any.whl", hash = "sha256:a51af13f345f1cdea62347589fbb6df3b290306ab8930713bfae4d475a7d4a59"}, + {file = "questionary-2.1.1.tar.gz", hash = "sha256:3d7e980292bb0107abaa79c68dd3eee3c561b83a0f89ae482860b181c8bd412d"}, +] + +[package.dependencies] +prompt_toolkit = ">=2.0,<4.0" + [[package]] name = "redis" version = "7.2.0" @@ -813,7 +843,19 @@ h2 = ["h2 (>=4,<5)"] socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] zstd = ["backports-zstd (>=1.0.0) ; python_version < \"3.14\""] +[[package]] +name = "wcwidth" +version = "0.6.0" +description = "Measures the displayed width of unicode strings in a terminal" +optional = false +python-versions = ">=3.8" +groups = ["main"] +files = [ + {file = "wcwidth-0.6.0-py3-none-any.whl", hash = "sha256:1a3a1e510b553315f8e146c54764f4fb6264ffad731b3d78088cdb1478ffbdad"}, + {file = "wcwidth-0.6.0.tar.gz", hash = "sha256:cdc4e4262d6ef9a1a57e018384cbeb1208d8abbc64176027e2c2455c81313159"}, +] + [metadata] lock-version = "2.1" python-versions = ">=3.12" -content-hash = "1f76bd0078157a2f7e42c0ebe2e09b6a123b5b4f15901410713c2f3cf6f6ff62" +content-hash = "3381fd2dddde02a45e0ec75a79128c842411bd68a8f64d1052bae6c95d7397b9" diff --git a/pyproject.toml b/pyproject.toml index 8cf2e6c..c4a132a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ dependencies = [ "pydantic (>=2.12.5,<3.0.0)", "redis (>=7.2.0,<8.0.0)", "typer (>=0.24.1,<0.25.0)", + "questionary (>=2.1.1,<3.0.0)", ] [tool.poetry]