printer-cli 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.
prt/tui/app.tcss ADDED
@@ -0,0 +1,308 @@
1
+ /* prt — "lab instrument panel".
2
+ * Black field, white type, gray hairlines, bright green as the only accent (focus, active, ok).
3
+ * Ink is the only colour that fills anything. Red/amber appear on text only.
4
+ * Gray (#6B7280, 4.3:1 on black) is used for borders and rules — never for text.
5
+ */
6
+
7
+ Screen {
8
+ background: #000000;
9
+ color: #FFFFFF;
10
+ }
11
+
12
+ #topbar {
13
+ height: 1;
14
+ background: #000000;
15
+ padding: 0 1;
16
+ }
17
+
18
+ TabbedContent {
19
+ height: 1fr;
20
+ }
21
+
22
+ Tabs {
23
+ background: #000000;
24
+ }
25
+
26
+ Tab {
27
+ color: #FFFFFF;
28
+ text-style: none;
29
+ }
30
+
31
+ Tab.-active {
32
+ color: #22C55E;
33
+ text-style: bold;
34
+ }
35
+
36
+ Tab:hover {
37
+ color: #22C55E;
38
+ background: #000000;
39
+ }
40
+
41
+ /* Textual paints the focused active tab with its blue cursor colour; keep it on-palette. */
42
+ Tabs:focus .-active, Tabs .-active, Tabs:focus Tab.-active {
43
+ background: #000000;
44
+ color: #22C55E;
45
+ text-style: bold;
46
+ }
47
+
48
+ Underline > .underline--bar {
49
+ background: #6B7280;
50
+ color: #22C55E;
51
+ }
52
+
53
+ TabPane {
54
+ padding: 1 1 0 1;
55
+ }
56
+
57
+ /* --- dashboard grid --------------------------------------------------------- */
58
+
59
+ #dash {
60
+ layout: grid;
61
+ grid-size: 2 2;
62
+ grid-columns: 3fr 2fr;
63
+ grid-rows: auto 1fr;
64
+ grid-gutter: 1 2;
65
+ height: 1fr;
66
+ }
67
+
68
+ #dash.narrow {
69
+ grid-size: 1;
70
+ grid-columns: 1fr;
71
+ grid-rows: auto auto auto auto;
72
+ overflow-y: auto;
73
+ }
74
+
75
+ Panel {
76
+ border: round #6B7280;
77
+ border-title-color: #FFFFFF;
78
+ border-title-style: bold;
79
+ padding: 0 1;
80
+ height: auto;
81
+ background: #000000;
82
+ }
83
+
84
+ Panel:focus {
85
+ border: round #22C55E;
86
+ }
87
+
88
+ #ink {
89
+ padding: 1 2 0 2;
90
+ text-align: center;
91
+ }
92
+
93
+ #side {
94
+ height: auto;
95
+ }
96
+
97
+ #side Panel {
98
+ margin-bottom: 1;
99
+ }
100
+
101
+ /* --- actions ---------------------------------------------------------------- */
102
+
103
+ Button {
104
+ background: #000000;
105
+ color: #FFFFFF;
106
+ border: round #6B7280;
107
+ min-width: 18;
108
+ height: 3;
109
+ text-style: bold;
110
+ }
111
+
112
+ Button:hover {
113
+ background: #000000;
114
+ border: round #FFFFFF;
115
+ }
116
+
117
+ Button:focus {
118
+ background: #000000;
119
+ background-tint: #000000 0%;
120
+ color: #22C55E;
121
+ border: round #22C55E;
122
+ text-style: bold;
123
+ }
124
+
125
+ Button.-active {
126
+ background: #000000;
127
+ border: round #22C55E;
128
+ }
129
+
130
+ Button.danger {
131
+ color: #EF4444;
132
+ }
133
+
134
+ Button:disabled {
135
+ color: #6B7280;
136
+ border: round #6B7280;
137
+ text-style: none;
138
+ }
139
+
140
+ .actions {
141
+ height: auto;
142
+ margin: 0 0 1 0;
143
+ }
144
+
145
+ .actions Button {
146
+ margin-right: 2;
147
+ }
148
+
149
+ .hint {
150
+ color: #FFFFFF;
151
+ text-style: italic;
152
+ margin: 0 0 1 0;
153
+ height: auto;
154
+ }
155
+
156
+ .field-row {
157
+ height: auto;
158
+ margin-bottom: 1;
159
+ }
160
+
161
+ .field {
162
+ width: 1fr;
163
+ height: auto;
164
+ margin-right: 2;
165
+ }
166
+
167
+ .field Label {
168
+ margin-bottom: 0;
169
+ text-style: bold;
170
+ }
171
+
172
+ Input, Select > SelectCurrent {
173
+ background: #000000;
174
+ color: #FFFFFF;
175
+ border: round #6B7280;
176
+ }
177
+
178
+ Input:focus, Select:focus > SelectCurrent {
179
+ border: round #22C55E;
180
+ }
181
+
182
+ Input > .input--placeholder {
183
+ color: #FFFFFF;
184
+ text-style: italic;
185
+ }
186
+
187
+ SelectOverlay {
188
+ background: #000000;
189
+ border: round #22C55E;
190
+ }
191
+
192
+ Switch {
193
+ background: #000000;
194
+ border: round #6B7280;
195
+ }
196
+
197
+ Switch:focus {
198
+ border: round #22C55E;
199
+ }
200
+
201
+ Switch > .switch--slider {
202
+ color: #6B7280;
203
+ background: #000000;
204
+ }
205
+
206
+ Switch.-on > .switch--slider {
207
+ color: #22C55E;
208
+ }
209
+
210
+ RichLog {
211
+ background: #000000;
212
+ border: round #6B7280;
213
+ height: 1fr;
214
+ min-height: 6;
215
+ padding: 0 1;
216
+ }
217
+
218
+ RichLog:focus {
219
+ border: round #22C55E;
220
+ }
221
+
222
+ DataTable {
223
+ background: #000000;
224
+ height: 1fr;
225
+ border: round #6B7280;
226
+ }
227
+
228
+ DataTable:focus {
229
+ border: round #22C55E;
230
+ }
231
+
232
+ DataTable > .datatable--header {
233
+ background: #000000;
234
+ color: #FFFFFF;
235
+ text-style: bold;
236
+ }
237
+
238
+ /* Selected row: green text + underline — green stays a highlight, never a background. */
239
+ DataTable > .datatable--cursor {
240
+ background: #000000;
241
+ color: #22C55E;
242
+ text-style: bold underline;
243
+ }
244
+
245
+ DataTable > .datatable--hover {
246
+ background: #000000;
247
+ text-style: underline;
248
+ }
249
+
250
+ /* --- modal ---------------------------------------------------------------------- */
251
+
252
+ ConfirmScreen {
253
+ align: center middle;
254
+ background: #000000 70%;
255
+ }
256
+
257
+ #dialog {
258
+ width: 72;
259
+ max-width: 95%;
260
+ height: auto;
261
+ border: round #22C55E;
262
+ background: #000000;
263
+ padding: 1 2;
264
+ }
265
+
266
+ #dialog #question {
267
+ text-style: bold;
268
+ margin-bottom: 1;
269
+ }
270
+
271
+ #dialog #details {
272
+ margin-bottom: 1;
273
+ height: auto;
274
+ }
275
+
276
+ #dialog .actions {
277
+ align-horizontal: right;
278
+ margin: 0;
279
+ }
280
+
281
+ Footer {
282
+ background: #000000;
283
+ color: #FFFFFF;
284
+ }
285
+
286
+ Footer .footer-key--key {
287
+ background: #000000;
288
+ color: #22C55E;
289
+ text-style: bold;
290
+ }
291
+
292
+ Footer .footer-key--description {
293
+ color: #FFFFFF;
294
+ }
295
+
296
+ Toast {
297
+ background: #000000;
298
+ border-left: outer #22C55E;
299
+ color: #FFFFFF;
300
+ }
301
+
302
+ Toast.-error {
303
+ border-left: outer #EF4444;
304
+ }
305
+
306
+ Toast.-warning {
307
+ border-left: outer #F59E0B;
308
+ }
prt/tui/widgets.py ADDED
@@ -0,0 +1,181 @@
1
+ """Dashboard widgets. Rendering is pure (Status/PrinterInfo → rich Text) so it is testable."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import time
6
+
7
+ from rich.text import Text
8
+ from textual.widgets import Static
9
+
10
+ from prt.models import Ink, PrinterInfo, Severity, Status
11
+ from prt.style import escape, ink_colors, is_dark
12
+
13
+ # Palette (frontend-design default): black field, white text, gray hairlines, one green accent.
14
+ # Status colours are used on text only. Gray is never used for text (4.3:1 on black < AA).
15
+ WHITE, GRAY, GREEN = "#FFFFFF", "#6B7280", "#22C55E"
16
+ RED, AMBER = "#EF4444", "#F59E0B"
17
+ EIGHTHS = " ▁▂▃▄▅▆▇█"
18
+
19
+
20
+ def ink_fills(ink: Ink) -> list[str]:
21
+ """The cartridge's real colour(s) — several for a multi-colour cartridge such as an HP
22
+ tri-colour; near-black inks are drawn white so they show on the black field."""
23
+ return [WHITE if is_dark(c) else c for c in ink_colors(ink.color)] or [WHITE]
24
+
25
+
26
+ def render_tanks(inks: list[Ink], height: int = 10, tank_w: int = 6, gap: int = 4,
27
+ waste: str | None = None) -> Text:
28
+ """Vertical cartridge tanks side by side, filled from the bottom in eighth-cell steps."""
29
+ out = Text()
30
+ if not inks:
31
+ out.append("no ink data reported", style="italic")
32
+ return out
33
+ inner = tank_w - 2
34
+ # cap row
35
+ for i, _ in enumerate(inks):
36
+ out.append(("" if i == 0 else " " * gap) + "▁" * tank_w, style=GRAY)
37
+ out.append("\n")
38
+ for row in range(height, 0, -1): # top → bottom
39
+ for i, ink in enumerate(inks):
40
+ if i:
41
+ out.append(" " * gap)
42
+ eighths = 0 if ink.level is None else round(ink.level / 100 * height * 8)
43
+ cell_floor = (row - 1) * 8
44
+ fill = max(0, min(8, eighths - cell_floor))
45
+ low_row = ink.level is not None and row == max(1, round(ink.low / 100 * height))
46
+ out.append("▕", style=GRAY)
47
+ fills = ink_fills(ink)
48
+ for cell in range(inner): # multi-colour cartridges split the tank into stripes
49
+ out.append(EIGHTHS[fill], style=fills[cell * len(fills) // inner])
50
+ out.append("▏" if not low_row else "◂", style=AMBER if low_row else GRAY)
51
+ out.append("\n")
52
+ for i, _ in enumerate(inks):
53
+ out.append(("" if i == 0 else " " * gap) + "▔" * tank_w, style=GRAY)
54
+ out.append("\n")
55
+ for i, ink in enumerate(inks):
56
+ out.append(("" if i == 0 else " " * gap) + f"{ink.short:^{tank_w}}", style="bold")
57
+ out.append("\n")
58
+ for i, ink in enumerate(inks):
59
+ pct = "?" if ink.level is None else f"{ink.level}%"
60
+ colour = {"replace": RED, "low": AMBER}.get(ink.state, WHITE)
61
+ out.append(("" if i == 0 else " " * gap) + f"{pct:^{tank_w}}", style=f"bold {colour}")
62
+ out.append("\n")
63
+ for i, ink in enumerate(inks):
64
+ word = {"replace": "✗ out", "low": "▲ low", "unknown": "?"}.get(ink.state, "")
65
+ colour = {"replace": RED, "low": AMBER}.get(ink.state, WHITE)
66
+ out.append(("" if i == 0 else " " * gap) + f"{word:^{tank_w}}", style=colour)
67
+ # The waste ink pad decides whether the printer keeps working: show it with the inks.
68
+ if waste:
69
+ sym, colour, word = {"ok": ("●", GREEN, "ok"), "almost-full": ("▲", AMBER, "almost full — service soon"),
70
+ "full": ("✗", RED, "full — service required")}.get(waste, ("◆", WHITE, waste))
71
+ out.append("\n\n")
72
+ out.append("waste ink pad ")
73
+ out.append(f"{sym} ", style=f"bold {colour}")
74
+ out.append(word, style="bold")
75
+ return out
76
+
77
+
78
+ def _uptime(seconds: int | None) -> str:
79
+ if seconds is None:
80
+ return "—"
81
+ d, rem = divmod(seconds, 86400)
82
+ h, rem = divmod(rem, 3600)
83
+ return f"{d}d {h}h {rem // 60:02d}m" if d else f"{h}h {rem // 60:02d}m"
84
+
85
+
86
+ def render_system(info: PrinterInfo | None) -> Text:
87
+ out = Text()
88
+ if info is None:
89
+ out.append("waiting for the printer…", style="italic")
90
+ return out
91
+ rows = [
92
+ ("Model", info.make_model), ("Firmware", info.firmware), ("Serial", info.serial),
93
+ ("Uptime", _uptime(info.uptime_seconds)),
94
+ ("Pages", f"{info.page_count:,}" if info.page_count is not None else None),
95
+ ("Host", info.host), ("Driver", info.driver),
96
+ ("Speed", f"{info.ppm} ppm" if info.ppm else None),
97
+ ("Duplex", "yes" if info.duplex else ("no" if info.duplex is not None else None)),
98
+ ]
99
+ first = True
100
+ for k, v in rows:
101
+ if v in (None, ""):
102
+ continue
103
+ if not first:
104
+ out.append("\n")
105
+ first = False
106
+ out.append(f"{k:<10}")
107
+ out.append(escape(v), style="bold")
108
+ return out
109
+
110
+
111
+ def render_paper(st: Status | None) -> Text:
112
+ out = Text()
113
+ if st is None or not st.trays:
114
+ out.append("no media reported", style="italic")
115
+ return out
116
+ for i, tray in enumerate(st.trays):
117
+ if i:
118
+ out.append("\n")
119
+ out.append(f"{escape(tray.source):<7}")
120
+ out.append(escape(tray.media or "?"), style="bold")
121
+ if tray.media_type:
122
+ out.append(f" · {escape(tray.media_type)}")
123
+ out.append(" ✓", style=GREEN)
124
+ if tray.level is not None:
125
+ out.append(f" {tray.level}%")
126
+ if all(t.level is None for t in st.trays):
127
+ out.append("\n")
128
+ out.append("fill level not reported by printer", style="italic")
129
+ return out
130
+
131
+
132
+ def render_alerts(st: Status | None) -> Text:
133
+ out = Text()
134
+ if st is None:
135
+ return out
136
+ if not st.alerts:
137
+ out.append("● ", style=GREEN)
138
+ out.append("all clear")
139
+ return out
140
+ for i, a in enumerate(st.alerts):
141
+ if i:
142
+ out.append("\n")
143
+ sym, colour = {Severity.ERROR: ("✗", RED), Severity.WARNING: ("▲", AMBER),
144
+ Severity.INFO: ("◆", WHITE)}[a.severity]
145
+ out.append(f"{sym} ", style=f"bold {colour}")
146
+ out.append(escape(a.message))
147
+ return out
148
+
149
+
150
+ def render_topbar(name: str, model: str, st: Status | None, printers: list[tuple[str, bool]],
151
+ active: int, busy: bool) -> Text:
152
+ out = Text()
153
+ out.append(" prt ", style=f"bold {GREEN}")
154
+ out.append("│ ", style=GRAY)
155
+ out.append(escape(model), style="bold")
156
+ out.append(f" {escape(name)} ")
157
+ if st is None:
158
+ out.append("○ connecting…" if busy else "○ unknown")
159
+ elif st.stale:
160
+ out.append("○ offline", style=f"bold {AMBER}")
161
+ out.append(f" · last seen {time.strftime('%H:%M', time.localtime(st.checked_at))}")
162
+ else:
163
+ colour = {"idle": GREEN, "processing": GREEN, "stopped": RED}.get(st.state, WHITE)
164
+ out.append("● ", style=colour)
165
+ out.append(st.state, style="bold")
166
+ if st.queued_jobs:
167
+ out.append(f" · {st.queued_jobs} queued")
168
+ if len(printers) > 1:
169
+ out.append(" ")
170
+ for i, (label, ok) in enumerate(printers):
171
+ style = f"bold {GREEN}" if i == active else ""
172
+ out.append(f" [{i + 1}] {escape(label)}", style=style)
173
+ return out
174
+
175
+
176
+ class Panel(Static):
177
+ """A bordered dashboard card; the border title carries its name."""
178
+
179
+ def __init__(self, title: str, **kwargs):
180
+ super().__init__("", **kwargs)
181
+ self.border_title = title