feat: man jonathan replaces the journalctl line
This commit is contained in:
1 parent
f848489ae2
commit
950651c152
3 files changed
+146
-68
No files matched your search
+17
-56
@@ -161,7 +161,21 @@ def vikunja_done(cfg):
|
||||
# ---------------------------------------------------------------- blocks
|
||||
|
||||
|
||||
def terminal_block(cfg, stacks, hosts, journal):
|
||||
def man_block(cfg):
|
||||
"""The about text as a man page: header, sections, footer."""
|
||||
p = cfg["palette"]
|
||||
man = cfg["man"]
|
||||
lines = [f'<span style="color:{p["muted"]}">{man["header"]}</span>']
|
||||
for title, body in man["sections"]:
|
||||
lines.append("")
|
||||
lines.append(f'<span style="color:{p["path"]}">{title}</span>')
|
||||
lines.extend(body)
|
||||
lines.append("")
|
||||
lines.append(f'<span style="color:{p["muted"]}">{man["footer"]}</span>')
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def terminal_block(cfg, stacks, hosts, man):
|
||||
p = cfg["palette"]
|
||||
|
||||
def c(key, text):
|
||||
@@ -185,53 +199,10 @@ def terminal_block(cfg, stacks, hosts, journal):
|
||||
f'{c("muted", f"{i:2d}")} {c("path", f"{hop["name"]:<18}")}'
|
||||
f'{c("muted", f"{a:>7.3f} ms {b:>7.3f} ms {d:>7.3f} ms")}'
|
||||
)
|
||||
lines += ["", f"{prompt} journalctl -u jonathan -n 1 -o cat"]
|
||||
if journal:
|
||||
lines.append(journal)
|
||||
lines += ["", f"{prompt} man jonathan", man]
|
||||
return "<pre>" + "\n".join(lines) + "</pre>"
|
||||
|
||||
|
||||
def current_activity(cfg, tok):
|
||||
"""Newest signal of what he is doing: an open Vikunja task or a real commit."""
|
||||
cands = []
|
||||
vtok = os.environ.get("VIKUNJA_TOKEN", "").strip()
|
||||
if vtok:
|
||||
base = cfg["vikunja"]["base"]
|
||||
for proj in cfg["vikunja"].get("activity_projects", [cfg["vikunja"]["project"]]):
|
||||
try:
|
||||
tasks = http_json(
|
||||
f"{base}/api/v1/projects/{proj}/tasks?per_page=100",
|
||||
headers={"Authorization": "Bearer " + vtok},
|
||||
)
|
||||
except Exception:
|
||||
continue
|
||||
for t in tasks:
|
||||
if not t.get("done") and t.get("updated"):
|
||||
cands.append((t["updated"], t["title"]))
|
||||
for name in cfg["featured_repos"]:
|
||||
try:
|
||||
commits = gitea(f"/repos/jblu/{name}/commits?limit=5&stat=false", tok)
|
||||
except Exception:
|
||||
continue
|
||||
for c in commits:
|
||||
msg = c["commit"]["message"].strip()
|
||||
if msg.startswith(("Merge pull request", "Merge PR", "chore: refresh profile README")):
|
||||
continue # merges duplicate the PR block; the refresh is self-referential
|
||||
cands.append((c["commit"]["author"]["date"], msg.splitlines()[0]))
|
||||
if not cands:
|
||||
return None
|
||||
cands.sort(key=lambda x: x[0], reverse=True)
|
||||
return cands[0]
|
||||
|
||||
|
||||
def journal_line(cfg, activity):
|
||||
"""`-o cat` prints the message only, so the line fits the card without wrapping."""
|
||||
if not activity:
|
||||
return ""
|
||||
_, msg = activity
|
||||
return one_line(msg, 70)
|
||||
|
||||
|
||||
def status_block(cfg, up, total):
|
||||
p = cfg["palette"]
|
||||
ok = up == total
|
||||
@@ -327,17 +298,7 @@ def build():
|
||||
if hosts is None:
|
||||
hosts = previous_int(text, r"up (\d+) hosts")
|
||||
|
||||
activity = None
|
||||
try:
|
||||
activity = current_activity(cfg, tok)
|
||||
except Exception as exc:
|
||||
errors.append(f"activity: {type(exc).__name__}: {exc}")
|
||||
if activity is None:
|
||||
# no signal at all: keep the previous card rather than print a stale lie
|
||||
errors.append("activity: no signal, keeping the previous terminal card")
|
||||
else:
|
||||
journal = journal_line(cfg, activity)
|
||||
apply("terminal", lambda: terminal_block(cfg, stacks, hosts, journal))
|
||||
apply("terminal", lambda: terminal_block(cfg, stacks, hosts, man_block(cfg)))
|
||||
|
||||
try:
|
||||
up, total = kuma_counts(cfg)
|
||||
|
||||
Reference in new issue
Block a user