ui-theme 0.1.0__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.
- ui_theme/__init__.py +4 -0
- ui_theme/backend.py +81 -0
- ui_theme/catalog.py +513 -0
- ui_theme/clock.py +141 -0
- ui_theme/colour.py +223 -0
- ui_theme/depth.py +48 -0
- ui_theme/effects.py +449 -0
- ui_theme/py.typed +0 -0
- ui_theme/scheme.py +426 -0
- ui_theme/splash.py +76 -0
- ui_theme/wal.py +71 -0
- ui_theme-0.1.0.dist-info/METADATA +11 -0
- ui_theme-0.1.0.dist-info/RECORD +14 -0
- ui_theme-0.1.0.dist-info/WHEEL +4 -0
ui_theme/scheme.py
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
"""Colour schemes: what each semantic colour is in one theme.
|
|
2
|
+
|
|
3
|
+
Something drawn asks for a `ThemeColour` (primary, warning, muted, ...); the
|
|
4
|
+
active scheme supplies it. Every scheme states the eight core colours. It may
|
|
5
|
+
also state layer colours (surface, panel, boost) and element colours; where it
|
|
6
|
+
does not, each backend lays out its own surfaces.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections.abc import Callable, Mapping
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from enum import Enum
|
|
14
|
+
from typing import TYPE_CHECKING, ClassVar, Self, cast
|
|
15
|
+
|
|
16
|
+
from metaclass_registry import AutoRegisterMeta # type: ignore[import-untyped]
|
|
17
|
+
|
|
18
|
+
from ui_theme.colour import (
|
|
19
|
+
Colour,
|
|
20
|
+
PaletteSource,
|
|
21
|
+
Rgb,
|
|
22
|
+
TerminalOwnedPalette,
|
|
23
|
+
TerminalPalette,
|
|
24
|
+
ThemeValue,
|
|
25
|
+
require_terminal_palette,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
if TYPE_CHECKING:
|
|
29
|
+
from ui_theme.backend import TerminalBackend
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ThemePart:
|
|
33
|
+
"""A declared interface part owns its variable name."""
|
|
34
|
+
|
|
35
|
+
name: ClassVar[str]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ThemeColour(ThemePart, metaclass=AutoRegisterMeta):
|
|
39
|
+
"""A semantic colour; its `name` is the one every backend and scheme uses."""
|
|
40
|
+
|
|
41
|
+
__registry_key__ = "name"
|
|
42
|
+
__registry__: ClassVar[dict[str, type[ThemeColour]]]
|
|
43
|
+
# Drawn behind content rather than as content (decides the terminal default).
|
|
44
|
+
background: ClassVar[bool] = False
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def members(cls) -> tuple[type[Self], ...]:
|
|
48
|
+
return tuple(member for member in ThemeColour.__registry__.values() if issubclass(member, cls))
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def rgb(cls, scheme: ColourScheme) -> Rgb:
|
|
52
|
+
"""This colour in 24 bits under `scheme`; a terminal colour is read from its palette."""
|
|
53
|
+
return cls.resolve_rgb(lambda member: scheme.colours[member].rgb(
|
|
54
|
+
scheme.terminal.resolve(require_terminal_palette), background=member.background))
|
|
55
|
+
|
|
56
|
+
@classmethod
|
|
57
|
+
def resolve_rgb(cls, read: Callable[[type[ThemeColour]], Rgb]) -> Rgb:
|
|
58
|
+
"""Resolve this declaration against the caller's already decoded palette."""
|
|
59
|
+
return read(cls)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class CoreColour(ThemeColour):
|
|
63
|
+
"""A colour every scheme states."""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class LayerColour(ThemeColour):
|
|
67
|
+
"""A surface colour a scheme may state; otherwise the backend lays out its own."""
|
|
68
|
+
|
|
69
|
+
background = True
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class ForegroundColour(CoreColour):
|
|
73
|
+
"""Ordinary text."""
|
|
74
|
+
|
|
75
|
+
name = "foreground"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class BackgroundColour(CoreColour):
|
|
79
|
+
name = "background"
|
|
80
|
+
background = True
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class PrimaryColour(CoreColour):
|
|
84
|
+
name = "primary"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class SecondaryColour(CoreColour):
|
|
88
|
+
name = "secondary"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class AccentColour(CoreColour):
|
|
92
|
+
name = "accent"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class SuccessColour(CoreColour):
|
|
96
|
+
name = "success"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class WarningColour(CoreColour):
|
|
100
|
+
name = "warning"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class ElementColour(ThemeColour):
|
|
104
|
+
"""A declared interface part; an unstated ordinary element has no value."""
|
|
105
|
+
|
|
106
|
+
@classmethod
|
|
107
|
+
def value(cls, scheme: ColourScheme) -> Colour:
|
|
108
|
+
return cast(Colour, scheme.elements[cls])
|
|
109
|
+
|
|
110
|
+
@classmethod
|
|
111
|
+
def rgb(cls, scheme: ColourScheme) -> Rgb:
|
|
112
|
+
return cls.value(scheme).rgb(scheme.terminal.resolve(require_terminal_palette),
|
|
113
|
+
background=cls.background)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class DerivedElementColour(ElementColour):
|
|
117
|
+
"""A part whose declaration supplies its value when a scheme leaves it unstated."""
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
def value(cls, scheme: ColourScheme) -> Colour:
|
|
121
|
+
return super().value(scheme) if cls in scheme.elements else cls.derive(scheme)
|
|
122
|
+
|
|
123
|
+
@classmethod
|
|
124
|
+
def derive(cls, scheme: ColourScheme) -> Colour:
|
|
125
|
+
raise NotImplementedError
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class BlockCursorBackgroundColour(DerivedElementColour):
|
|
129
|
+
name = "block-cursor-background"
|
|
130
|
+
background = True
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def derive(cls, scheme: ColourScheme) -> Colour:
|
|
134
|
+
return scheme.colours[PrimaryColour]
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class BlockCursorForegroundColour(DerivedElementColour):
|
|
138
|
+
name = "block-cursor-foreground"
|
|
139
|
+
|
|
140
|
+
@classmethod
|
|
141
|
+
def derive(cls, scheme: ColourScheme) -> Rgb:
|
|
142
|
+
# The cursor's existing 87% ink at eight-bit colour precision.
|
|
143
|
+
return BlockCursorBackgroundColour.rgb(scheme).contrast_text(0xDD / 255)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class FooterKeyForegroundColour(ElementColour):
|
|
147
|
+
name = "footer-key-foreground"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class InputSelectionBackgroundColour(ElementColour):
|
|
151
|
+
name = "input-selection-background"
|
|
152
|
+
background = True
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class ButtonForegroundColour(ElementColour):
|
|
156
|
+
name = "button-color-foreground"
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class InputCursorForegroundColour(ElementColour):
|
|
160
|
+
name = "input-cursor-foreground"
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class InputCursorBackgroundColour(ElementColour):
|
|
164
|
+
name = "input-cursor-background"
|
|
165
|
+
background = True
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class BorderColour(ElementColour):
|
|
169
|
+
name = "border"
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class BlurredBorderColour(ElementColour):
|
|
173
|
+
name = "border-blurred"
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class FooterBackgroundColour(ElementColour):
|
|
177
|
+
name = "footer-background"
|
|
178
|
+
background = True
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class ForegroundMutedColour(ElementColour):
|
|
182
|
+
name = "foreground-muted"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class FooterDescriptionForegroundColour(ElementColour):
|
|
186
|
+
name = "footer-description-foreground"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class AnsiBackgroundColour(ElementColour):
|
|
190
|
+
name = "ansi-background"
|
|
191
|
+
background = True
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class AnsiForegroundColour(ElementColour):
|
|
195
|
+
name = "ansi-foreground"
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class InputSelectionForegroundColour(ElementColour):
|
|
199
|
+
name = "input-selection-foreground"
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class ScreenSelectionBackgroundColour(ElementColour):
|
|
203
|
+
name = "screen-selection-background"
|
|
204
|
+
background = True
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class ScreenSelectionForegroundColour(ElementColour):
|
|
208
|
+
name = "screen-selection-foreground"
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class ScrollbarColour(ElementColour):
|
|
212
|
+
name = "scrollbar"
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class ScrollbarHoverColour(ElementColour):
|
|
216
|
+
name = "scrollbar-hover"
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
class ScrollbarActiveColour(ElementColour):
|
|
220
|
+
name = "scrollbar-active"
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class ScrollbarBackgroundColour(ElementColour):
|
|
224
|
+
name = "scrollbar-background"
|
|
225
|
+
background = True
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class ScrollbarCornerColour(ElementColour):
|
|
229
|
+
name = "scrollbar-corner-color"
|
|
230
|
+
background = True
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class ScrollbarBackgroundHoverColour(ElementColour):
|
|
234
|
+
name = "scrollbar-background-hover"
|
|
235
|
+
background = True
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class ScrollbarBackgroundActiveColour(ElementColour):
|
|
239
|
+
name = "scrollbar-background-active"
|
|
240
|
+
background = True
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class BlockHoverBackgroundColour(ElementColour):
|
|
244
|
+
name = "block-hover-background"
|
|
245
|
+
background = True
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class ThemeTextStyle(ThemePart):
|
|
249
|
+
"""A declared text-emphasis part, rather than a colour."""
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
class BlockCursorTextStyle(ThemeTextStyle):
|
|
253
|
+
name = "block-cursor-text-style"
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class InputCursorTextStyle(ThemeTextStyle):
|
|
257
|
+
name = "input-cursor-text-style"
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
class ButtonFocusTextStyle(ThemeTextStyle):
|
|
261
|
+
name = "button-focus-text-style"
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
class ErrorColour(CoreColour):
|
|
265
|
+
"""Failures stay recognisably red in monochromatic wallpaper palettes."""
|
|
266
|
+
|
|
267
|
+
name = "error"
|
|
268
|
+
palette_colour: ClassVar[Rgb] = Rgb.parse("#e06c75")
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
class SurfaceColour(LayerColour):
|
|
272
|
+
name = "surface"
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class PanelColour(LayerColour):
|
|
276
|
+
name = "panel"
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class BoostColour(LayerColour):
|
|
280
|
+
name = "boost"
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class BlendColour(ThemeColour):
|
|
284
|
+
"""A colour no scheme states: the background `amount` of the way to the foreground.
|
|
285
|
+
|
|
286
|
+
The same ratio steps lighter in a dark theme and darker in a light one.
|
|
287
|
+
"""
|
|
288
|
+
|
|
289
|
+
amount: ClassVar[float]
|
|
290
|
+
|
|
291
|
+
@classmethod
|
|
292
|
+
def resolve_rgb(cls, read: Callable[[type[ThemeColour]], Rgb]) -> Rgb:
|
|
293
|
+
return BackgroundColour.resolve_rgb(read).blend(ForegroundColour.resolve_rgb(read), cls.amount)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
class MutedColour(BlendColour):
|
|
297
|
+
"""Secondary text: the foreground part of the way over the background.
|
|
298
|
+
|
|
299
|
+
Terminal colours cannot be blended without their palette; a terminal
|
|
300
|
+
backend that emits them natively dims the foreground instead.
|
|
301
|
+
"""
|
|
302
|
+
|
|
303
|
+
name = "muted"
|
|
304
|
+
amount = 0.6
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
class SurfaceHoverColour(BlendColour):
|
|
308
|
+
"""Raised surface behind hovered or focused project-search controls."""
|
|
309
|
+
|
|
310
|
+
name = "surface-hover"
|
|
311
|
+
amount = 0.12
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
class ToneColour(BlendColour):
|
|
315
|
+
"""A surface a slight step off the background that sets one screen area apart.
|
|
316
|
+
|
|
317
|
+
The transcript stays on the background itself; every other area steps away from it.
|
|
318
|
+
"""
|
|
319
|
+
|
|
320
|
+
background = True
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
class TurnBandColour(ToneColour):
|
|
324
|
+
"""A quiet separator surface between a transcript and its prompt."""
|
|
325
|
+
|
|
326
|
+
name = "turn-band"
|
|
327
|
+
amount = 0.08
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class HeaderToneColour(ToneColour):
|
|
331
|
+
"""The tab bar along the top."""
|
|
332
|
+
|
|
333
|
+
name = "tone-header"
|
|
334
|
+
amount = 0.06
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
class SidebarToneColour(ToneColour):
|
|
338
|
+
"""The channel and thread sidebars."""
|
|
339
|
+
|
|
340
|
+
name = "tone-sidebar"
|
|
341
|
+
amount = 0.035
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
class AlternateRowToneColour(ToneColour):
|
|
345
|
+
"""Every other row of a sidebar list, one more step off the sidebar."""
|
|
346
|
+
|
|
347
|
+
name = "tone-alternate-row"
|
|
348
|
+
amount = 0.075
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
class PromptToneColour(ToneColour):
|
|
352
|
+
"""The prompt area under the transcript."""
|
|
353
|
+
|
|
354
|
+
name = "tone-prompt"
|
|
355
|
+
amount = 0.04
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class FooterToneColour(ToneColour):
|
|
359
|
+
"""The key bar along the bottom."""
|
|
360
|
+
|
|
361
|
+
name = "tone-footer"
|
|
362
|
+
amount = 0.06
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
class TextStyle(ThemeValue, Enum):
|
|
366
|
+
"""How an element's text is emphasised."""
|
|
367
|
+
|
|
368
|
+
NONE = "none"
|
|
369
|
+
REVERSE = "reverse"
|
|
370
|
+
|
|
371
|
+
def variable[Palette](self, backend: TerminalBackend[Palette]) -> str:
|
|
372
|
+
return backend.text_style(self)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
@dataclass(frozen=True)
|
|
376
|
+
class ColourScheme:
|
|
377
|
+
"""One theme: its colours, whether it is dark, and the palette terminal colours come from.
|
|
378
|
+
|
|
379
|
+
`elements` colours individual interface parts (a cursor, a selection, a
|
|
380
|
+
border) by the part's design name; a backend applies the parts it has.
|
|
381
|
+
"""
|
|
382
|
+
|
|
383
|
+
name: str
|
|
384
|
+
dark: bool
|
|
385
|
+
colours: Mapping[type[ThemeColour], Colour]
|
|
386
|
+
terminal: PaletteSource = field(default_factory=TerminalOwnedPalette)
|
|
387
|
+
elements: Mapping[type[ThemePart], ThemeValue] = field(default_factory=dict)
|
|
388
|
+
|
|
389
|
+
def __post_init__(self) -> None:
|
|
390
|
+
missing = [colour.name for colour in CoreColour.members() if colour not in self.colours]
|
|
391
|
+
if missing:
|
|
392
|
+
raise ValueError(f"Scheme {self.name!r} does not state {', '.join(missing)}")
|
|
393
|
+
derived = [colour.name for colour in self.colours
|
|
394
|
+
if not issubclass(colour, (CoreColour, LayerColour))]
|
|
395
|
+
if derived:
|
|
396
|
+
raise ValueError(f"Scheme {self.name!r} states derived colours: {', '.join(derived)}")
|
|
397
|
+
|
|
398
|
+
@property
|
|
399
|
+
def resolved_colours(self) -> Mapping[type[ThemeColour], Colour]:
|
|
400
|
+
elements = self.resolved_elements
|
|
401
|
+
return {**self.colours, **{member: cast(Colour, elements[member])
|
|
402
|
+
for member in ElementColour.members() if member in elements}}
|
|
403
|
+
|
|
404
|
+
@property
|
|
405
|
+
def resolved_elements(self) -> Mapping[type[ThemePart], ThemeValue]:
|
|
406
|
+
"""Stated parts and the cursor declarations' own derivations; no generic fallback."""
|
|
407
|
+
return {**self.elements,
|
|
408
|
+
**{member: member.value(self) for member in DerivedElementColour.members()}}
|
|
409
|
+
|
|
410
|
+
@property
|
|
411
|
+
def from_terminal(self) -> bool:
|
|
412
|
+
"""True when the scheme uses the terminal's own colours (an ANSI theme)."""
|
|
413
|
+
return self.colours[BackgroundColour].from_terminal
|
|
414
|
+
|
|
415
|
+
def rgb(self, colour: type[ThemeColour]) -> Rgb:
|
|
416
|
+
return colour.rgb(self)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def scheme_of_palette(name: str, palette: TerminalPalette) -> ColourScheme:
|
|
420
|
+
"""Wallpaper accents as true colour, with the error role's own failure red."""
|
|
421
|
+
slot = palette.ansi
|
|
422
|
+
return ColourScheme(name, palette.dark, {
|
|
423
|
+
ForegroundColour: palette.foreground, BackgroundColour: palette.background,
|
|
424
|
+
PrimaryColour: slot[4], SecondaryColour: slot[6], AccentColour: slot[5],
|
|
425
|
+
SuccessColour: slot[2], WarningColour: slot[3], ErrorColour: ErrorColour.palette_colour,
|
|
426
|
+
}, palette)
|
ui_theme/splash.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Text effects from TerminalTextEffects, built in advance into `PlayedText`.
|
|
2
|
+
|
|
3
|
+
Building an effect does its path and gradient work up front (tens to hundreds
|
|
4
|
+
of milliseconds), so `TextEffect.build` belongs off the UI thread, in a worker
|
|
5
|
+
process. It reads each character's position, symbol and colour straight from
|
|
6
|
+
the effect's state, so no terminal output is produced or parsed back.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from ui_theme.colour import Rgb
|
|
15
|
+
from ui_theme.effects import PlayedText, TextFrame
|
|
16
|
+
from ui_theme.scheme import AccentColour, ColourScheme, PrimaryColour, SecondaryColour, ThemeColour
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class TextEffect:
|
|
21
|
+
"""A TerminalTextEffects effect over `text`, finishing in the scheme's colours."""
|
|
22
|
+
|
|
23
|
+
effect: str
|
|
24
|
+
text: str
|
|
25
|
+
stops: tuple[type[ThemeColour], ...]
|
|
26
|
+
frames_per_second: float
|
|
27
|
+
# The longest it may play; longer effects show every n-th frame.
|
|
28
|
+
longest: float
|
|
29
|
+
|
|
30
|
+
def build(self, scheme: ColourScheme) -> PlayedText:
|
|
31
|
+
from importlib import import_module
|
|
32
|
+
|
|
33
|
+
from terminaltexteffects.utils.graphics import Color, Gradient
|
|
34
|
+
|
|
35
|
+
module = import_module(f"terminaltexteffects.effects.effect_{self.effect}")
|
|
36
|
+
effect = module.get_effect_resources()[1](self.text)
|
|
37
|
+
effect.terminal_config.frame_rate = 0
|
|
38
|
+
effect.effect_config.final_gradient_stops = tuple(
|
|
39
|
+
Color(scheme.rgb(stop).hex[1:]) for stop in self.stops)
|
|
40
|
+
effect.effect_config.final_gradient_direction = Gradient.Direction.HORIZONTAL
|
|
41
|
+
iterator = iter(effect)
|
|
42
|
+
frames = [_text_frame(iterator.terminal) for _ in _advance(iterator)]
|
|
43
|
+
step = max(1, -(-len(frames) // int(self.longest * self.frames_per_second)))
|
|
44
|
+
kept = frames[step - 1::step]
|
|
45
|
+
if kept[-1] is not frames[-1]:
|
|
46
|
+
kept.append(frames[-1])
|
|
47
|
+
return PlayedText(tuple(kept), self.frames_per_second)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _advance(iterator: Any) -> Any:
|
|
51
|
+
for _ in iterator:
|
|
52
|
+
yield
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _text_frame(terminal: Any) -> TextFrame:
|
|
56
|
+
canvas = terminal.canvas
|
|
57
|
+
rows: list[list[tuple[str, Rgb | None]]] = [
|
|
58
|
+
[(" ", None)] * canvas.right for _ in range(canvas.top)]
|
|
59
|
+
for character in sorted(terminal.get_characters(), key=lambda c: c.layer):
|
|
60
|
+
if not character.is_visible:
|
|
61
|
+
continue
|
|
62
|
+
coord = character.motion.current_coord
|
|
63
|
+
if not (1 <= coord.row <= canvas.top and 1 <= coord.column <= canvas.right):
|
|
64
|
+
continue
|
|
65
|
+
visual = character.animation.current_character_visual
|
|
66
|
+
colours = visual.colors
|
|
67
|
+
colour = (Rgb.parse("#" + colours.fg_color.rgb_color)
|
|
68
|
+
if colours is not None and colours.fg_color is not None else None)
|
|
69
|
+
rows[canvas.top - coord.row][coord.column - 1] = (visual.symbol, colour)
|
|
70
|
+
return TextFrame(tuple(tuple(row) for row in rows))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def loading_splash(text: str) -> TextEffect:
|
|
74
|
+
"""The splash shown while history loads: the text swept into the theme's colours."""
|
|
75
|
+
return TextEffect("sweep", text, (PrimaryColour, AccentColour, SecondaryColour),
|
|
76
|
+
frames_per_second=30, longest=2.0)
|
ui_theme/wal.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""pywal's colour file, decoded once into a terminal palette and a scheme.
|
|
2
|
+
|
|
3
|
+
pywal (`wal -i`, `wal -R`) writes `colors.json` in its cache directory, in
|
|
4
|
+
place, and sends the same colours to every open terminal as OSC 4/10/11
|
|
5
|
+
sequences, so a scheme of terminal colours follows it without reading the
|
|
6
|
+
file. A true-colour scheme reads the file. The format is pywal's and is decoded
|
|
7
|
+
with optional checksum metadata written by pywal16. Colours still require
|
|
8
|
+
`#rrggbb` form; checksum metadata does not participate in the palette.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
from collections.abc import Mapping
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from ui_theme.colour import Rgb, TerminalPalette
|
|
20
|
+
from ui_theme.scheme import ColourScheme, scheme_of_palette
|
|
21
|
+
|
|
22
|
+
COLOURS = tuple(f"color{index}" for index in range(16))
|
|
23
|
+
SPECIAL = ("background", "foreground", "cursor")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _exact(value: Any, keys: tuple[str, ...], where: str,
|
|
27
|
+
*, optional: tuple[str, ...] = ()) -> Mapping[str, Any]:
|
|
28
|
+
if not isinstance(value, dict) or not set(keys) <= set(value) <= set(keys + optional):
|
|
29
|
+
found = sorted(value) if isinstance(value, dict) else type(value).__name__
|
|
30
|
+
raise ValueError(f"pywal's {where} requires keys {list(keys)}"
|
|
31
|
+
f" with optional {list(optional)}, not {found}")
|
|
32
|
+
return value
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class WalFile:
|
|
37
|
+
"""`colors.json` as pywal writes it."""
|
|
38
|
+
|
|
39
|
+
wallpaper: str
|
|
40
|
+
alpha: str
|
|
41
|
+
palette: TerminalPalette
|
|
42
|
+
|
|
43
|
+
NAME = "colors.json"
|
|
44
|
+
SCHEME = "wal"
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def directory(environment: Mapping[str, str]) -> Path:
|
|
48
|
+
"""pywal's cache directory: `PYWAL_CACHE_DIR`, else `~/.cache/wal`."""
|
|
49
|
+
configured = environment.get("PYWAL_CACHE_DIR")
|
|
50
|
+
return Path(configured) if configured else Path(environment["HOME"]) / ".cache" / "wal"
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def decode(cls, data: Any) -> WalFile:
|
|
54
|
+
top = _exact(data, ("wallpaper", "alpha", "special", "colors"), "file",
|
|
55
|
+
optional=("checksum",))
|
|
56
|
+
special = _exact(top["special"], SPECIAL, "special")
|
|
57
|
+
colours = _exact(top["colors"], COLOURS, "colors")
|
|
58
|
+
for key in ("wallpaper", "alpha"):
|
|
59
|
+
if not isinstance(top[key], str):
|
|
60
|
+
raise ValueError(f"pywal's {key} is a string, not {top[key]!r}")
|
|
61
|
+
background, foreground, cursor = (Rgb.parse(special[key]) for key in SPECIAL)
|
|
62
|
+
return cls(top["wallpaper"], top["alpha"], TerminalPalette(
|
|
63
|
+
background, foreground, cursor, tuple(Rgb.parse(colours[key]) for key in COLOURS)))
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def read(cls, path: Path) -> WalFile:
|
|
67
|
+
return cls.decode(json.loads(path.read_text(encoding="utf-8")))
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def scheme(self) -> ColourScheme:
|
|
71
|
+
return scheme_of_palette(self.SCHEME, self.palette)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ui-theme
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Colour schemes, pywal, colour depth and animated effects for any UI backend
|
|
5
|
+
Author-email: Tristan Simas <tristan.simas@mail.mcgill.ca>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Requires-Dist: metaclass-registry>=0.2.1
|
|
9
|
+
Requires-Dist: terminaltexteffects==0.15.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
ui_theme/__init__.py,sha256=hUktJgDlng2vALUTQ3kepERIbo3eSNvgYnBUzG2C5ls,163
|
|
2
|
+
ui_theme/backend.py,sha256=j5S0b3pyR65YB9HM3xlmkNtL3UC-KkdL6UlGvgplJyQ,2657
|
|
3
|
+
ui_theme/catalog.py,sha256=QlkVkURmzU0qoe0Ie-JmBGaQD3BJ3Qk0mLmh6nXEquM,20265
|
|
4
|
+
ui_theme/clock.py,sha256=wLvMQsfyMXBOgW9YdE6I6hnhrA6MLIhHe3MFuy5UZz0,5626
|
|
5
|
+
ui_theme/colour.py,sha256=dlqbZShhl3U3mahqCKGxaAUSDTxLWR4J2g-vz6wovc4,7496
|
|
6
|
+
ui_theme/depth.py,sha256=PEXLp42KjH3QvvCaLUYI3VWA7gSJWGPH5OBRd9dHaPQ,1497
|
|
7
|
+
ui_theme/effects.py,sha256=_tVPFkitiDDEVKn3J5BohsQQhD8itFrHGIu9Yh5hFHM,15743
|
|
8
|
+
ui_theme/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
ui_theme/scheme.py,sha256=R8GHYji6d7sUdEa3D5fuYLPA1Xl2vB8PSV686mKhpI4,11549
|
|
10
|
+
ui_theme/splash.py,sha256=HJgQWRqTsVLAmUwjEBqQnY3JHm7OMUWZIPMqwVaUw3I,3146
|
|
11
|
+
ui_theme/wal.py,sha256=kIugatdIZHnn2HfZnwtfHO6KvV6RRg3joWE9xEbbYik,2847
|
|
12
|
+
ui_theme-0.1.0.dist-info/METADATA,sha256=Dx3H2u3bN_4kyfafhYlA_OWjZxXsGDkGGnJzzxxm9hg,378
|
|
13
|
+
ui_theme-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
14
|
+
ui_theme-0.1.0.dist-info/RECORD,,
|