mmit-clitheme 0.15.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.
- cli_theme/__init__.py +47 -0
- cli_theme/arguments.py +265 -0
- cli_theme/bash/cli.lib.sh +475 -0
- cli_theme/bash/make.lib.sh +138 -0
- cli_theme/cli.py +276 -0
- cli_theme/deno/deno.json +10 -0
- cli_theme/deno/help.ts +150 -0
- cli_theme/deno/mod.ts +413 -0
- cli_theme/export.py +221 -0
- cli_theme/i18n.py +18 -0
- cli_theme/locales/de/LC_MESSAGES/cli_theme.mo +0 -0
- cli_theme/locales/de/LC_MESSAGES/cli_theme.po +328 -0
- cli_theme/output.py +261 -0
- cli_theme/skill.py +107 -0
- cli_theme/templates/classic.theme +46 -0
- cli_theme/templates/earth.theme +46 -0
- cli_theme/templates/forest.theme +46 -0
- cli_theme/templates/mono.theme +46 -0
- cli_theme/templates/neon.theme +46 -0
- cli_theme/templates/night.theme +46 -0
- cli_theme/templates/ocean.theme +46 -0
- cli_theme/templates/shell.theme +46 -0
- cli_theme/templates/sunset.theme +46 -0
- cli_theme/theme.py +422 -0
- mmit_clitheme-0.15.0.data/scripts/clilib-path +74 -0
- mmit_clitheme-0.15.0.dist-info/METADATA +482 -0
- mmit_clitheme-0.15.0.dist-info/RECORD +33 -0
- mmit_clitheme-0.15.0.dist-info/WHEEL +5 -0
- mmit_clitheme-0.15.0.dist-info/entry_points.txt +3 -0
- mmit_clitheme-0.15.0.dist-info/licenses/LICENSE +287 -0
- mmit_clitheme-0.15.0.dist-info/licenses/LICENSE.de.txt +101 -0
- mmit_clitheme-0.15.0.dist-info/licenses/LICENSING.md +97 -0
- mmit_clitheme-0.15.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
# Deutsche Übersetzung von clitheme; Basissprache ist Englisch.
|
|
2
|
+
msgid ""
|
|
3
|
+
msgstr ""
|
|
4
|
+
"Project-Id-Version: mmit-clitheme\n"
|
|
5
|
+
"POT-Creation-Date: 2026-10-31 13:47+0100\n"
|
|
6
|
+
"Language: de\n"
|
|
7
|
+
"MIME-Version: 1.0\n"
|
|
8
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
|
9
|
+
"Content-Transfer-Encoding: 8bit\n"
|
|
10
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
|
11
|
+
|
|
12
|
+
msgid "Sample"
|
|
13
|
+
msgstr "Muster"
|
|
14
|
+
|
|
15
|
+
msgid "Theme files"
|
|
16
|
+
msgstr "Theme-Dateien"
|
|
17
|
+
|
|
18
|
+
msgid "created"
|
|
19
|
+
msgstr "angelegt"
|
|
20
|
+
|
|
21
|
+
msgid "unchanged"
|
|
22
|
+
msgstr "unverändert"
|
|
23
|
+
|
|
24
|
+
msgid "Theme"
|
|
25
|
+
msgstr "Theme"
|
|
26
|
+
|
|
27
|
+
msgid "File"
|
|
28
|
+
msgstr "Datei"
|
|
29
|
+
|
|
30
|
+
msgid "File missing: no colors, spacing from the classic template."
|
|
31
|
+
msgstr "Datei fehlt: keine Farben, Abstände aus der classic-Vorlage."
|
|
32
|
+
|
|
33
|
+
msgid "Create it with: clitheme install"
|
|
34
|
+
msgstr "Anlegen mit: clitheme install"
|
|
35
|
+
|
|
36
|
+
msgid "Colors"
|
|
37
|
+
msgstr "Farben"
|
|
38
|
+
|
|
39
|
+
msgid "Spacing"
|
|
40
|
+
msgstr "Abstände"
|
|
41
|
+
|
|
42
|
+
msgid "Shared CLI theme for Python, Bash and Make: colors and spacing."
|
|
43
|
+
msgstr "Gemeinsames CLI-Theme für Python, Bash und Make: Farben und Abstände."
|
|
44
|
+
|
|
45
|
+
msgid "create missing theme files, keep existing ones"
|
|
46
|
+
msgstr "fehlende Theme-Dateien anlegen, vorhandene behalten"
|
|
47
|
+
|
|
48
|
+
msgid "print the path of the chosen theme file"
|
|
49
|
+
msgstr "Ort der gewählten Theme-Datei ausgeben"
|
|
50
|
+
|
|
51
|
+
msgid "show roles and spacing of the chosen theme"
|
|
52
|
+
msgstr "Rollen und Abstände des gewählten Themes zeigen"
|
|
53
|
+
|
|
54
|
+
#, python-brace-format
|
|
55
|
+
msgid "Invalid CLI_THEME {name}"
|
|
56
|
+
msgstr "Ungültiges CLI_THEME {name}"
|
|
57
|
+
|
|
58
|
+
#, python-brace-format
|
|
59
|
+
msgid "{source}:{line}: invalid theme entry {entry}"
|
|
60
|
+
msgstr "{source}:{line}: ungültiger Eintrag {entry}"
|
|
61
|
+
|
|
62
|
+
#, python-brace-format
|
|
63
|
+
msgid "{source}: missing theme entries {names}"
|
|
64
|
+
msgstr "{source}: fehlende Einträge {names}"
|
|
65
|
+
|
|
66
|
+
#, python-brace-format
|
|
67
|
+
msgid "{path} is a link; refused for safety"
|
|
68
|
+
msgstr "{path} ist ein Link; aus Sicherheitsgründen abgelehnt"
|
|
69
|
+
|
|
70
|
+
#, python-brace-format
|
|
71
|
+
msgid "{path}: cannot read ({reason})"
|
|
72
|
+
msgstr "{path}: nicht lesbar ({reason})"
|
|
73
|
+
|
|
74
|
+
#, python-brace-format
|
|
75
|
+
msgid "{path} is not a regular file"
|
|
76
|
+
msgstr "{path} ist keine reguläre Datei"
|
|
77
|
+
|
|
78
|
+
#, python-brace-format
|
|
79
|
+
msgid "{source}:{line}: not valid UTF-8"
|
|
80
|
+
msgstr "{source}:{line}: kein gültiges UTF-8"
|
|
81
|
+
|
|
82
|
+
msgid "default"
|
|
83
|
+
msgstr "Standard"
|
|
84
|
+
|
|
85
|
+
#, python-brace-format
|
|
86
|
+
msgid "Theme file missing: {path}"
|
|
87
|
+
msgstr "Theme-Datei fehlt: {path}"
|
|
88
|
+
|
|
89
|
+
msgid ""
|
|
90
|
+
"Resolved THEME_* values of the chosen theme (CLI_THEME or clitheme use, "
|
|
91
|
+
"file under XDG_CONFIG_HOME). Without a valid file: no colors, classic spacing and "
|
|
92
|
+
"THEME_NOTICE with the finding; exit 0. The result is cached under "
|
|
93
|
+
"${XDG_CACHE_HOME:-~/.cache}/clitheme/. Bash: eval \"$(clitheme export "
|
|
94
|
+
"--bash)\". Make: -include $(shell clitheme export --make 2>/dev/null). "
|
|
95
|
+
"Other languages: --json, one JSON object with the same names. Deno: --deno, "
|
|
96
|
+
"path of mod.ts of the package @mmit/clitheme in this installation."
|
|
97
|
+
msgstr ""
|
|
98
|
+
"Aufgelöste THEME_*-Werte des gewählten Themes (CLI_THEME oder clitheme "
|
|
99
|
+
"use, Datei unter XDG_CONFIG_HOME). Ohne gültige Datei: keine Farben, Abstände von classic "
|
|
100
|
+
"und THEME_NOTICE mit dem Befund; Exit 0. Das Ergebnis liegt im Cache unter "
|
|
101
|
+
"${XDG_CACHE_HOME:-~/.cache}/clitheme/. Bash: eval \"$(clitheme export "
|
|
102
|
+
"--bash)\". Make: -include $(shell clitheme export --make 2>/dev/null). "
|
|
103
|
+
"Andere Sprachen: --json, ein JSON-Objekt mit denselben Namen. Deno: --deno, "
|
|
104
|
+
"Pfad von mod.ts des Pakets @mmit/clitheme in dieser Installation."
|
|
105
|
+
|
|
106
|
+
msgid "print THEME_* values for Bash, a .mk file for Make, JSON, or the Deno package"
|
|
107
|
+
msgstr "THEME_*-Werte für Bash, eine .mk-Datei für Make, JSON oder das Deno-Paket ausgeben"
|
|
108
|
+
|
|
109
|
+
msgid "print assignments for eval, each value quoted"
|
|
110
|
+
msgstr "Zuweisungen für eval ausgeben, jeder Wert gequotet"
|
|
111
|
+
|
|
112
|
+
msgid "print the path of a .mk file in the cache, for -include"
|
|
113
|
+
msgstr "Pfad einer .mk-Datei im Cache ausgeben, für -include"
|
|
114
|
+
|
|
115
|
+
msgid "print one JSON object, numbers for widths and spacing, else strings"
|
|
116
|
+
msgstr "ein JSON-Objekt ausgeben, Breiten und Abstände als Zahl, sonst Strings"
|
|
117
|
+
|
|
118
|
+
msgid "print the path of mod.ts of the Deno package @mmit/clitheme"
|
|
119
|
+
msgstr "Pfad von mod.ts des Deno-Pakets @mmit/clitheme ausgeben"
|
|
120
|
+
|
|
121
|
+
msgid "Deno package missing: {path}"
|
|
122
|
+
msgstr "Deno-Paket fehlt: {path}"
|
|
123
|
+
|
|
124
|
+
msgid "adopted"
|
|
125
|
+
msgstr "übernommen"
|
|
126
|
+
|
|
127
|
+
msgid "File in the old folder cli-theme; move it with: clitheme install"
|
|
128
|
+
msgstr "Datei im alten Ordner cli-theme; umziehen mit: clitheme install"
|
|
129
|
+
|
|
130
|
+
#, python-brace-format
|
|
131
|
+
msgid "Theme file still in the old folder {folder}"
|
|
132
|
+
msgstr "Theme-Datei noch im alten Ordner {folder}"
|
|
133
|
+
|
|
134
|
+
msgid "skipped"
|
|
135
|
+
msgstr "übersprungen"
|
|
136
|
+
|
|
137
|
+
msgid "Name"
|
|
138
|
+
msgstr "Name"
|
|
139
|
+
|
|
140
|
+
msgid "Chosen by"
|
|
141
|
+
msgstr "Gewählt über"
|
|
142
|
+
|
|
143
|
+
msgid "Themes"
|
|
144
|
+
msgstr "Themes"
|
|
145
|
+
|
|
146
|
+
msgid "not installed"
|
|
147
|
+
msgstr "nicht angelegt"
|
|
148
|
+
|
|
149
|
+
#, python-brace-format
|
|
150
|
+
msgid "active, {origin}"
|
|
151
|
+
msgstr "wirksam, {origin}"
|
|
152
|
+
|
|
153
|
+
msgid "Switch with: clitheme use NAME"
|
|
154
|
+
msgstr "Umschalten mit: clitheme use NAME"
|
|
155
|
+
|
|
156
|
+
#, python-brace-format
|
|
157
|
+
msgid "Using {name}; choose again with: clitheme use NAME"
|
|
158
|
+
msgstr "Es gilt {name}; neu wählen mit: clitheme use NAME"
|
|
159
|
+
|
|
160
|
+
msgid "Chosen"
|
|
161
|
+
msgstr "Gewählt"
|
|
162
|
+
|
|
163
|
+
#, python-brace-format
|
|
164
|
+
msgid "CLI_THEME={name} is set and wins over this choice; it takes effect after:"
|
|
165
|
+
msgstr "CLI_THEME={name} ist gesetzt und geht dieser Wahl vor; sie wirkt erst nach:"
|
|
166
|
+
|
|
167
|
+
msgid "list the available themes and mark the active one"
|
|
168
|
+
msgstr "verfügbare Themes auflisten und das wirksame markieren"
|
|
169
|
+
|
|
170
|
+
msgid ""
|
|
171
|
+
"Lists the templates and own theme files with their location. The active "
|
|
172
|
+
"theme comes from CLI_THEME, else from clitheme use, else classic."
|
|
173
|
+
msgstr ""
|
|
174
|
+
"Listet die Vorlagen und eigenen Theme-Dateien mit ihrem Ort. Das wirksame "
|
|
175
|
+
"Theme kommt aus CLI_THEME, sonst aus clitheme use, sonst gilt classic."
|
|
176
|
+
|
|
177
|
+
msgid "choose the theme for new processes"
|
|
178
|
+
msgstr "Theme für neue Prozesse wählen"
|
|
179
|
+
|
|
180
|
+
msgid ""
|
|
181
|
+
"Saves NAME as the theme for new processes in ${XDG_CONFIG_HOME:-~/.config}/"
|
|
182
|
+
"clitheme/selected; a missing template file is created. CLI_THEME wins over "
|
|
183
|
+
"this choice."
|
|
184
|
+
msgstr ""
|
|
185
|
+
"Speichert NAME als Theme für neue Prozesse in ${XDG_CONFIG_HOME:-~/.config}/"
|
|
186
|
+
"clitheme/selected; eine fehlende Vorlagendatei wird angelegt. CLI_THEME geht "
|
|
187
|
+
"dieser Wahl vor."
|
|
188
|
+
|
|
189
|
+
msgid "name from clitheme list"
|
|
190
|
+
msgstr "Name aus clitheme list"
|
|
191
|
+
|
|
192
|
+
#, python-brace-format
|
|
193
|
+
msgid "{path}: invalid theme name {name}"
|
|
194
|
+
msgstr "{path}: ungültiger Theme-Name {name}"
|
|
195
|
+
|
|
196
|
+
#, python-brace-format
|
|
197
|
+
msgid "Invalid theme name {name}"
|
|
198
|
+
msgstr "Ungültiger Theme-Name {name}"
|
|
199
|
+
|
|
200
|
+
#, python-brace-format
|
|
201
|
+
msgid "Theme files still in the old folder {folder}; move them first: clitheme install"
|
|
202
|
+
msgstr "Theme-Dateien noch im alten Ordner {folder}; zuerst umziehen: clitheme install"
|
|
203
|
+
|
|
204
|
+
#, python-brace-format
|
|
205
|
+
msgid "Unknown theme {name}; available: {names}"
|
|
206
|
+
msgstr "Unbekanntes Theme {name}; verfügbar: {names}"
|
|
207
|
+
|
|
208
|
+
msgid "options"
|
|
209
|
+
msgstr "Optionen"
|
|
210
|
+
|
|
211
|
+
msgid "show this help"
|
|
212
|
+
msgstr "diese Hilfe zeigen"
|
|
213
|
+
|
|
214
|
+
msgid "show the installed version"
|
|
215
|
+
msgstr "installierte Version zeigen"
|
|
216
|
+
|
|
217
|
+
msgid "describe the commands for AI agents (Markdown)"
|
|
218
|
+
msgstr "die Befehle für KI-Agenten beschreiben (Markdown)"
|
|
219
|
+
|
|
220
|
+
msgid "commands"
|
|
221
|
+
msgstr "Befehle"
|
|
222
|
+
|
|
223
|
+
msgid "arguments"
|
|
224
|
+
msgstr "Argumente"
|
|
225
|
+
|
|
226
|
+
msgid "reads"
|
|
227
|
+
msgstr "liest"
|
|
228
|
+
|
|
229
|
+
msgid "writes"
|
|
230
|
+
msgstr "schreibt"
|
|
231
|
+
|
|
232
|
+
msgid "set up clitheme after installing it or restore a deleted template"
|
|
233
|
+
msgstr "clitheme nach der Installation einrichten oder eine gelöschte Vorlage wiederherstellen"
|
|
234
|
+
|
|
235
|
+
msgid "find out which themes exist and which one is active"
|
|
236
|
+
msgstr "herausfinden, welche Themes es gibt und welches wirkt"
|
|
237
|
+
|
|
238
|
+
msgid "switch the theme of all tools that use clitheme"
|
|
239
|
+
msgstr "das Theme aller Werkzeuge wechseln, die clitheme nutzen"
|
|
240
|
+
|
|
241
|
+
msgid "open or edit the theme file"
|
|
242
|
+
msgstr "die Theme-Datei öffnen oder bearbeiten"
|
|
243
|
+
|
|
244
|
+
msgid "check the colors and spacing of the active theme"
|
|
245
|
+
msgstr "Farben und Abstände des wirksamen Themes prüfen"
|
|
246
|
+
|
|
247
|
+
msgid "use the theme colors and spacing in a Bash script, a Makefile or another language"
|
|
248
|
+
msgstr "Farben und Abstände des Themes in einem Bash-Skript, einem Makefile oder einer anderen Sprache nutzen"
|
|
249
|
+
|
|
250
|
+
msgid ""
|
|
251
|
+
"Shared CLI theme for Python, Bash and Make: colors and spacing. Installed "
|
|
252
|
+
"version {version}. The commands run in any folder; the theme files live in "
|
|
253
|
+
"`{folder}`. All options of a command: `clitheme <command> --help`."
|
|
254
|
+
msgstr ""
|
|
255
|
+
"Gemeinsames CLI-Theme für Python, Bash und Make: Farben und Abstände. "
|
|
256
|
+
"Installierte Version {version}. Die Befehle laufen in jedem Ordner; die "
|
|
257
|
+
"Theme-Dateien liegen in `{folder}`. Alle Optionen eines Befehls: `clitheme "
|
|
258
|
+
"<befehl> --help`."
|
|
259
|
+
|
|
260
|
+
msgid "When"
|
|
261
|
+
msgstr "Wann"
|
|
262
|
+
|
|
263
|
+
msgid "Commands"
|
|
264
|
+
msgstr "Befehle"
|
|
265
|
+
|
|
266
|
+
msgid "Examples"
|
|
267
|
+
msgstr "Beispiele"
|
|
268
|
+
|
|
269
|
+
msgid "Libraries"
|
|
270
|
+
msgstr "Bibliotheken"
|
|
271
|
+
|
|
272
|
+
msgid "Requirements"
|
|
273
|
+
msgstr "Voraussetzungen"
|
|
274
|
+
|
|
275
|
+
msgid "available themes, the active one marked"
|
|
276
|
+
msgstr "verfügbare Themes, das wirksame markiert"
|
|
277
|
+
|
|
278
|
+
msgid "choose ocean for new processes"
|
|
279
|
+
msgstr "ocean für neue Prozesse wählen"
|
|
280
|
+
|
|
281
|
+
msgid "colors and spacing of the active theme"
|
|
282
|
+
msgstr "Farben und Abstände des wirksamen Themes"
|
|
283
|
+
|
|
284
|
+
msgid "THEME_* values in a Bash script"
|
|
285
|
+
msgstr "THEME_*-Werte in einem Bash-Skript"
|
|
286
|
+
|
|
287
|
+
msgid "path of the .mk file for -include in a Makefile"
|
|
288
|
+
msgstr "Pfad der .mk-Datei für -include in einem Makefile"
|
|
289
|
+
|
|
290
|
+
msgid "the same values for other languages"
|
|
291
|
+
msgstr "dieselben Werte für andere Sprachen"
|
|
292
|
+
|
|
293
|
+
msgid "path of mod.ts of the Deno package @mmit/clitheme"
|
|
294
|
+
msgstr "Pfad von mod.ts des Deno-Pakets @mmit/clitheme"
|
|
295
|
+
|
|
296
|
+
msgid ""
|
|
297
|
+
"`cli_theme` (Python): output and argparse help in the colors and columns of "
|
|
298
|
+
"the theme. When: a Python CLI prints headings, rows, hints or its help without"
|
|
299
|
+
" own colors. Important: `Output`, `ArgumentParser`, `HelpFormatter`, "
|
|
300
|
+
"`load_theme`"
|
|
301
|
+
msgstr ""
|
|
302
|
+
"`cli_theme` (Python): Ausgabe und argparse-Hilfe in den Farben und Spalten "
|
|
303
|
+
"des Themes. Wann: eine Python-CLI gibt Überschriften, Zeilen, Hinweise oder "
|
|
304
|
+
"ihre Hilfe ohne eigene Farben aus. Wichtig: `Output`, `ArgumentParser`, "
|
|
305
|
+
"`HelpFormatter`, `load_theme`"
|
|
306
|
+
|
|
307
|
+
msgid ""
|
|
308
|
+
"`@mmit/clitheme` (Deno): the same output and a --help like changelog for "
|
|
309
|
+
"TypeScript tools, shipped with clitheme; import the path from `clitheme export "
|
|
310
|
+
"--deno`, run with `--allow-run=clitheme`. When: a Deno CLI prints headings, "
|
|
311
|
+
"rows, status lines or its help in the theme. Important: `Theme.load`, "
|
|
312
|
+
"`Theme.help`, `plain`"
|
|
313
|
+
msgstr ""
|
|
314
|
+
"`@mmit/clitheme` (Deno): dieselbe Ausgabe und eine --help wie bei changelog "
|
|
315
|
+
"für TypeScript-Werkzeuge, kommt mit clitheme; den Pfad zum Import nennt "
|
|
316
|
+
"`clitheme export --deno`, Aufruf mit `--allow-run=clitheme`. Wann: eine "
|
|
317
|
+
"Deno-CLI gibt Überschriften, Zeilen, Statuszeilen oder ihre Hilfe im Theme "
|
|
318
|
+
"aus. Wichtig: `Theme.load`, `Theme.help`, `plain`"
|
|
319
|
+
|
|
320
|
+
msgid ""
|
|
321
|
+
"Without a theme file there are no colors and the classic spacing applies; "
|
|
322
|
+
"create the files with `clitheme install`."
|
|
323
|
+
msgstr ""
|
|
324
|
+
"Ohne Theme-Datei gibt es keine Farben, es gelten die Abstände von classic; "
|
|
325
|
+
"die Dateien legt `clitheme install` an."
|
|
326
|
+
|
|
327
|
+
msgid "`CLI_THEME=NAME` wins over `clitheme use`; `NO_COLOR` switches colors off."
|
|
328
|
+
msgstr "`CLI_THEME=NAME` geht vor `clitheme use`; `NO_COLOR` schaltet die Farben ab."
|
cli_theme/output.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""Ausgabe mit rich: Stile je Rolle, Abstände und Helfer für Überschrift, Zeile und Hinweis."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import shutil
|
|
6
|
+
import sys
|
|
7
|
+
from collections.abc import Iterable
|
|
8
|
+
from types import TracebackType
|
|
9
|
+
from typing import Self, TextIO
|
|
10
|
+
|
|
11
|
+
from rich.console import Console
|
|
12
|
+
from rich.text import Text
|
|
13
|
+
|
|
14
|
+
from cli_theme.theme import Theme, ThemeError, fallback_theme, load_theme, theme_path
|
|
15
|
+
|
|
16
|
+
# Steuerzeichen außer Zeilenumbruch und Tabulator: C0, DEL und C1 (U+0080 bis U+009F).
|
|
17
|
+
CONTROL = re.compile(r"[\x00-\x08\x0b-\x1f\x7f-\x9f]")
|
|
18
|
+
# Annahme, wenn das Terminal seine Breite nicht nennt.
|
|
19
|
+
FALLBACK_COLUMNS = 100
|
|
20
|
+
# Schmaler darf die Wertspalte nicht werden; sonst steht der Wert unter seiner Bezeichnung.
|
|
21
|
+
MIN_VALUE_WIDTH = 20
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def current_theme() -> Theme:
|
|
25
|
+
"""Gewähltes Theme für die Ausgabe; scheitert nie an der Konfiguration.
|
|
26
|
+
|
|
27
|
+
Ist die Datei ungültig, ein Link oder CLI_THEME ungültig, gibt es keine Farben und die
|
|
28
|
+
Abstände der classic-Vorlage. Den Grund nennt load_theme bzw. clitheme show.
|
|
29
|
+
"""
|
|
30
|
+
try:
|
|
31
|
+
return load_theme()
|
|
32
|
+
except (ThemeError, OSError):
|
|
33
|
+
try:
|
|
34
|
+
path = theme_path()
|
|
35
|
+
except ThemeError:
|
|
36
|
+
path = None
|
|
37
|
+
return fallback_theme(path)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def rich_style(value: str) -> str:
|
|
41
|
+
"""Farbangabe des Themes als rich-Stil: bold+11 → bold color(11), 33 → color(33)."""
|
|
42
|
+
effect, _, number = value.rpartition("+") if "+" in value else ("", "", value)
|
|
43
|
+
if not number.isdigit():
|
|
44
|
+
return value
|
|
45
|
+
return f"{effect} color({number})".strip()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def styles(theme: Theme | None = None) -> dict[str, str]:
|
|
49
|
+
"""rich-Stil je Rolle; leer heißt Terminalfarbe."""
|
|
50
|
+
theme = theme or current_theme()
|
|
51
|
+
return {role: rich_style(value) for role, value in theme.colors.items()}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def guard(text: str) -> str:
|
|
55
|
+
"""Entschärft Steuerzeichen in einem Text: Es bleiben Zeilenumbruch und Tabulator; jedes
|
|
56
|
+
andere Steuerzeichen (übrige C0-Zeichen samt ESC, DEL, die C1-Zeichen U+0080 bis U+009F)
|
|
57
|
+
wird zu „�“. So bringt ein Wert von außen keine Steuerfolge ans Terminal, etwa Fenstertitel
|
|
58
|
+
setzen oder Bildschirm löschen, und keine eigene Farbe: Farben kommen hier nur aus den
|
|
59
|
+
Stilen von rich. Bash-Lib (themeGuard) und Deno-Paket (guard) lassen zusätzlich Farbfolgen
|
|
60
|
+
durch, weil ihre Bausteine sie in Texte einbauen."""
|
|
61
|
+
return CONTROL.sub("\ufffd", text)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def guarded(text: Text) -> Text:
|
|
65
|
+
"""text mit entschärften Steuerzeichen (guard); gleich viele Zeichen, die Stile bleiben."""
|
|
66
|
+
if (clean := guard(text.plain)) == text.plain:
|
|
67
|
+
return text
|
|
68
|
+
text = text.copy()
|
|
69
|
+
text.plain = clean
|
|
70
|
+
return text
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def plain_requested() -> bool:
|
|
74
|
+
"""NO_COLOR (auch leer) oder TERM=dumb verlangen Ausgabe ganz ohne Escape-Codes."""
|
|
75
|
+
return "NO_COLOR" in os.environ or os.environ.get("TERM") == "dumb"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def is_terminal(stream: TextIO) -> bool:
|
|
79
|
+
"""Geht stream an ein Terminal?"""
|
|
80
|
+
return bool(getattr(stream, "isatty", lambda: False)())
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def output_width(stream: TextIO, theme: Theme) -> int | None:
|
|
84
|
+
"""Zeilenbreite im Terminal: dessen Breite, höchstens WIDTH (0 = ganze Breite);
|
|
85
|
+
in Pipes und Dateien None, dort bleibt jede Zeile ungebrochen."""
|
|
86
|
+
if not is_terminal(stream):
|
|
87
|
+
return None
|
|
88
|
+
limit = theme.spacing["width"]
|
|
89
|
+
columns = shutil.get_terminal_size((limit or FALLBACK_COLUMNS, 24)).columns
|
|
90
|
+
return min(columns, limit) if limit else columns
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def console_for(stream: TextIO) -> Console:
|
|
94
|
+
"""Konsole für stream; ohne Terminal, mit NO_COLOR oder TERM=dumb ohne Farben."""
|
|
95
|
+
terminal = is_terminal(stream)
|
|
96
|
+
return Console(
|
|
97
|
+
file=stream,
|
|
98
|
+
force_terminal=terminal,
|
|
99
|
+
highlight=False,
|
|
100
|
+
soft_wrap=True,
|
|
101
|
+
emoji=False,
|
|
102
|
+
markup=False,
|
|
103
|
+
color_system=None if plain_requested() or not terminal else "auto",
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class Output:
|
|
108
|
+
"""Schreibt Überschriften, zweispaltige Zeilen und Hinweise nach dem Theme.
|
|
109
|
+
|
|
110
|
+
Vor jeder Überschrift außer der ersten stehen SPACE Leerzeilen. finish oder das Ende
|
|
111
|
+
eines with-Blocks schließt mit einer Leerzeile auf jedem Strom ab, der Ausgabe bekam;
|
|
112
|
+
was nicht über Output geht, etwa ein Befehl zum Kopieren mit print, zählt nicht.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def __init__(
|
|
116
|
+
self,
|
|
117
|
+
stream: TextIO | None = None,
|
|
118
|
+
error_stream: TextIO | None = None,
|
|
119
|
+
theme: Theme | None = None,
|
|
120
|
+
) -> None:
|
|
121
|
+
self.stream = sys.stdout if stream is None else stream
|
|
122
|
+
self.error_stream = sys.stderr if error_stream is None else error_stream
|
|
123
|
+
self.theme = theme or current_theme()
|
|
124
|
+
self.styles = styles(self.theme)
|
|
125
|
+
self.started = False
|
|
126
|
+
# Ströme mit Ausgabe seit dem letzten finish, in der Reihenfolge der ersten Ausgabe.
|
|
127
|
+
self.written: list[TextIO] = []
|
|
128
|
+
|
|
129
|
+
def __enter__(self) -> Self:
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
def __exit__(
|
|
133
|
+
self,
|
|
134
|
+
kind: type[BaseException] | None,
|
|
135
|
+
error: BaseException | None,
|
|
136
|
+
traceback: TracebackType | None,
|
|
137
|
+
) -> None:
|
|
138
|
+
self.finish()
|
|
139
|
+
|
|
140
|
+
def finish(self) -> None:
|
|
141
|
+
"""Schließt die Ausgabe ab: genau eine Leerzeile auf jedem Strom, der seit dem letzten
|
|
142
|
+
finish Ausgabe bekam; ohne Ausgabe nichts."""
|
|
143
|
+
for stream in self.written:
|
|
144
|
+
stream.write("\n")
|
|
145
|
+
stream.flush()
|
|
146
|
+
self.written.clear()
|
|
147
|
+
|
|
148
|
+
def spacing(self, name: str) -> int:
|
|
149
|
+
"""Abstand aus dem Theme, etwa i_row oder w_key."""
|
|
150
|
+
return self.theme.spacing[name]
|
|
151
|
+
|
|
152
|
+
def indent(self, name: str) -> str:
|
|
153
|
+
"""Einrückung aus dem Theme als Leerzeichen (i_head, i_row, i_hint)."""
|
|
154
|
+
return " " * self.spacing(name)
|
|
155
|
+
|
|
156
|
+
def write(
|
|
157
|
+
self, text: Text, stream: TextIO | None = None, hang: int = 0, wrap: bool = True
|
|
158
|
+
) -> None:
|
|
159
|
+
"""Gibt eine Zeile aus; im Terminal auf die Ausgabebreite umbrochen.
|
|
160
|
+
|
|
161
|
+
hang: Zahl der Zeichen am Anfang, die nur in der ersten Zeile stehen (Einzug und
|
|
162
|
+
Bezeichnung); Folgezeilen beginnen in dieser Spalte. Bleiben daneben weniger als
|
|
163
|
+
MIN_VALUE_WIDTH Zeichen, steht der Kopf allein und der Text darunter mit I_ROW.
|
|
164
|
+
wrap=False: nie umbrechen, auch wenn die Zeile breiter ist als das Terminal; für
|
|
165
|
+
Befehle und Pfade zum Kopieren. Farben und der Abschluss durch finish gelten weiter.
|
|
166
|
+
Steuerzeichen im Text entschärft guard. head, row, rows, hint und error tun das schon
|
|
167
|
+
vorher selbst: Eine Unterklasse, die write ersetzt, bekommt von ihnen geschützten Text
|
|
168
|
+
und ruft für eigene Ausgaben guard bzw. guarded auf.
|
|
169
|
+
"""
|
|
170
|
+
text = guarded(text)
|
|
171
|
+
target = stream or self.stream
|
|
172
|
+
if not any(target is seen for seen in self.written):
|
|
173
|
+
self.written.append(target)
|
|
174
|
+
console = console_for(target)
|
|
175
|
+
width = output_width(target, self.theme)
|
|
176
|
+
if not wrap or width is None or text.cell_len <= width:
|
|
177
|
+
console.print(text, crop=False, overflow="ignore")
|
|
178
|
+
return
|
|
179
|
+
head, rest = text[:hang], text[hang:]
|
|
180
|
+
if width - hang < MIN_VALUE_WIDTH:
|
|
181
|
+
if head.plain.strip():
|
|
182
|
+
head.rstrip()
|
|
183
|
+
head.truncate(width, overflow="ellipsis")
|
|
184
|
+
console.print(head, crop=False, overflow="ignore")
|
|
185
|
+
hang = min(self.spacing("i_row"), width // 3)
|
|
186
|
+
head = Text(" " * hang)
|
|
187
|
+
for index, line in enumerate(rest.wrap(console, width - hang)):
|
|
188
|
+
line.rstrip()
|
|
189
|
+
console.print((head if index == 0 else Text(" " * hang)) + line, crop=False)
|
|
190
|
+
|
|
191
|
+
def head(self, title: str) -> None:
|
|
192
|
+
"""Überschrift einer Gruppe, eingerückt um I_HEAD, in der Rolle head."""
|
|
193
|
+
if self.started:
|
|
194
|
+
self.stream.write("\n" * self.spacing("space"))
|
|
195
|
+
self.started = True
|
|
196
|
+
indent = self.indent("i_head")
|
|
197
|
+
title_text = Text(guard(title), style=self.styles["head"])
|
|
198
|
+
self.write(Text(indent) + title_text, hang=len(indent))
|
|
199
|
+
|
|
200
|
+
def row(self, label: str | Text, value: object, wrap: bool = True) -> None:
|
|
201
|
+
"""Bezeichnung (Rolle key) und Wert (Rolle val) in festen Spalten.
|
|
202
|
+
|
|
203
|
+
Ist die Bezeichnung länger als W_KEY, steht der Wert in der nächsten Zeile.
|
|
204
|
+
wrap=False: den Wert nie umbrechen, wie bei write; für Befehle zum Kopieren.
|
|
205
|
+
"""
|
|
206
|
+
self._row(label, value, self.spacing("w_key"), wrap)
|
|
207
|
+
|
|
208
|
+
def rows(self, entries: Iterable[tuple[str | Text, object]], wrap: bool = True) -> None:
|
|
209
|
+
"""Liste aus Bezeichnung und Wert wie row, alle Werte in einer Spalte.
|
|
210
|
+
|
|
211
|
+
Ist eine Bezeichnung länger als W_KEY, wird die erste Spalte samt GAP das kleinste
|
|
212
|
+
Vielfache von W_COL, in das sie passt (W_KEY 21, W_COL 12, 31 Zeichen → 36); so steht
|
|
213
|
+
jeder Wert in seiner Zeile, und Listen fluchten untereinander. Bleiben daneben weniger
|
|
214
|
+
als MIN_VALUE_WIDTH Zeichen, gilt W_KEY wie bei row.
|
|
215
|
+
"""
|
|
216
|
+
entries = [(self._label(label), value) for label, value in entries]
|
|
217
|
+
key, gap, step = self.spacing("w_key"), self.spacing("gap"), self.spacing("w_col")
|
|
218
|
+
longest = max((label.cell_len for label, _ in entries), default=0)
|
|
219
|
+
if longest > key:
|
|
220
|
+
grid = -(-(longest + gap) // step) * step - gap
|
|
221
|
+
width = output_width(self.stream, self.theme)
|
|
222
|
+
if width is None or width - self.spacing("i_row") - grid - gap >= MIN_VALUE_WIDTH:
|
|
223
|
+
key = grid
|
|
224
|
+
for label, value in entries:
|
|
225
|
+
self._row(label, value, key, wrap)
|
|
226
|
+
|
|
227
|
+
def _label(self, label: str | Text) -> Text:
|
|
228
|
+
"""Bezeichnung als Text in der Rolle key, Steuerzeichen entschärft."""
|
|
229
|
+
if isinstance(label, Text):
|
|
230
|
+
return guarded(label)
|
|
231
|
+
return Text(guard(label), style=self.styles["key"])
|
|
232
|
+
|
|
233
|
+
def _row(self, label: str | Text, value: object, key: int, wrap: bool) -> None:
|
|
234
|
+
"""row mit der Breite key für die Bezeichnung statt W_KEY."""
|
|
235
|
+
self.started = True
|
|
236
|
+
indent = self.indent("i_row")
|
|
237
|
+
label_text = self._label(label)
|
|
238
|
+
value_text = (
|
|
239
|
+
guarded(value)
|
|
240
|
+
if isinstance(value, Text)
|
|
241
|
+
else Text(guard(str(value)), style=self.styles["val"])
|
|
242
|
+
)
|
|
243
|
+
width = key + self.spacing("gap")
|
|
244
|
+
column = len(indent) + width
|
|
245
|
+
if label_text.cell_len <= key:
|
|
246
|
+
padding = Text(" " * (width - label_text.cell_len))
|
|
247
|
+
self.write(Text(indent) + label_text + padding + value_text, hang=column, wrap=wrap)
|
|
248
|
+
else:
|
|
249
|
+
self.write(Text(indent) + label_text, hang=len(indent), wrap=wrap)
|
|
250
|
+
self.write(Text(" " * column) + value_text, hang=column, wrap=wrap)
|
|
251
|
+
|
|
252
|
+
def hint(self, value: str) -> None:
|
|
253
|
+
"""Hinweistext, eingerückt um I_HINT, in der Rolle hint, Zeile für Zeile."""
|
|
254
|
+
self.started = True
|
|
255
|
+
indent = self.indent("i_hint")
|
|
256
|
+
for line in guard(value).splitlines():
|
|
257
|
+
self.write(Text(indent) + Text(line, style=self.styles["hint"]), hang=len(indent))
|
|
258
|
+
|
|
259
|
+
def error(self, message: str) -> None:
|
|
260
|
+
"""Fehlermeldung in der Rolle err auf den Fehlerstrom."""
|
|
261
|
+
self.write(Text(guard(message), style=self.styles["err"]), self.error_stream)
|