noneto-cli 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- noneto/__init__.py +1 -0
- noneto/__main__.py +3 -0
- noneto/app.py +113 -0
- noneto/assets/noneto.ico +0 -0
- noneto/audio/__init__.py +1 -0
- noneto/audio/controller.py +427 -0
- noneto/audio/inspector.py +21 -0
- noneto/audio/ipc_unix.py +29 -0
- noneto/audio/ipc_windows.py +94 -0
- noneto/audio/lifetime.py +68 -0
- noneto/audio/media_controls.py +107 -0
- noneto/audio/mpv_install.py +71 -0
- noneto/audio/player.py +222 -0
- noneto/audio/pulse_tap.py +120 -0
- noneto/audio/spectrum.py +44 -0
- noneto/audio/streams.py +101 -0
- noneto/audio/tap.py +208 -0
- noneto/audio/windows_identity.py +79 -0
- noneto/audio/windows_media.py +157 -0
- noneto/auth/__init__.py +1 -0
- noneto/auth/dpapi.py +28 -0
- noneto/auth/service.py +53 -0
- noneto/auth/storage.py +120 -0
- noneto/diagnostics.py +115 -0
- noneto/errors.py +12 -0
- noneto/i18n.py +199 -0
- noneto/platform/__init__.py +1 -0
- noneto/platform/paths.py +27 -0
- noneto/security.py +59 -0
- noneto/services/__init__.py +1 -0
- noneto/services/covers.py +88 -0
- noneto/services/executor.py +83 -0
- noneto/services/library.py +110 -0
- noneto/services/tidal.py +188 -0
- noneto/settings.py +48 -0
- noneto/state/__init__.py +1 -0
- noneto/state/queue.py +130 -0
- noneto/state/writer.py +38 -0
- noneto/ui/__init__.py +1 -0
- noneto/ui/common.py +36 -0
- noneto/ui/cover.py +88 -0
- noneto/ui/dialogs.py +107 -0
- noneto/ui/linux_login.py +57 -0
- noneto/ui/login_window.py +201 -0
- noneto/ui/lyrics.py +142 -0
- noneto/ui/player.py +172 -0
- noneto/ui/quality.py +75 -0
- noneto/ui/queue.py +34 -0
- noneto/ui/terminal.py +65 -0
- noneto/ui/themes.py +352 -0
- noneto/ui/top.py +39 -0
- noneto/ui/tracks.py +139 -0
- noneto/ui/tui.py +601 -0
- noneto/ui/visualizer.py +343 -0
- noneto_cli-1.1.1.dist-info/METADATA +222 -0
- noneto_cli-1.1.1.dist-info/RECORD +59 -0
- noneto_cli-1.1.1.dist-info/WHEEL +4 -0
- noneto_cli-1.1.1.dist-info/entry_points.txt +2 -0
- noneto_cli-1.1.1.dist-info/licenses/LICENSE +21 -0
noneto/ui/themes.py
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"""Color palettes and theme extension API for the terminal interface.
|
|
2
|
+
|
|
3
|
+
The layout uses Textual's semantic CSS variables, so registering another Theme
|
|
4
|
+
can change its colors without rewriting the screen or its widgets.
|
|
5
|
+
|
|
6
|
+
People and agents can register new themes in two ways:
|
|
7
|
+
1. Programmatically via `register_theme(ThemeSpec(...))` or `register_theme(theme, stops=...)`.
|
|
8
|
+
2. Declaratively by dropping a JSON file into `<config_dir>/themes/*.json` (loaded via `load_user_themes()`).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
import json
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
from textual.theme import BUILTIN_THEMES, Theme
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
NAME_PATTERN = re.compile(r"^[a-z0-9][a-z0-9_-]{0,49}$")
|
|
20
|
+
HEX_COLOR_PATTERN = re.compile(r"^#[0-9a-fA-F]{6}$")
|
|
21
|
+
MAX_THEME_FILE_BYTES = 16384
|
|
22
|
+
MAX_STOPS = 16
|
|
23
|
+
ALLOWED_VARIABLES = frozenset({
|
|
24
|
+
"text",
|
|
25
|
+
"text-muted",
|
|
26
|
+
"border",
|
|
27
|
+
"border-blurred",
|
|
28
|
+
"block-cursor-background",
|
|
29
|
+
"block-cursor-foreground",
|
|
30
|
+
"block-cursor-blurred-background",
|
|
31
|
+
"block-cursor-blurred-foreground",
|
|
32
|
+
"block-hover-background",
|
|
33
|
+
"button-foreground",
|
|
34
|
+
"button-color-foreground",
|
|
35
|
+
"input-selection-background",
|
|
36
|
+
"input-selection-foreground",
|
|
37
|
+
"footer-background",
|
|
38
|
+
"footer-key-foreground",
|
|
39
|
+
"scrollbar",
|
|
40
|
+
"scrollbar-background",
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _valid_name(name):
|
|
45
|
+
if not isinstance(name, str) or not NAME_PATTERN.match(name):
|
|
46
|
+
raise ValueError(f"Invalid name: {name!r}")
|
|
47
|
+
return name
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _valid_hex(color):
|
|
51
|
+
if not isinstance(color, str) or not HEX_COLOR_PATTERN.match(color):
|
|
52
|
+
raise ValueError(f"Invalid #rrggbb color: {color!r}")
|
|
53
|
+
return color.lower()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _valid_stops(stops, fallback):
|
|
57
|
+
if not stops:
|
|
58
|
+
return (_valid_hex(fallback),)
|
|
59
|
+
if not isinstance(stops, (list, tuple)) or len(stops) > MAX_STOPS:
|
|
60
|
+
raise ValueError("Visualizer stops must be a sequence of 1 to 16 #rrggbb colors")
|
|
61
|
+
return tuple(_valid_hex(stop) for stop in stops)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True)
|
|
65
|
+
class ThemeSpec:
|
|
66
|
+
"""Declarative specification for a Noneto CLI theme and its visualizer gradient."""
|
|
67
|
+
|
|
68
|
+
name: str
|
|
69
|
+
primary: str
|
|
70
|
+
background: str
|
|
71
|
+
foreground: str = "#f5f5f5"
|
|
72
|
+
secondary: str | None = None
|
|
73
|
+
accent: str | None = None
|
|
74
|
+
surface: str | None = None
|
|
75
|
+
panel: str | None = None
|
|
76
|
+
warning: str | None = None
|
|
77
|
+
error: str | None = None
|
|
78
|
+
success: str | None = None
|
|
79
|
+
dark: bool = True
|
|
80
|
+
stops: tuple[str, ...] = ()
|
|
81
|
+
variables: dict[str, str] = field(default_factory=dict)
|
|
82
|
+
|
|
83
|
+
def __post_init__(self):
|
|
84
|
+
object.__setattr__(self, "name", _valid_name(self.name))
|
|
85
|
+
for field_name in ("primary", "background", "foreground"):
|
|
86
|
+
object.__setattr__(self, field_name, _valid_hex(getattr(self, field_name)))
|
|
87
|
+
for optional_name in ("secondary", "accent", "surface", "panel", "warning", "error", "success"):
|
|
88
|
+
value = getattr(self, optional_name)
|
|
89
|
+
if value is not None:
|
|
90
|
+
object.__setattr__(self, optional_name, _valid_hex(value))
|
|
91
|
+
if not isinstance(self.dark, bool):
|
|
92
|
+
raise ValueError("dark must be a boolean")
|
|
93
|
+
object.__setattr__(self, "stops", _valid_stops(self.stops, self.primary))
|
|
94
|
+
cleaned_vars = {}
|
|
95
|
+
if not isinstance(self.variables, dict):
|
|
96
|
+
raise ValueError("variables must be a dict")
|
|
97
|
+
for key, val in self.variables.items():
|
|
98
|
+
if key in ALLOWED_VARIABLES:
|
|
99
|
+
cleaned_vars[key] = _valid_hex(val)
|
|
100
|
+
object.__setattr__(self, "variables", cleaned_vars)
|
|
101
|
+
|
|
102
|
+
def to_textual_theme(self) -> Theme:
|
|
103
|
+
kwargs = {
|
|
104
|
+
"name": self.name,
|
|
105
|
+
"primary": self.primary,
|
|
106
|
+
"secondary": self.secondary or self.primary,
|
|
107
|
+
"accent": self.accent or self.primary,
|
|
108
|
+
"foreground": self.foreground,
|
|
109
|
+
"background": self.background,
|
|
110
|
+
"surface": self.surface or self.background,
|
|
111
|
+
"panel": self.panel or self.surface or self.background,
|
|
112
|
+
"dark": self.dark,
|
|
113
|
+
"variables": dict(self.variables),
|
|
114
|
+
}
|
|
115
|
+
for optional_key in ("warning", "error", "success"):
|
|
116
|
+
val = getattr(self, optional_key)
|
|
117
|
+
if val is not None:
|
|
118
|
+
kwargs[optional_key] = val
|
|
119
|
+
return Theme(**kwargs)
|
|
120
|
+
|
|
121
|
+
@classmethod
|
|
122
|
+
def from_dict(cls, data: dict) -> "ThemeSpec":
|
|
123
|
+
if not isinstance(data, dict):
|
|
124
|
+
raise ValueError("Theme definition must be a JSON object")
|
|
125
|
+
return cls(
|
|
126
|
+
name=data.get("name"),
|
|
127
|
+
primary=data.get("primary"),
|
|
128
|
+
background=data.get("background"),
|
|
129
|
+
foreground=data.get("foreground", "#f5f5f5" if data.get("dark", True) else "#1c1c1c"),
|
|
130
|
+
secondary=data.get("secondary"),
|
|
131
|
+
accent=data.get("accent"),
|
|
132
|
+
surface=data.get("surface"),
|
|
133
|
+
panel=data.get("panel"),
|
|
134
|
+
warning=data.get("warning"),
|
|
135
|
+
error=data.get("error"),
|
|
136
|
+
success=data.get("success"),
|
|
137
|
+
dark=data.get("dark", True),
|
|
138
|
+
stops=tuple(data.get("stops") or ()),
|
|
139
|
+
variables=data.get("variables") or {},
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
TIDAL_DARK = Theme(
|
|
144
|
+
name="noneto-dark",
|
|
145
|
+
primary="#f5f5f5",
|
|
146
|
+
secondary="#b3b3b3",
|
|
147
|
+
accent="#f5f5f5",
|
|
148
|
+
foreground="#f5f5f5",
|
|
149
|
+
background="#000000",
|
|
150
|
+
surface="#121212",
|
|
151
|
+
panel="#1c1c1c",
|
|
152
|
+
dark=True,
|
|
153
|
+
variables={
|
|
154
|
+
"text": "#f5f5f5",
|
|
155
|
+
"text-muted": "#a6a6a6",
|
|
156
|
+
"border": "#383838",
|
|
157
|
+
"border-blurred": "#292929",
|
|
158
|
+
"block-cursor-background": "#f5f5f5",
|
|
159
|
+
"block-cursor-foreground": "#000000",
|
|
160
|
+
"block-cursor-blurred-background": "#303030",
|
|
161
|
+
"block-cursor-blurred-foreground": "#f5f5f5",
|
|
162
|
+
"block-hover-background": "#292929",
|
|
163
|
+
"button-foreground": "#f5f5f5",
|
|
164
|
+
"button-color-foreground": "#000000",
|
|
165
|
+
"input-selection-background": "#4a4a4a",
|
|
166
|
+
"input-selection-foreground": "#ffffff",
|
|
167
|
+
"footer-background": "#000000",
|
|
168
|
+
"footer-key-foreground": "#f5f5f5",
|
|
169
|
+
"scrollbar": "#555555",
|
|
170
|
+
"scrollbar-background": "#121212",
|
|
171
|
+
},
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
KANAGAWA = Theme(
|
|
175
|
+
name="kanagawa",
|
|
176
|
+
primary="#7e9cd8",
|
|
177
|
+
secondary="#957fb8",
|
|
178
|
+
accent="#ffa066",
|
|
179
|
+
foreground="#dcd7ba",
|
|
180
|
+
background="#1f1f28",
|
|
181
|
+
surface="#2a2a37",
|
|
182
|
+
panel="#16161d",
|
|
183
|
+
warning="#ff9e3b",
|
|
184
|
+
error="#e82424",
|
|
185
|
+
success="#98bb6c",
|
|
186
|
+
dark=True,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
EVERFOREST = Theme(
|
|
190
|
+
name="everforest",
|
|
191
|
+
primary="#a7c080",
|
|
192
|
+
secondary="#7fbbb3",
|
|
193
|
+
accent="#e67e80",
|
|
194
|
+
foreground="#d3c6aa",
|
|
195
|
+
background="#2d353b",
|
|
196
|
+
surface="#343f44",
|
|
197
|
+
panel="#232a2e",
|
|
198
|
+
warning="#dbbc7f",
|
|
199
|
+
error="#e67e80",
|
|
200
|
+
success="#a7c080",
|
|
201
|
+
dark=True,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
VESPER = Theme(
|
|
205
|
+
name="vesper",
|
|
206
|
+
primary="#ffc799",
|
|
207
|
+
secondary="#99ffe4",
|
|
208
|
+
accent="#ffc799",
|
|
209
|
+
foreground="#ffffff",
|
|
210
|
+
background="#101010",
|
|
211
|
+
surface="#1c1c1c",
|
|
212
|
+
panel="#161616",
|
|
213
|
+
warning="#ffc799",
|
|
214
|
+
error="#ff8080",
|
|
215
|
+
success="#99ffe4",
|
|
216
|
+
dark=True,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
SYNTHWAVE_84 = Theme(
|
|
220
|
+
name="synthwave-84",
|
|
221
|
+
primary="#ff7edb",
|
|
222
|
+
secondary="#36f9f6",
|
|
223
|
+
accent="#fede5d",
|
|
224
|
+
foreground="#ffffff",
|
|
225
|
+
background="#262335",
|
|
226
|
+
surface="#34294f",
|
|
227
|
+
panel="#1e1a2b",
|
|
228
|
+
warning="#fede5d",
|
|
229
|
+
error="#fe4450",
|
|
230
|
+
success="#72f1b8",
|
|
231
|
+
dark=True,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
CUSTOM_THEMES = {
|
|
235
|
+
theme.name: theme
|
|
236
|
+
for theme in (TIDAL_DARK, KANAGAWA, EVERFOREST, VESPER, SYNTHWAVE_84)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# Themes offered in the app, in Ctrl+T order.
|
|
240
|
+
THEMES = (
|
|
241
|
+
"noneto-dark",
|
|
242
|
+
"catppuccin-mocha",
|
|
243
|
+
"dracula",
|
|
244
|
+
"tokyo-night",
|
|
245
|
+
"nord",
|
|
246
|
+
"rose-pine",
|
|
247
|
+
"flexoki",
|
|
248
|
+
"catppuccin-latte",
|
|
249
|
+
"rose-pine-dawn",
|
|
250
|
+
"kanagawa",
|
|
251
|
+
"everforest",
|
|
252
|
+
"vesper",
|
|
253
|
+
"synthwave-84",
|
|
254
|
+
"gruvbox",
|
|
255
|
+
"monokai",
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
# Visualizer gradient, left to right across the bars, from each palette's own accent colors.
|
|
259
|
+
VISUALIZER_STOPS = {
|
|
260
|
+
"noneto-dark": ("#4dd0e1", "#5c7cfa", "#b197fc", "#f783ac"),
|
|
261
|
+
"catppuccin-mocha": ("#89b4fa", "#74c7ec", "#94e2d5", "#a6e3a1", "#f9e2af", "#fab387", "#f38ba8", "#cba6f7"),
|
|
262
|
+
"dracula": ("#8be9fd", "#50fa7b", "#f1fa8c", "#ffb86c", "#ff79c6", "#bd93f9"),
|
|
263
|
+
"tokyo-night": ("#7aa2f7", "#7dcfff", "#73daca", "#9ece6a", "#e0af68", "#ff9e64", "#f7768e", "#bb9af7"),
|
|
264
|
+
"nord": ("#5e81ac", "#81a1c1", "#88c0d0", "#8fbcbb", "#a3be8c", "#ebcb8b", "#d08770", "#bf616a", "#b48ead"),
|
|
265
|
+
"rose-pine": ("#31748f", "#9ccfd8", "#c4a7e7", "#ebbcba", "#f6c177", "#eb6f92"),
|
|
266
|
+
"flexoki": ("#4385be", "#3aa99f", "#879a39", "#d0a215", "#da702c", "#d14d41", "#ce5d97", "#8b7ec8"),
|
|
267
|
+
"catppuccin-latte": ("#1e66f5", "#209fb5", "#179299", "#40a02b", "#df8e1d", "#fe640b", "#d20f39", "#8839ef"),
|
|
268
|
+
"rose-pine-dawn": ("#286983", "#56949f", "#907aa9", "#d7827e", "#ea9d34", "#b4637a"),
|
|
269
|
+
"kanagawa": ("#7e9cd8", "#7fb4ca", "#98bb6c", "#dca561", "#ffa066", "#e46876", "#957fb8"),
|
|
270
|
+
"everforest": ("#7fbbb3", "#83c092", "#a7c080", "#dbbc7f", "#e69875", "#e67e80", "#d699b6"),
|
|
271
|
+
"vesper": ("#5a5a5a", "#8c8c8c", "#d4b08c", "#ffc799", "#ffe2cc", "#99ffe4"),
|
|
272
|
+
"synthwave-84": ("#36f9f6", "#72f1b8", "#fede5d", "#ff8b39", "#fe4450", "#ff7edb", "#b893ce"),
|
|
273
|
+
"gruvbox": ("#83a598", "#8ec07c", "#b8bb26", "#fabd2f", "#fe8019", "#fb4934", "#d3869b"),
|
|
274
|
+
"monokai": ("#66d9ef", "#a6e22e", "#e6db74", "#fd971f", "#f92672", "#ae81ff"),
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def register_theme(theme_or_spec, stops=None) -> Theme:
|
|
279
|
+
"""Register a custom theme and its visualizer stops into Noneto CLI.
|
|
280
|
+
|
|
281
|
+
Accepts either a `ThemeSpec`, a `dict` matching `ThemeSpec`, or a Textual `Theme` instance.
|
|
282
|
+
Updates `CUSTOM_THEMES`, `VISUALIZER_STOPS`, and `THEMES` in place so `NonetoApp` picks it up.
|
|
283
|
+
"""
|
|
284
|
+
global THEMES
|
|
285
|
+
if isinstance(theme_or_spec, dict):
|
|
286
|
+
theme_or_spec = ThemeSpec.from_dict(theme_or_spec)
|
|
287
|
+
if isinstance(theme_or_spec, ThemeSpec):
|
|
288
|
+
theme = theme_or_spec.to_textual_theme()
|
|
289
|
+
resolved_stops = _valid_stops(stops, theme.primary) if stops is not None else theme_or_spec.stops
|
|
290
|
+
elif isinstance(theme_or_spec, Theme):
|
|
291
|
+
_valid_name(theme_or_spec.name)
|
|
292
|
+
theme = theme_or_spec
|
|
293
|
+
resolved_stops = _valid_stops(stops, theme.primary)
|
|
294
|
+
else:
|
|
295
|
+
raise TypeError("Expected ThemeSpec, dict, or textual.theme.Theme")
|
|
296
|
+
|
|
297
|
+
if theme.name not in BUILTIN_THEMES:
|
|
298
|
+
CUSTOM_THEMES[theme.name] = theme
|
|
299
|
+
VISUALIZER_STOPS[theme.name] = resolved_stops
|
|
300
|
+
if theme.name not in THEMES:
|
|
301
|
+
THEMES = (*THEMES, theme.name)
|
|
302
|
+
return theme
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def available_themes() -> tuple[str, ...]:
|
|
306
|
+
"""Return the current tuple of registered theme names in Ctrl+T cycle order."""
|
|
307
|
+
return THEMES
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def load_user_themes(directory: Path | str | None = None) -> tuple[str, ...]:
|
|
311
|
+
"""Load declarative `*.json` theme files from `<config_dir>/themes` (or `directory`).
|
|
312
|
+
|
|
313
|
+
Invalid or oversized files are skipped without crashing startup. Returns the names loaded.
|
|
314
|
+
"""
|
|
315
|
+
if directory is None:
|
|
316
|
+
from ..platform.paths import config_dir
|
|
317
|
+
directory = config_dir() / "themes"
|
|
318
|
+
path = Path(directory)
|
|
319
|
+
if not path.is_dir():
|
|
320
|
+
return ()
|
|
321
|
+
loaded = []
|
|
322
|
+
for item in sorted(path.glob("*.json"))[:50]:
|
|
323
|
+
try:
|
|
324
|
+
if not item.is_file():
|
|
325
|
+
continue
|
|
326
|
+
with item.open("rb") as handle:
|
|
327
|
+
raw = handle.read(MAX_THEME_FILE_BYTES + 1)
|
|
328
|
+
if len(raw) > MAX_THEME_FILE_BYTES:
|
|
329
|
+
continue
|
|
330
|
+
spec = ThemeSpec.from_dict(json.loads(raw.decode("utf-8")))
|
|
331
|
+
register_theme(spec)
|
|
332
|
+
loaded.append(spec.name)
|
|
333
|
+
except (OSError, ValueError, TypeError):
|
|
334
|
+
continue
|
|
335
|
+
return tuple(loaded)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def gradient(stops, count):
|
|
339
|
+
"""`count` colors evenly spread over the stops, as #rrggbb."""
|
|
340
|
+
if count <= 0:
|
|
341
|
+
return []
|
|
342
|
+
points = [tuple(int(stop[i:i + 2], 16) for i in (1, 3, 5)) for stop in stops]
|
|
343
|
+
if len(points) == 1 or count == 1:
|
|
344
|
+
return [stops[0]] * count
|
|
345
|
+
colors = []
|
|
346
|
+
for index in range(count):
|
|
347
|
+
position = index / (count - 1) * (len(points) - 1)
|
|
348
|
+
left = min(int(position), len(points) - 2)
|
|
349
|
+
share = position - left
|
|
350
|
+
mixed = (round(a + (b - a) * share) for a, b in zip(points[left], points[left + 1]))
|
|
351
|
+
colors.append("#" + "".join(f"{channel:02x}" for channel in mixed))
|
|
352
|
+
return colors
|
noneto/ui/top.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Top bar: logo, Library ▾, search box and the quality badge."""
|
|
2
|
+
from textual.containers import Horizontal
|
|
3
|
+
from textual.widgets import Button, Input, Static
|
|
4
|
+
|
|
5
|
+
from ..i18n import _
|
|
6
|
+
from .common import clean
|
|
7
|
+
from .quality import QualityBadge
|
|
8
|
+
|
|
9
|
+
CSS = """
|
|
10
|
+
#top { height: 5; background: $panel; padding: 1 0; }
|
|
11
|
+
#top > #quality { margin-top: 1; }
|
|
12
|
+
#top > Button { margin: 1 1 0 0; }
|
|
13
|
+
#brand { width: auto; height: 3; padding: 0 1 0 2; text-style: bold; }
|
|
14
|
+
#library { max-width: 32; background: $surface; }
|
|
15
|
+
#search { width: 1fr; height: 3; border: round $border; padding: 0 1; margin-right: 1; background: $panel; }
|
|
16
|
+
#search:focus { border: round $primary; background: $panel; }
|
|
17
|
+
#search-button { min-width: 8; }
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# Noneto symbol (docs/assets/noneto-symbol-*.svg) in half blocks: 6×6 pixels over the 3-row top bar.
|
|
21
|
+
# The symbol is the N of NONETO, as in the logo.
|
|
22
|
+
BRAND = "██▄ █\n█ ▀▄ █ ONETO\n█ ▀██"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TopBar(Horizontal):
|
|
26
|
+
"""Layout only: the app handles Library, Search and the badge updates."""
|
|
27
|
+
|
|
28
|
+
def __init__(self, user_name, quality, **kwargs):
|
|
29
|
+
super().__init__(**kwargs)
|
|
30
|
+
self.user_name, self.quality = user_name, quality
|
|
31
|
+
|
|
32
|
+
def compose(self):
|
|
33
|
+
yield Static(BRAND, id="brand", markup=False)
|
|
34
|
+
library = Button(_("Library ▾"), id="library")
|
|
35
|
+
library.tooltip = _("{name}'s playlists · Ctrl+L", name=clean(self.user_name or _("User")))
|
|
36
|
+
yield library
|
|
37
|
+
yield Input(placeholder=_("Search songs or playlists…"), max_length=200, id="search")
|
|
38
|
+
yield Button(_("Search"), id="search-button", variant="primary")
|
|
39
|
+
yield QualityBadge(self.quality, id="quality")
|
noneto/ui/tracks.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Songs tab: the track table, filled in batches, with ▷ on the song that is playing."""
|
|
2
|
+
import asyncio
|
|
3
|
+
|
|
4
|
+
from rich.text import Text
|
|
5
|
+
from textual.coordinate import Coordinate
|
|
6
|
+
from textual.widgets import DataTable
|
|
7
|
+
|
|
8
|
+
from ..i18n import _
|
|
9
|
+
from .common import album, artist, clean, duration
|
|
10
|
+
|
|
11
|
+
CSS = """
|
|
12
|
+
#tracks { height: 1fr; background: $background; }
|
|
13
|
+
DataTable > .datatable--header { background: $background; color: $text-muted; text-style: bold; }
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TrackTable(DataTable):
|
|
18
|
+
"""Play a track with one mouse click while keeping row selection for actions.
|
|
19
|
+
|
|
20
|
+
`tracks` always holds the whole list so Play gets every song. Rows appear 100 at first and
|
|
21
|
+
then in batches of up to 500, yielding the loop between them; `reset()` drops pending batches.
|
|
22
|
+
The title column takes the width the others leave and cuts long names with "…", so the
|
|
23
|
+
table never scrolls sideways and Duration stays visible.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, **kwargs):
|
|
27
|
+
super().__init__(**kwargs)
|
|
28
|
+
self.tracks = []
|
|
29
|
+
self._current_id = None
|
|
30
|
+
self._revision = 0
|
|
31
|
+
self._fill_task = None
|
|
32
|
+
|
|
33
|
+
def on_mount(self):
|
|
34
|
+
self._mark_key, self._title_key, self._duration_key = self.add_columns("#", _("Title"), _("Duration"))
|
|
35
|
+
self.columns[self._title_key].auto_width = False
|
|
36
|
+
self._fit_title()
|
|
37
|
+
|
|
38
|
+
def on_resize(self):
|
|
39
|
+
self._fit_title()
|
|
40
|
+
|
|
41
|
+
def _fit_title(self):
|
|
42
|
+
# The vertical scrollbar is always reserved so the width doesn't jump when it appears.
|
|
43
|
+
mark = max(1, len(str(len(self.tracks)))) + 2 * self.cell_padding
|
|
44
|
+
others = mark + self.columns[self._duration_key].get_render_width(self)
|
|
45
|
+
free = self.size.width - self.styles.scrollbar_size_vertical - others - 2 * self.cell_padding
|
|
46
|
+
title = self.columns[self._title_key]
|
|
47
|
+
if title.width != max(10, free):
|
|
48
|
+
title.width = max(10, free)
|
|
49
|
+
# Textual has no public call to resize a column: drop its render caches, which are not
|
|
50
|
+
# keyed by width, and let it recompute the virtual size (checked against textual 8.2.8).
|
|
51
|
+
self._clear_caches()
|
|
52
|
+
self._require_update_dimensions = True
|
|
53
|
+
self.refresh()
|
|
54
|
+
|
|
55
|
+
async def _on_click(self, event):
|
|
56
|
+
row = event.style.meta.get("row")
|
|
57
|
+
column = event.style.meta.get("column")
|
|
58
|
+
if (event.button == 1 and isinstance(row, int) and 0 <= row < self.row_count
|
|
59
|
+
and isinstance(column, int) and column >= 0):
|
|
60
|
+
coordinate = Coordinate(row, column)
|
|
61
|
+
self.cursor_coordinate = coordinate
|
|
62
|
+
row_key, _column = self.coordinate_to_cell_key(coordinate)
|
|
63
|
+
self.post_message(DataTable.RowSelected(self, row, row_key))
|
|
64
|
+
event.stop()
|
|
65
|
+
return
|
|
66
|
+
await super()._on_click(event)
|
|
67
|
+
|
|
68
|
+
def selected(self):
|
|
69
|
+
index = self.cursor_row
|
|
70
|
+
return self.tracks[index] if 0 <= index < len(self.tracks) else None
|
|
71
|
+
|
|
72
|
+
def reset(self):
|
|
73
|
+
self._revision += 1
|
|
74
|
+
if self._fill_task is not None:
|
|
75
|
+
self._fill_task.cancel()
|
|
76
|
+
self._fill_task = None
|
|
77
|
+
self.tracks = []
|
|
78
|
+
self.clear()
|
|
79
|
+
|
|
80
|
+
def show(self, tracks, append=False):
|
|
81
|
+
if not append:
|
|
82
|
+
self._revision += 1
|
|
83
|
+
if self._fill_task is not None:
|
|
84
|
+
self._fill_task.cancel()
|
|
85
|
+
self._fill_task = None
|
|
86
|
+
self.clear()
|
|
87
|
+
self.tracks = []
|
|
88
|
+
self.tracks.extend(tracks)
|
|
89
|
+
if self._fill_task is None:
|
|
90
|
+
self._fill(self._revision)
|
|
91
|
+
|
|
92
|
+
def set_current(self, track_id):
|
|
93
|
+
previous, self._current_id = self._current_id, track_id
|
|
94
|
+
for index, track in enumerate(self.tracks):
|
|
95
|
+
if index < self.row_count and getattr(track, "id", None) in (previous, track_id):
|
|
96
|
+
self.update_cell_at(Coordinate(index, 0), self._mark(index, track))
|
|
97
|
+
|
|
98
|
+
async def cancel_fill(self):
|
|
99
|
+
if self._fill_task is not None:
|
|
100
|
+
self._fill_task.cancel()
|
|
101
|
+
try:
|
|
102
|
+
await self._fill_task
|
|
103
|
+
except asyncio.CancelledError:
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
def _mark(self, index, track):
|
|
107
|
+
if self._current_id is not None and getattr(track, "id", None) == self._current_id:
|
|
108
|
+
return Text("▷", style="bold")
|
|
109
|
+
return Text(str(index + 1), style="dim")
|
|
110
|
+
|
|
111
|
+
def _fill(self, revision):
|
|
112
|
+
if revision != self._revision:
|
|
113
|
+
return
|
|
114
|
+
start = self.row_count
|
|
115
|
+
batch = 100 if self._fill_task is None else 500
|
|
116
|
+
for index in range(start, min(start + batch, len(self.tracks))):
|
|
117
|
+
track = self.tracks[index]
|
|
118
|
+
title = Text(clean(track.name), style="bold", no_wrap=True, overflow="ellipsis")
|
|
119
|
+
title.append(f"\n{artist(track)} · {album(track)}", style="dim")
|
|
120
|
+
self.add_row(self._mark(index, track), title,
|
|
121
|
+
Text(duration(getattr(track, "duration", 0)), style="dim"), height=2)
|
|
122
|
+
self._fit_title() # more rows can mean one more digit in the # column
|
|
123
|
+
if self.row_count < len(self.tracks) and self._fill_task is None:
|
|
124
|
+
self._fill_task = asyncio.create_task(self._fill_remaining(revision))
|
|
125
|
+
|
|
126
|
+
async def _fill_remaining(self, revision):
|
|
127
|
+
try:
|
|
128
|
+
while self.is_mounted and revision == self._revision:
|
|
129
|
+
await asyncio.sleep(0) # Yield without a per-batch Windows timer wakeup.
|
|
130
|
+
if revision != self._revision or not self.is_mounted:
|
|
131
|
+
return
|
|
132
|
+
self._fill(revision)
|
|
133
|
+
if self.row_count >= len(self.tracks):
|
|
134
|
+
return
|
|
135
|
+
except Exception as error:
|
|
136
|
+
self.app._handle_exception(error)
|
|
137
|
+
finally:
|
|
138
|
+
if revision == self._revision:
|
|
139
|
+
self._fill_task = None
|