mintterm 0.2.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.
- mintterm/__init__.py +3 -0
- mintterm/__main__.py +38 -0
- mintterm/app.py +765 -0
- mintterm/assets/icon.svg +12 -0
- mintterm/assets/logo.svg +15 -0
- mintterm/branding.py +21 -0
- mintterm/clipboard.py +22 -0
- mintterm/helper.py +132 -0
- mintterm/prompt.py +64 -0
- mintterm/render.py +23 -0
- mintterm/runner.py +106 -0
- mintterm/safety.py +97 -0
- mintterm/storage.py +82 -0
- mintterm/themes.py +34 -0
- mintterm/trash.py +68 -0
- mintterm/views.py +412 -0
- mintterm-0.2.0.dist-info/METADATA +168 -0
- mintterm-0.2.0.dist-info/RECORD +22 -0
- mintterm-0.2.0.dist-info/WHEEL +5 -0
- mintterm-0.2.0.dist-info/entry_points.txt +2 -0
- mintterm-0.2.0.dist-info/licenses/LICENSE +21 -0
- mintterm-0.2.0.dist-info/top_level.txt +1 -0
mintterm/trash.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Move files to a mintterm trash instead of deleting them, so undo can bring them back."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import time
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from .storage import TRASH_DIR
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Action:
|
|
13
|
+
"""A reversible file operation. pairs are (current_location, original_location)."""
|
|
14
|
+
|
|
15
|
+
label: str
|
|
16
|
+
pairs: list
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def move_to_trash(paths):
|
|
20
|
+
"""Move paths into a new trash batch. Returns (Action or None, error messages)."""
|
|
21
|
+
errors = []
|
|
22
|
+
if not paths:
|
|
23
|
+
return None, ["Nothing to move."]
|
|
24
|
+
|
|
25
|
+
batch = os.path.join(TRASH_DIR, time.strftime("%Y%m%d-%H%M%S") + f"-{time.monotonic_ns() % 100000}")
|
|
26
|
+
os.makedirs(batch, exist_ok=True)
|
|
27
|
+
|
|
28
|
+
pairs = []
|
|
29
|
+
for path in paths:
|
|
30
|
+
original = os.path.abspath(path)
|
|
31
|
+
if not os.path.lexists(original):
|
|
32
|
+
errors.append(f"No such file: {path}")
|
|
33
|
+
continue
|
|
34
|
+
name = os.path.basename(original.rstrip(os.sep)) or "root"
|
|
35
|
+
dest = os.path.join(batch, name)
|
|
36
|
+
n = 1
|
|
37
|
+
while os.path.lexists(dest):
|
|
38
|
+
dest = os.path.join(batch, f"{name}.{n}")
|
|
39
|
+
n += 1
|
|
40
|
+
try:
|
|
41
|
+
shutil.move(original, dest)
|
|
42
|
+
pairs.append((dest, original))
|
|
43
|
+
except OSError as exc:
|
|
44
|
+
errors.append(f"{path}: {exc.strerror or exc}")
|
|
45
|
+
|
|
46
|
+
if not pairs:
|
|
47
|
+
return None, errors
|
|
48
|
+
return Action(f"moved {len(pairs)} item(s)", pairs), errors
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def undo(action):
|
|
52
|
+
"""Move each item back to where it came from. Returns (restored count, error messages)."""
|
|
53
|
+
restored = 0
|
|
54
|
+
errors = []
|
|
55
|
+
for current, original in action.pairs:
|
|
56
|
+
if not os.path.lexists(current):
|
|
57
|
+
errors.append(f"Missing, cannot restore: {current}")
|
|
58
|
+
continue
|
|
59
|
+
if os.path.lexists(original):
|
|
60
|
+
errors.append(f"Already exists, not overwritten: {original}")
|
|
61
|
+
continue
|
|
62
|
+
try:
|
|
63
|
+
os.makedirs(os.path.dirname(original), exist_ok=True)
|
|
64
|
+
shutil.move(current, original)
|
|
65
|
+
restored += 1
|
|
66
|
+
except OSError as exc:
|
|
67
|
+
errors.append(f"{original}: {exc.strerror or exc}")
|
|
68
|
+
return restored, errors
|
mintterm/views.py
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
"""Turn plain command output into structured views: tables, bars, key-value pairs and text.
|
|
2
|
+
|
|
3
|
+
Every parser takes plain text and returns plain Python data, so it can be tested without pygame.
|
|
4
|
+
`plan(command)` decides what to really run and which renderer to use. Commands with pipes,
|
|
5
|
+
redirects or other shell syntax run exactly as typed, with plain output.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
from .render import parse_df as parse_df_rows
|
|
12
|
+
|
|
13
|
+
MAX_ROWS = 300
|
|
14
|
+
SHELL_OPERATORS = set("|;&<>`(){}")
|
|
15
|
+
|
|
16
|
+
_UNITS = {"": 1, "K": 1024, "M": 1024**2, "G": 1024**3, "T": 1024**4, "P": 1024**5}
|
|
17
|
+
_SIZE_RE = re.compile(r"^\s*([\d.]+)\s*([KMGTP]?)(i?B?)?\s*$", re.IGNORECASE)
|
|
18
|
+
_GREP_RE = re.compile(r"^(.+?):(\d+):(.*)$")
|
|
19
|
+
_GREP_ONE_FILE_RE = re.compile(r"^(\d+):(.*)$")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# ---- view builders ---------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
def text_view(lines):
|
|
25
|
+
return [{"type": "text", "lines": list(lines)}]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def kv_view(pairs):
|
|
29
|
+
return [{"type": "kv", "pairs": list(pairs)}]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def table(headers, rows, tone=None, bar_col=None):
|
|
33
|
+
rows = [[str(c) for c in r] for r in rows][:MAX_ROWS]
|
|
34
|
+
tone = list(tone) if tone else [None] * len(rows)
|
|
35
|
+
return {"type": "table", "headers": list(headers), "rows": rows, "tone": tone, "bar_col": bar_col}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def table_layout(headers, rows, bar_col):
|
|
39
|
+
"""Column positions in character units: a list of (x, width) per column."""
|
|
40
|
+
layout = []
|
|
41
|
+
x = 0
|
|
42
|
+
for i, header in enumerate(headers):
|
|
43
|
+
if i == bar_col:
|
|
44
|
+
width = 22
|
|
45
|
+
else:
|
|
46
|
+
longest = max([len(str(header))] + [len(str(r[i])) for r in rows if i < len(r)])
|
|
47
|
+
width = min(longest, 48) + 2
|
|
48
|
+
layout.append((x, width))
|
|
49
|
+
x += width
|
|
50
|
+
return layout
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# ---- parsers ---------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
def parse_size(text):
|
|
56
|
+
"""'4.0K' -> 4096, '1.5Gi' -> 1610612736, '0' -> 0."""
|
|
57
|
+
m = _SIZE_RE.match(text or "")
|
|
58
|
+
if not m:
|
|
59
|
+
return 0
|
|
60
|
+
return int(float(m.group(1)) * _UNITS[m.group(2).upper()])
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def parse_ls_long(text):
|
|
64
|
+
"""`ls -l` lines -> (rows, tone). Folders get ▸, links →, executables *."""
|
|
65
|
+
rows, tone = [], []
|
|
66
|
+
for line in text.splitlines():
|
|
67
|
+
if not line or line.startswith("total"):
|
|
68
|
+
continue
|
|
69
|
+
p = line.split(None, 6)
|
|
70
|
+
if len(p) < 7:
|
|
71
|
+
continue
|
|
72
|
+
perms, owner, size, date, name = p[0], p[2], p[4], p[5], p[6]
|
|
73
|
+
if perms.startswith("d"):
|
|
74
|
+
mark, t = "▸", "accent"
|
|
75
|
+
elif perms.startswith("l"):
|
|
76
|
+
mark, t = "→", None
|
|
77
|
+
elif any(perms[i] == "x" for i in (3, 6, 9) if i < len(perms)):
|
|
78
|
+
mark, t = "*", "prompt"
|
|
79
|
+
else:
|
|
80
|
+
mark, t = "·", None
|
|
81
|
+
rows.append([f"{mark} {name}", size, date, perms, owner])
|
|
82
|
+
tone.append(t)
|
|
83
|
+
return rows, tone
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def parse_du(text):
|
|
87
|
+
rows = []
|
|
88
|
+
for line in text.splitlines():
|
|
89
|
+
if "\t" not in line:
|
|
90
|
+
continue
|
|
91
|
+
size, path = line.split("\t", 1)
|
|
92
|
+
rows.append((size.strip(), path.strip()))
|
|
93
|
+
return rows
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def parse_ps(text):
|
|
97
|
+
"""`ps aux` lines -> (pid, cpu, mem, command) tuples."""
|
|
98
|
+
rows = []
|
|
99
|
+
for line in text.splitlines()[1:]:
|
|
100
|
+
p = line.split(None, 10)
|
|
101
|
+
if len(p) < 11:
|
|
102
|
+
continue
|
|
103
|
+
rows.append((p[1], p[2], p[3], p[10]))
|
|
104
|
+
return rows[:25]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def parse_free(text):
|
|
108
|
+
"""`free -h` -> bar rows for RAM and swap."""
|
|
109
|
+
bars = []
|
|
110
|
+
for line in text.splitlines():
|
|
111
|
+
p = line.split()
|
|
112
|
+
if len(p) < 3 or p[0] not in ("Mem:", "Swap:"):
|
|
113
|
+
continue
|
|
114
|
+
total, used = parse_size(p[1]), parse_size(p[2])
|
|
115
|
+
pct = int(used * 100 / total) if total else 0
|
|
116
|
+
label = "RAM" if p[0] == "Mem:" else "swap"
|
|
117
|
+
bars.append((label, pct, f"{p[2]} of {p[1]}"))
|
|
118
|
+
return bars
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def parse_ip_brief(text):
|
|
122
|
+
rows, tone = [], []
|
|
123
|
+
for line in text.splitlines():
|
|
124
|
+
p = line.split()
|
|
125
|
+
if len(p) < 2:
|
|
126
|
+
continue
|
|
127
|
+
rows.append([p[0], p[1], " ".join(p[2:]) or "-"])
|
|
128
|
+
tone.append("prompt" if p[1] == "UP" else "muted")
|
|
129
|
+
return rows, tone
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def parse_ss(text):
|
|
133
|
+
rows = []
|
|
134
|
+
for line in text.splitlines()[1:]:
|
|
135
|
+
p = line.split()
|
|
136
|
+
if len(p) < 5:
|
|
137
|
+
continue
|
|
138
|
+
names = re.findall(r'\("([^"]+)"', line)
|
|
139
|
+
rows.append([p[0], p[4], ", ".join(sorted(set(names))) or "-"])
|
|
140
|
+
return rows
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def parse_git_status(text):
|
|
144
|
+
"""`git status --porcelain=v1 -b` -> (key-value pairs, rows, tone)."""
|
|
145
|
+
lines = text.splitlines()
|
|
146
|
+
pairs, rows, tone = [], [], []
|
|
147
|
+
if lines and lines[0].startswith("## "):
|
|
148
|
+
head = lines[0][3:]
|
|
149
|
+
branch = head.split("...")[0].strip() or "?"
|
|
150
|
+
pairs.append(("branch", branch))
|
|
151
|
+
if "[" in head:
|
|
152
|
+
sync = head[head.index("[") + 1:].rstrip("]")
|
|
153
|
+
elif "..." in head:
|
|
154
|
+
sync = "up to date"
|
|
155
|
+
else:
|
|
156
|
+
sync = "no upstream"
|
|
157
|
+
pairs.append(("sync", sync))
|
|
158
|
+
for line in lines[1:]:
|
|
159
|
+
if len(line) < 4:
|
|
160
|
+
continue
|
|
161
|
+
code, path = line[:2], line[3:]
|
|
162
|
+
if code == "??":
|
|
163
|
+
label, t = "new", None
|
|
164
|
+
elif "D" in code:
|
|
165
|
+
label, t = "deleted", "warn"
|
|
166
|
+
elif "A" in code:
|
|
167
|
+
label, t = "added", "accent"
|
|
168
|
+
elif "R" in code:
|
|
169
|
+
label, t = "renamed", "accent"
|
|
170
|
+
elif "M" in code:
|
|
171
|
+
label, t = "modified", None
|
|
172
|
+
else:
|
|
173
|
+
label, t = "changed", None
|
|
174
|
+
rows.append([label, path])
|
|
175
|
+
tone.append(t)
|
|
176
|
+
return pairs, rows, tone
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def parse_git_log(text):
|
|
180
|
+
rows = []
|
|
181
|
+
for line in text.splitlines():
|
|
182
|
+
parts = line.split("\t", 2)
|
|
183
|
+
if len(parts) == 3:
|
|
184
|
+
rows.append(parts)
|
|
185
|
+
return rows
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def parse_grep(text):
|
|
189
|
+
rows = []
|
|
190
|
+
for line in text.splitlines():
|
|
191
|
+
m = _GREP_RE.match(line)
|
|
192
|
+
if m:
|
|
193
|
+
rows.append([m.group(1), m.group(2), m.group(3).strip()[:120]])
|
|
194
|
+
continue
|
|
195
|
+
m = _GREP_ONE_FILE_RE.match(line)
|
|
196
|
+
if m:
|
|
197
|
+
rows.append(["(this file)", m.group(1), m.group(2).strip()[:120]])
|
|
198
|
+
return rows
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def parse_apt_upgradable(text):
|
|
202
|
+
rows = []
|
|
203
|
+
for line in text.splitlines():
|
|
204
|
+
if "[upgradable from" not in line:
|
|
205
|
+
continue
|
|
206
|
+
p = line.split()
|
|
207
|
+
if len(p) < 2:
|
|
208
|
+
continue
|
|
209
|
+
name = p[0].split("/")[0]
|
|
210
|
+
repo = p[0].partition("/")[2].split(",")[0] or "-"
|
|
211
|
+
rows.append([name, p[1], repo])
|
|
212
|
+
return rows
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def parse_failed_units(text):
|
|
216
|
+
rows = []
|
|
217
|
+
for line in text.splitlines():
|
|
218
|
+
p = line.split(None, 4)
|
|
219
|
+
if len(p) < 4:
|
|
220
|
+
continue
|
|
221
|
+
desc = p[4] if len(p) > 4 else ""
|
|
222
|
+
rows.append([p[0], f"{p[2]} ({p[3]})", desc])
|
|
223
|
+
return rows
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def parse_pct(cell):
|
|
227
|
+
try:
|
|
228
|
+
return int(float(str(cell).rstrip("%")))
|
|
229
|
+
except ValueError:
|
|
230
|
+
return 0
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
# ---- renderers: Result -> view items ---------------------------------------
|
|
234
|
+
|
|
235
|
+
def _plain(r):
|
|
236
|
+
return text_view(r.output.splitlines())
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def render_ls(r):
|
|
240
|
+
if r.code != 0:
|
|
241
|
+
return _plain(r)
|
|
242
|
+
rows, tone = parse_ls_long(r.output)
|
|
243
|
+
if not rows:
|
|
244
|
+
return text_view(["Empty folder."])
|
|
245
|
+
return [table(["name", "size", "modified", "permissions", "owner"], rows, tone)]
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def render_df(r):
|
|
249
|
+
if r.code != 0:
|
|
250
|
+
return _plain(r)
|
|
251
|
+
rows, tone = [], []
|
|
252
|
+
for d in parse_df_rows(r.output):
|
|
253
|
+
rows.append([d["mount"], d["size"], d["used"], d["avail"], f"{d['pct']}%"])
|
|
254
|
+
tone.append("warn" if d["pct"] > 85 else None)
|
|
255
|
+
if not rows:
|
|
256
|
+
return _plain(r)
|
|
257
|
+
return [table(["mount", "size", "used", "free", "use"], rows, tone, bar_col=4)]
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def render_du(r):
|
|
261
|
+
if r.code != 0:
|
|
262
|
+
return _plain(r)
|
|
263
|
+
entries = parse_du(r.output)
|
|
264
|
+
if not entries:
|
|
265
|
+
return _plain(r)
|
|
266
|
+
biggest = max(parse_size(size) for size, _ in entries) or 1
|
|
267
|
+
rows = [[size, path, f"{int(parse_size(size) * 100 / biggest)}%"] for size, path in entries]
|
|
268
|
+
return [table(["size", "path", "share"], rows, bar_col=2)]
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def render_ps(r):
|
|
272
|
+
if r.code != 0:
|
|
273
|
+
return _plain(r)
|
|
274
|
+
rows = parse_ps(r.output)
|
|
275
|
+
if not rows:
|
|
276
|
+
return _plain(r)
|
|
277
|
+
cells = [[pid, f"{cpu}%", f"{mem}%", cmd[:60]] for pid, cpu, mem, cmd in rows]
|
|
278
|
+
tone = ["warn" if float(cpu) >= 50 else None for _, cpu, _, _ in rows]
|
|
279
|
+
return [table(["pid", "cpu", "mem", "command"], cells, tone, bar_col=1)]
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def render_free(r):
|
|
283
|
+
if r.code != 0:
|
|
284
|
+
return _plain(r)
|
|
285
|
+
bars = parse_free(r.output)
|
|
286
|
+
if not bars:
|
|
287
|
+
return _plain(r)
|
|
288
|
+
return [{"type": "bars", "rows": bars}]
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def render_ip(r):
|
|
292
|
+
if r.code != 0:
|
|
293
|
+
return _plain(r)
|
|
294
|
+
rows, tone = parse_ip_brief(r.output)
|
|
295
|
+
if not rows:
|
|
296
|
+
return _plain(r)
|
|
297
|
+
return [table(["interface", "state", "addresses"], rows, tone)]
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def render_ss(r):
|
|
301
|
+
rows = parse_ss(r.output)
|
|
302
|
+
if not rows:
|
|
303
|
+
return _plain(r)
|
|
304
|
+
return [table(["protocol", "listening on", "process"], rows)]
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def render_git_status(r):
|
|
308
|
+
if r.code != 0:
|
|
309
|
+
return _plain(r)
|
|
310
|
+
pairs, rows, tone = parse_git_status(r.output)
|
|
311
|
+
pairs.append(("changes", str(len(rows))))
|
|
312
|
+
items = kv_view(pairs)
|
|
313
|
+
if rows:
|
|
314
|
+
items.append(table(["change", "file"], rows, tone))
|
|
315
|
+
else:
|
|
316
|
+
items += text_view(["Working tree clean."])
|
|
317
|
+
return items
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def render_git_log(r):
|
|
321
|
+
if r.code != 0:
|
|
322
|
+
return _plain(r)
|
|
323
|
+
rows = parse_git_log(r.output)
|
|
324
|
+
if not rows:
|
|
325
|
+
return _plain(r)
|
|
326
|
+
return [table(["commit", "date", "message"], rows)]
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def render_grep(r):
|
|
330
|
+
if r.code != 0:
|
|
331
|
+
return _plain(r)
|
|
332
|
+
rows = parse_grep(r.output)
|
|
333
|
+
if not rows:
|
|
334
|
+
return _plain(r)
|
|
335
|
+
return [table(["file", "line", "match"], rows)]
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def render_find(r):
|
|
339
|
+
if r.code != 0 and not r.output:
|
|
340
|
+
return _plain(r)
|
|
341
|
+
rows, tone = [], []
|
|
342
|
+
for path in r.output.splitlines()[:MAX_ROWS]:
|
|
343
|
+
is_dir = os.path.isdir(os.path.join(r.start_cwd, path))
|
|
344
|
+
rows.append(["folder" if is_dir else "file", path])
|
|
345
|
+
tone.append("accent" if is_dir else None)
|
|
346
|
+
if not rows:
|
|
347
|
+
return text_view(["Nothing found."])
|
|
348
|
+
return [table(["type", "path"], rows, tone)]
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def render_apt(r):
|
|
352
|
+
if r.code != 0:
|
|
353
|
+
return _plain(r)
|
|
354
|
+
rows = parse_apt_upgradable(r.output)
|
|
355
|
+
if not rows:
|
|
356
|
+
return text_view(["Everything is up to date."])
|
|
357
|
+
return [table(["package", "new version", "repo"], rows)]
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def render_failed(r):
|
|
361
|
+
if r.code != 0:
|
|
362
|
+
return _plain(r)
|
|
363
|
+
rows = parse_failed_units(r.output)
|
|
364
|
+
if not rows:
|
|
365
|
+
return text_view(["No failed services."])
|
|
366
|
+
return [table(["unit", "state", "description"], rows, ["warn"] * len(rows))]
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# ---- planning ---------------------------------------------------------------
|
|
370
|
+
|
|
371
|
+
def plan(command):
|
|
372
|
+
"""Return (command_to_run, renderer or None) for a typed command."""
|
|
373
|
+
cmd = command.strip()
|
|
374
|
+
if not cmd or any(ch in cmd for ch in SHELL_OPERATORS):
|
|
375
|
+
return cmd, None
|
|
376
|
+
|
|
377
|
+
parts = cmd.split(maxsplit=1)
|
|
378
|
+
prog = os.path.basename(parts[0])
|
|
379
|
+
rest = parts[1].strip() if len(parts) > 1 else ""
|
|
380
|
+
args = rest.split()
|
|
381
|
+
|
|
382
|
+
if prog == "ls":
|
|
383
|
+
if "--raw" in args:
|
|
384
|
+
return " ".join(["ls"] + [a for a in args if a != "--raw"]), None
|
|
385
|
+
return f"ls -lh --time-style=+%F {rest}".rstrip(), render_ls
|
|
386
|
+
if prog == "df":
|
|
387
|
+
return f"df -h {rest}".rstrip(), render_df
|
|
388
|
+
if prog == "du":
|
|
389
|
+
return f"du -h --max-depth=1 {rest or '.'} 2>/dev/null | sort -rh | head -n 50", render_du
|
|
390
|
+
if prog == "ps" and not args:
|
|
391
|
+
return "ps aux --sort=-%cpu | head -n 26", render_ps
|
|
392
|
+
if prog == "free" and not args:
|
|
393
|
+
return "free -h", render_free
|
|
394
|
+
if prog == "ip" and args in ([], ["a"], ["addr"], ["address"]):
|
|
395
|
+
return "ip -br addr", render_ip
|
|
396
|
+
if prog == "ss" and not args:
|
|
397
|
+
return "ss -tulpn 2>/dev/null", render_ss
|
|
398
|
+
if prog == "git" and args == ["status"]:
|
|
399
|
+
return "git status --porcelain=v1 -b", render_git_status
|
|
400
|
+
if prog == "git" and args == ["log"]:
|
|
401
|
+
return "git log --date=short --pretty=format:%h%x09%ad%x09%s -n 20", render_git_log
|
|
402
|
+
if prog == "cat" and args and not args[0].startswith("-"):
|
|
403
|
+
return f"cat -n {rest}", None
|
|
404
|
+
if prog == "grep" and args:
|
|
405
|
+
return f"grep -n {rest}", render_grep
|
|
406
|
+
if prog == "find":
|
|
407
|
+
return f"find {rest or '.'} 2>/dev/null | head -n {MAX_ROWS}", render_find
|
|
408
|
+
if prog == "apt" and args[:2] == ["list", "--upgradable"]:
|
|
409
|
+
return "apt list --upgradable 2>/dev/null", render_apt
|
|
410
|
+
if prog == "systemctl" and "--failed" in args:
|
|
411
|
+
return "systemctl --failed --no-legend --plain", render_failed
|
|
412
|
+
return cmd, None
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mintterm
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A block-based terminal for Linux, built with pygame. Real bash, with safer and clearer output.
|
|
5
|
+
Author: Your Name
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/YOUR-USER/mintterm
|
|
8
|
+
Project-URL: Issues, https://github.com/YOUR-USER/mintterm/issues
|
|
9
|
+
Keywords: terminal,linux,ubuntu,linux-mint,pygame,shell
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Environment :: X11 Applications
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Topic :: System :: Shells
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pygame>=2.5
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
24
|
+
Requires-Dist: build>=1; extra == "dev"
|
|
25
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<img src="src/mintterm/assets/logo.svg" alt="mintterm" width="420">
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
# mintterm
|
|
33
|
+
|
|
34
|
+
A block-based terminal for Linux, built with pygame. It runs real bash underneath, so every command you know keeps working. Each command and its output become a card, common commands show tables and bars instead of walls of text, and risky commands ask before they touch your files.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
Linux Mint and Ubuntu:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install mintterm
|
|
42
|
+
mintterm
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Windows 11, through WSL:
|
|
46
|
+
|
|
47
|
+
```powershell
|
|
48
|
+
wsl --install
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Open Ubuntu from the Start menu, then run `pip install mintterm` and `mintterm`. Windows 11 shows the window through WSLg with no extra setup. Windows 10 needs an X server such as VcXsrv and is not supported in v0.2.
|
|
52
|
+
|
|
53
|
+
## Commands that look different
|
|
54
|
+
|
|
55
|
+
These run as real commands. mintterm adds flags behind the scenes so the output can be parsed, and you see the output as a table or bars.
|
|
56
|
+
|
|
57
|
+
| You type | You get |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `ls`, `ls ~/Downloads` | Table with size, date, permissions, owner. ▸ folders, * programs, → links |
|
|
60
|
+
| `ls --raw` | Plain `ls` output |
|
|
61
|
+
| `df` | Drives with usage bars. Bars turn red above 85% |
|
|
62
|
+
| `du`, `du ~` | Biggest folders first, with a share bar |
|
|
63
|
+
| `ps` | Top 25 processes by CPU, with bars |
|
|
64
|
+
| `free` | RAM and swap bars |
|
|
65
|
+
| `ip` | Network interfaces with state and addresses |
|
|
66
|
+
| `ss` | Listening ports with the program that owns each one |
|
|
67
|
+
| `git status` | Branch, sync state, and a table of changes |
|
|
68
|
+
| `git log` | Last 20 commits as a table |
|
|
69
|
+
| `grep pattern file` | Matches as a table with file and line |
|
|
70
|
+
| `find ...` | Results as a table, folders highlighted |
|
|
71
|
+
| `apt list --upgradable` | Packages with new versions |
|
|
72
|
+
| `systemctl --failed` | Failed services in red |
|
|
73
|
+
| `cat file` | Numbered lines |
|
|
74
|
+
|
|
75
|
+
Everything else runs exactly as typed, with its output in a card. Cards work for every command: fold, pin, copy, and exit codes.
|
|
76
|
+
|
|
77
|
+
## Built-in features
|
|
78
|
+
|
|
79
|
+
- **Trash and undo.** `rm` moves files into the mintterm trash instead of deleting them. `undo` brings them back. `mv` is recorded too. `rm --really` deletes permanently.
|
|
80
|
+
- **Safety preview.** `rm -rf`, `sudo rm`, `dd`, `mkfs`, and `chmod -R` list what would change and wait for `y`.
|
|
81
|
+
- **`?` helper.** `? find big files`, `? update my system`, or `? explain tar`. It suggests commands but never runs them.
|
|
82
|
+
- **Tab completion.** Completes file and folder names, and lists options when several match.
|
|
83
|
+
- **History search.** Ctrl+R, type part of an old command, press Enter.
|
|
84
|
+
- **Cards.** Click a prompt line to fold a card. Ctrl+P pins a card to the top. Ctrl+Shift+C copies its output (needs `xclip` or `wl-copy`).
|
|
85
|
+
- **Background commands.** The window stays responsive while a command runs. Ctrl+C stops it.
|
|
86
|
+
- **Notifications.** If a command takes longer than 10 seconds and the window is in the background, you get a desktop notification (uses `notify-send`, included in Mint).
|
|
87
|
+
- **Prompt segments and profiles.** Show or hide time, user, host, folder, git branch, Python venv, and exit code. Server profile shows a red prompt so production never looks like your sandbox.
|
|
88
|
+
|
|
89
|
+
## Keys
|
|
90
|
+
|
|
91
|
+
| Key | Action |
|
|
92
|
+
| --- | --- |
|
|
93
|
+
| Enter | Run the command |
|
|
94
|
+
| Up / Down | Command history, or move through search results |
|
|
95
|
+
| Tab | Complete a file or folder name |
|
|
96
|
+
| Ctrl+R | Search history |
|
|
97
|
+
| Ctrl+P | Pin or unpin the selected card |
|
|
98
|
+
| Ctrl+Shift+C | Copy the selected card's output |
|
|
99
|
+
| Ctrl+L or `clear` | Clear the screen |
|
|
100
|
+
| Ctrl+U | Clear the input line |
|
|
101
|
+
| Ctrl+T | Switch to the next theme |
|
|
102
|
+
| Ctrl+C | Stop a running command, or cancel a confirmation |
|
|
103
|
+
| Mouse wheel | Scroll |
|
|
104
|
+
| Esc | Quit (or leave search) |
|
|
105
|
+
|
|
106
|
+
## Settings
|
|
107
|
+
|
|
108
|
+
Type these inside mintterm. Settings save to `~/.config/mintterm/config.json`.
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
set theme sunset mint-dark, mint-light, sunset
|
|
112
|
+
set profile Server Dev, Server, Minimal
|
|
113
|
+
set font 18 10 to 28
|
|
114
|
+
set segments user,host,path time, user, host, path, git, venv, exit
|
|
115
|
+
set notify 10 seconds before a desktop alert (0 = always)
|
|
116
|
+
set show current settings
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Command-line options: `mintterm --theme mint-light` (for this run only), `mintterm --version`, `mintterm --help`.
|
|
120
|
+
|
|
121
|
+
## Limitations in v0.2
|
|
122
|
+
|
|
123
|
+
- Full-screen programs (`vim`, `nano`, `top`, `htop`) do not run inside mintterm. Use `ps` and `free` for the same information.
|
|
124
|
+
- `sudo` asks for a password in the terminal that launched mintterm, not in the window. Run `sudo -v` in your normal terminal first, then `sudo` commands in mintterm work for about 15 minutes.
|
|
125
|
+
- Output appears when a command finishes, not line by line.
|
|
126
|
+
- Only the commands listed above get tables. Others are shown as plain output in cards.
|
|
127
|
+
- Plugins, an SSH manager, widgets and session sharing are planned for later versions.
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
python3 -m venv .venv
|
|
133
|
+
source .venv/bin/activate
|
|
134
|
+
pip install -e ".[dev]"
|
|
135
|
+
pytest
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The parsers, safety checks, trash, and helper have no pygame dependency and are fully tested. The window code is tested by running it against a display.
|
|
139
|
+
|
|
140
|
+
## Publishing to PyPI
|
|
141
|
+
|
|
142
|
+
1. Create an account at pypi.org and an API token under Account settings.
|
|
143
|
+
2. Update `authors` and the URLs in `pyproject.toml`, and bump `version` for each release.
|
|
144
|
+
3. Build and check:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
python -m build
|
|
148
|
+
twine check dist/*
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
4. Test on TestPyPI first:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
twine upload --repository testpypi dist/*
|
|
155
|
+
pip install -i https://test.pypi.org/simple/ mintterm
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
5. Upload to the real index:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
twine upload dist/*
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Username: `__token__`. Password: your `pypi-...` token.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
MIT. See LICENSE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
mintterm/__init__.py,sha256=lqtlKA7isykNWAmp5OrE-feYBWkRcnEOi5btgZVCSw0,73
|
|
2
|
+
mintterm/__main__.py,sha256=dv4kQhPqLI7lwIJQRBUJvaREUtqRmAv5LdTvlMYYuQ8,1081
|
|
3
|
+
mintterm/app.py,sha256=_f6oE1nqdpU53q5gV8eCjVpQb-e5cggvzfeCoNi4xhQ,27703
|
|
4
|
+
mintterm/branding.py,sha256=ZMzC_SSuXNPSc1vvgEZW-D_WGiQvULEOVtpfpLAGlb4,746
|
|
5
|
+
mintterm/clipboard.py,sha256=aHgGLbeZVRfh3frzuWeSqwjOB9d4RE0nOyHEaQfZHdY,549
|
|
6
|
+
mintterm/helper.py,sha256=rsTc0d6ftewOBIqvCDAUU0m2drJkfq46Hof0Li_yaak,6687
|
|
7
|
+
mintterm/prompt.py,sha256=ZGu24RbEzWtFYeEZTWazXnUDQcSSeImczHaJxsVfzCg,1730
|
|
8
|
+
mintterm/render.py,sha256=pgZwPu60NVoe0Bc5qwe_BAeGg7aYl5yDtrlkK9Ggn1s,721
|
|
9
|
+
mintterm/runner.py,sha256=lXzB7p88D2ayUQz7fSZV9hmLmhfsvCAugeXR1GNg7k0,3049
|
|
10
|
+
mintterm/safety.py,sha256=1Y9trmj65u6TUG3OtPXam_fD3YY1nPS3RJl9tiU_ZyA,3088
|
|
11
|
+
mintterm/storage.py,sha256=HZFMoOuzcTG95VLETgIq6L7P3ZlRYX6I6q4QaYo4WlQ,2655
|
|
12
|
+
mintterm/themes.py,sha256=90ZaGRqoJ-J54isv3Vpdfq7xQVtDStubM_Tzblp-7_8,907
|
|
13
|
+
mintterm/trash.py,sha256=y3nZdKo57xtPaM6VSYb07nKHC6BJtidM0wEgCjOYEys,2123
|
|
14
|
+
mintterm/views.py,sha256=xAoLbef_hZ51hVyQoiAJFLc-OWL1hL8jX3EXu7vKeCY,12531
|
|
15
|
+
mintterm/assets/icon.svg,sha256=4bTYmF66iOIgmBxo4bX1Q1jjnEoXwm3qmmj9O0ZY_8A,672
|
|
16
|
+
mintterm/assets/logo.svg,sha256=yj2n6jH26d_y3QB-0qcoTQQbgMH8M-APYiYH7QSvjOc,896
|
|
17
|
+
mintterm-0.2.0.dist-info/licenses/LICENSE,sha256=v2spsd7N1pKFFh2G8wGP_45iwe5S0DYiJzG4im8Rupc,1066
|
|
18
|
+
mintterm-0.2.0.dist-info/METADATA,sha256=aZqtYTtGFFXgLuj3bHZm8Xalj6uCG15_m7jDnMZRNUE,6613
|
|
19
|
+
mintterm-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
20
|
+
mintterm-0.2.0.dist-info/entry_points.txt,sha256=DQvSqm_CYPSPL1vKL1rT8mBkoTW5UqLk3KncUuRpZbo,52
|
|
21
|
+
mintterm-0.2.0.dist-info/top_level.txt,sha256=HdF5LDZQUjA8lhW74nLRO1srUBZf0OSyEh2soxODI6U,9
|
|
22
|
+
mintterm-0.2.0.dist-info/RECORD,,
|