diff --git a/README.md b/README.md index 23757a6..219d4e5 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ includes the explicit backgrounds used for consistent terminal rendering. Each independent local root session gets its own metrics and 30-second graph; explicitly linked spawned agents are included with their root. Terminal session telemetry boxes keep their proportional width on narrow - screens but cap at 48 columns, leaving extra width for detail and graphs. + screens but cap at 40 columns, leaving extra width for detail and graphs. - Dismissible session rows that automatically return on fresh activity, without closing or modifying the underlying Codex session. - Highlighted per-session attention badges. A shared Codex app-server supplies @@ -598,6 +598,7 @@ codexometer --codex /path/to/codex | `z` | Zero the Sessions baseline | | `s` | Open Benchmark Scope (Benchmark view only) | | `o` | Close All session rows; strict confirmation mode adds a second press, with `Esc` to cancel | +| `k` | Clear the matching Check* session rows; strict confirmation mode adds a second press | | `g` | Cycle available trend periods in Quota → Pace | | `h` | Toggle the trace in Quota → Pace | | `y` | Cycle all listed Sessions rows: first match the most detailed row, then graph → split → wide → graph; never opens full detail | @@ -1211,10 +1212,12 @@ The other top-level views are: parent sessions and are not counted again. Tokens retain the existing measurement baseline (including previously dismissed sessions); the session/state counts describe currently visible rows. Elapsed time and average rate - remain underneath when space permits; clickable Zero and Close All controls - sit beside it, labelled `(Z)ERO` and `CL(O)SE ALL`. Close All dismisses - every visible session row, including those outside the current page, while - keeping the measurement baseline and telemetry. + remain underneath when space permits. Beside the summary, `(Z)ERO` resets the + measurement baseline, the two-line `CL(O)SE ALL` dismisses all matching rows, and + `CLEAR CHEC(K)` dismisses only matching rows flagged for inferred inactivity. + Both dismissal actions include off-page matches, leave Codex sessions running, + and keep measurement history. On very narrow terminals, use `k` when the + Clear Check button does not fit. Account-wide quota details live in Quota, not Sessions. During unavailable observation, live state counts show **—**, not zero. Active sessions are checked once per second and the idle cadence relaxes to five seconds. @@ -1320,6 +1323,9 @@ The other top-level views are: cancels. Changed visible rows require fresh confirmation; switching views or Zero cancels an armed action. Close All is disabled when no rows are visible. + Clear Check uses the same confirmation setting and leaves working, approval, + input, error and completed rows alone, including pending quota-profile reviews. + A dismissed Check* row comes back when new activity or a new alert is observed. When the terminal cannot fit every root, use Page Up, Page Down, or the mouse wheel to page through the rows. - **Benchmark** — runs the selected scope from the active Core, Extended, or @@ -1752,9 +1758,17 @@ Usable Sessions and Benchmark Copy buttons match their panel border colour at re highlight on hover, and flash briefly on click or `C`. An unavailable Benchmark matrix Copy button remains dim. Translations embed the shortcut where the word starts with C; otherwise they retain a separate `(C)` before the label. +Ordinary Sessions border controls also use the border colour at rest; disabled +navigation is dim, and approval warnings keep their warning colour. Copy exports the complete sanitized text available in the bounded session preview, not an unlimited transcript: it cannot recover text omitted by observation limits. Clipboard contents then follow your terminal and operating system's retention behaviour. +In terminal Sessions detail (split, expanded, or full), drag across visible +output to copy just that selection as plain text, with on-screen line breaks. +The selection flashes briefly and a centred badge at the bottom of the footer +shows how many characters were copied for five seconds. On narrow terminals it +uses the footer row above the shortcuts. A normal click still follows its usual +action. When Codex marks an answer as hidden, blocked, or requiring a native display that Codexometer cannot provide, Sessions shows **View this reply in Codex.** The terminal, history, Copy, and read-only web view use that notice in the @@ -1812,8 +1826,8 @@ the other categories; the counts are not separate parts to add together. The summary counts and token totals remain global, excluding dismissed sessions from state counts but retaining their measured tokens. Attention pills stay available across filters; opening an excluded session clears the filter to keep -its row accessible. **Close All** only dismisses matching, non-dismissed sessions; -`--confirmation require` adds confirmation. Filtering never stops telemetry +its row accessible. **Close All** and **Clear Check** only dismiss matching, +non-dismissed sessions; `--confirmation require` adds confirmation. Filtering never stops telemetry collection or changes the Zero baseline. Dismissed sessions are skipped, and Down is disabled at the last matching session. These up/down session-selection buttons disappear in full detail, where Up/Down scroll the text. diff --git a/assets/screenshots/approval.png b/assets/screenshots/approval.png index 9f35d67..8598757 100644 Binary files a/assets/screenshots/approval.png and b/assets/screenshots/approval.png differ diff --git a/assets/screenshots/manifest.json b/assets/screenshots/manifest.json index 090d3f8..c41647d 100644 --- a/assets/screenshots/manifest.json +++ b/assets/screenshots/manifest.json @@ -14,8 +14,8 @@ "caption": "Session detail: synthetic commentary, the exact command to review, and explicit approval controls.", "columns": 136, "rows": 35, - "frameSHA256": "d510a03e867ce2361878241a348dd3ea9598f0f2fcf1173514803befe3d052de", - "pngSHA256": "dc05f2bde7d24eee056754c492b180a31ce6b260e782044cee784ce90268eb91" + "frameSHA256": "7362de6b22d502965da958675078a7e703804bc5466a98d7d633f345beffa8a8", + "pngSHA256": "9912cc85bf04154ffec7c046b67ed6d10c7a9a2e719696c2e0125d88d4c70bea" }, { "file": "benchmark.png", @@ -54,8 +54,8 @@ "caption": "Sessions command centre: three synthetic sessions, live activity and an approval awaiting review.", "columns": 136, "rows": 45, - "frameSHA256": "88ed9e35c47368824709e4802e3f472b50008d46b672f04e85ca2177af2c63d3", - "pngSHA256": "7603782bb3a1628b714cecade418cef6c5cb34aaa9011b57c07b6b4448abdc53" + "frameSHA256": "77ec1df63beeb9435b59517ec198875655a259a3fb41fbd58e1410f30cf950a0", + "pngSHA256": "f7d0cb77b3425eafd6ea33f485569c678aabe0ea2655e84c0edf757b14529eb6" }, { "file": "usage.png", diff --git a/assets/screenshots/sessions.png b/assets/screenshots/sessions.png index 54b2569..2fafe5f 100644 Binary files a/assets/screenshots/sessions.png and b/assets/screenshots/sessions.png differ diff --git a/internal/i18n/locales/da.json b/internal/i18n/locales/da.json index 3400b7f..9230288 100644 --- a/internal/i18n/locales/da.json +++ b/internal/i18n/locales/da.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "RYD TJEK (K)", + "CONFIRM (K)": "BEKRÆFT (K)", + "Copied %d chars": "Kopierede %d tegn", "LINKS": "LINKS", "SESSION PREVIEW": "FORHÅNDSVISNING AF SESSION", "OPEN SESSION": "ÅBN SESSION", @@ -394,7 +397,7 @@ "QUOTA WATCH": "HOLD ØJE MED KVOTEN", "RANK": "RANG", "AVG TOK/MIN ": "GNS. TOK/MIN ", - "CL(O)SE ALL": "LUK ALLE (O)", + "CL(O)SE\nALL": "LUK\nALLE (O)", "C(O)NFIRM": "BEKRÆFT (O)", "(Z)ERO": "NULSTIL (Z)", "READY": "KLAR", diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index 343b6ee..32d6baf 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "PRÜFFÄLLE AUSBLENDEN (K)", + "CONFIRM (K)": "BESTÄTIGEN (K)", + "Copied %d chars": "%d Zeichen kopiert", "LINKS": "LINKS", "SESSION PREVIEW": "SITZUNGSVORSCHAU", "OPEN SESSION": "SITZUNG ÖFFNEN", @@ -394,7 +397,7 @@ "QUOTA WATCH": "KONTINGENT BEACHTEN", "RANK": "RANG", "AVG TOK/MIN ": "Ø TOK/MIN ", - "CL(O)SE ALL": "ALLE SCHLIESSEN (O)", + "CL(O)SE\nALL": "ALLE (O)\nSCHLIESSEN", "C(O)NFIRM": "BESTÄTIGEN (O)", "(Z)ERO": "NULLEN (Z)", "READY": "BEREIT", diff --git a/internal/i18n/locales/en-GB.json b/internal/i18n/locales/en-GB.json index 3dd72b7..2addf24 100644 --- a/internal/i18n/locales/en-GB.json +++ b/internal/i18n/locales/en-GB.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "CLEAR CHEC(K)", + "CONFIRM (K)": "CONFIRM (K)", + "Copied %d chars": "Copied %d chars", "LINKS": "LINKS", "SESSION PREVIEW": "SESSION PREVIEW", "OPEN SESSION": "OPEN SESSION", @@ -394,7 +397,7 @@ "QUOTA WATCH": "QUOTA WATCH", "RANK": "RANK", "AVG TOK/MIN ": "AVG TOK/MIN ", - "CL(O)SE ALL": "CL(O)SE ALL", + "CL(O)SE\nALL": "CL(O)SE\nALL", "C(O)NFIRM": "C(O)NFIRM", "(Z)ERO": "(Z)ERO", "READY": "READY", diff --git a/internal/i18n/locales/es.json b/internal/i18n/locales/es.json index d775645..7de74b7 100644 --- a/internal/i18n/locales/es.json +++ b/internal/i18n/locales/es.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "OCULTAR REVISIÓN (K)", + "CONFIRM (K)": "CONFIRMAR (K)", + "Copied %d chars": "%d caracteres copiados", "LINKS": "ENLACES", "SESSION PREVIEW": "VISTA PREVIA DE SESIÓN", "OPEN SESSION": "ABRIR SESIÓN", @@ -394,7 +397,7 @@ "QUOTA WATCH": "VIGILAR CUOTA", "RANK": "POSICIÓN", "AVG TOK/MIN ": "PROM. TOK/MIN ", - "CL(O)SE ALL": "CERRAR TODO (O)", + "CL(O)SE\nALL": "CERRAR\nTODO (O)", "C(O)NFIRM": "CONFIRMAR (O)", "(Z)ERO": "PONER A CERO (Z)", "READY": "LISTO", diff --git a/internal/i18n/locales/et.json b/internal/i18n/locales/et.json index 53d87b1..3522bed 100644 --- a/internal/i18n/locales/et.json +++ b/internal/i18n/locales/et.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "PEIDA KONTROLL (K)", + "CONFIRM (K)": "KINNITA (K)", + "Copied %d chars": "Kopeeriti %d märki", "LINKS": "LINGID", "SESSION PREVIEW": "SEANSI EELVAADE", "OPEN SESSION": "AVA SEANSS", @@ -394,7 +397,7 @@ "QUOTA WATCH": "JÄLGI KVOOTI", "RANK": "KOHT", "AVG TOK/MIN ": "KESK. TOK/MIN ", - "CL(O)SE ALL": "SULGE KÕIK (O)", + "CL(O)SE\nALL": "SULGE\nKÕIK (O)", "C(O)NFIRM": "KINNITA (O)", "(Z)ERO": "NULLI (Z)", "READY": "VALMIS", diff --git a/internal/i18n/locales/fi.json b/internal/i18n/locales/fi.json index 69541ac..9ebf47e 100644 --- a/internal/i18n/locales/fi.json +++ b/internal/i18n/locales/fi.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "PIILOTA TARKISTA (K)", + "CONFIRM (K)": "VAHVISTA (K)", + "Copied %d chars": "Kopioitu %d merkkiä", "LINKS": "LINKIT", "SESSION PREVIEW": "ISTUNNON ESIKATSELU", "OPEN SESSION": "AVAA ISTUNTO", @@ -394,7 +397,7 @@ "QUOTA WATCH": "SEURAA KIINTIÖTÄ", "RANK": "SIJA", "AVG TOK/MIN ": "KESKIM. TOK/MIN ", - "CL(O)SE ALL": "SULJE KAIKKI (O)", + "CL(O)SE\nALL": "SULJE\nKAIKKI (O)", "C(O)NFIRM": "VAHVISTA (O)", "(Z)ERO": "NOLLAA (Z)", "READY": "VALMIS", diff --git a/internal/i18n/locales/fr.json b/internal/i18n/locales/fr.json index 7624aa3..d63c8a5 100644 --- a/internal/i18n/locales/fr.json +++ b/internal/i18n/locales/fr.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "MASQUER À VÉRIFIER (K)", + "CONFIRM (K)": "CONFIRMER (K)", + "Copied %d chars": "%d caractères copiés", "LINKS": "LIENS", "SESSION PREVIEW": "APERÇU DE SESSION", "OPEN SESSION": "OUVRIR LA SESSION", @@ -394,7 +397,7 @@ "QUOTA WATCH": "QUOTA À SURVEILLER", "RANK": "CLASSEMENT", "AVG TOK/MIN ": "MOY. TOK/MIN ", - "CL(O)SE ALL": "TOUT FERMER (O)", + "CL(O)SE\nALL": "TOUT\nFERMER (O)", "C(O)NFIRM": "CONFIRMER (O)", "(Z)ERO": "REMISE À ZÉRO (Z)", "READY": "PRÊT", diff --git a/internal/i18n/locales/it.json b/internal/i18n/locales/it.json index 29c39b3..3773a54 100644 --- a/internal/i18n/locales/it.json +++ b/internal/i18n/locales/it.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "NASCONDI VERIFICA (K)", + "CONFIRM (K)": "CONFERMA (K)", + "Copied %d chars": "%d caratteri copiati", "LINKS": "LINK", "SESSION PREVIEW": "ANTEPRIMA DELLA SESSIONE", "OPEN SESSION": "APRI SESSIONE", @@ -394,7 +397,7 @@ "QUOTA WATCH": "ATTENZIONE ALLA QUOTA", "RANK": "POSIZIONE", "AVG TOK/MIN ": "MEDIA TOK/MIN ", - "CL(O)SE ALL": "CHIUDI TUTTO (O)", + "CL(O)SE\nALL": "CHIUDI\nTUTTO (O)", "C(O)NFIRM": "CONFERMA (O)", "(Z)ERO": "AZZERA (Z)", "READY": "PRONTO", diff --git a/internal/i18n/locales/ja.json b/internal/i18n/locales/ja.json index 16c17a8..21f6347 100644 --- a/internal/i18n/locales/ja.json +++ b/internal/i18n/locales/ja.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "要確認を非表示 (K)", + "CONFIRM (K)": "確認 (K)", + "Copied %d chars": "%d 文字をコピーしました", "LINKS": "リンク", "SESSION PREVIEW": "セッションのプレビュー", "OPEN SESSION": "セッションを開く", @@ -394,7 +397,7 @@ "QUOTA WATCH": "利用枠に注意", "RANK": "順位", "AVG TOK/MIN ": "平均トークン/分 ", - "CL(O)SE ALL": "すべて閉じる (O)", + "CL(O)SE\nALL": "すべて\n閉じる (O)", "C(O)NFIRM": "確認 (O)", "(Z)ERO": "ゼロにする (Z)", "READY": "準備完了", diff --git a/internal/i18n/locales/nb.json b/internal/i18n/locales/nb.json index e9efa6a..561fd52 100644 --- a/internal/i18n/locales/nb.json +++ b/internal/i18n/locales/nb.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "SKJUL SJEKK (K)", + "CONFIRM (K)": "BEKREFT (K)", + "Copied %d chars": "Kopierte %d tegn", "LINKS": "LENKER", "SESSION PREVIEW": "FORHÅNDSVISNING AV ØKT", "OPEN SESSION": "ÅPNE ØKT", @@ -394,7 +397,7 @@ "QUOTA WATCH": "FØLG MED PÅ KVOTEN", "RANK": "RANGERING", "AVG TOK/MIN ": "SNITT TOK/MIN ", - "CL(O)SE ALL": "LUKK ALLE (O)", + "CL(O)SE\nALL": "LUKK\nALLE (O)", "C(O)NFIRM": "BEKREFT (O)", "(Z)ERO": "NULLSTILL (Z)", "READY": "KLAR", diff --git a/internal/i18n/locales/nl.json b/internal/i18n/locales/nl.json index 49445a3..e5d974c 100644 --- a/internal/i18n/locales/nl.json +++ b/internal/i18n/locales/nl.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "CONTROLE VERBERGEN (K)", + "CONFIRM (K)": "BEVESTIGEN (K)", + "Copied %d chars": "%d tekens gekopieerd", "LINKS": "LINKS", "SESSION PREVIEW": "SESSIEVOORBEELD", "OPEN SESSION": "SESSIE OPENEN", @@ -394,7 +397,7 @@ "QUOTA WATCH": "LET OP QUOTUM", "RANK": "RANG", "AVG TOK/MIN ": "GEM. TOK/MIN ", - "CL(O)SE ALL": "ALLES SLUITEN (O)", + "CL(O)SE\nALL": "ALLES\nSLUITEN (O)", "C(O)NFIRM": "BEVESTIG (O)", "(Z)ERO": "NULSTELLEN (Z)", "READY": "GEREED", diff --git a/internal/i18n/locales/pt-BR.json b/internal/i18n/locales/pt-BR.json index 1e4c7da..a35186d 100644 --- a/internal/i18n/locales/pt-BR.json +++ b/internal/i18n/locales/pt-BR.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "OCULTAR VERIFICAR (K)", + "CONFIRM (K)": "CONFIRMAR (K)", + "Copied %d chars": "%d caracteres copiados", "LINKS": "LINKS", "SESSION PREVIEW": "PRÉVIA DA SESSÃO", "OPEN SESSION": "ABRIR SESSÃO", @@ -394,7 +397,7 @@ "QUOTA WATCH": "ATENÇÃO À COTA", "RANK": "RANKING", "AVG TOK/MIN ": "MÉDIA TOK/MIN ", - "CL(O)SE ALL": "FECHAR TUDO (O)", + "CL(O)SE\nALL": "FECHAR\nTUDO (O)", "C(O)NFIRM": "CONFIRMAR (O)", "(Z)ERO": "ZERAR (Z)", "READY": "PRONTO", diff --git a/internal/i18n/locales/pt-PT.json b/internal/i18n/locales/pt-PT.json index 5e52ac2..4a37afd 100644 --- a/internal/i18n/locales/pt-PT.json +++ b/internal/i18n/locales/pt-PT.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "OCULTAR VERIFICAR (K)", + "CONFIRM (K)": "CONFIRMAR (K)", + "Copied %d chars": "%d caracteres copiados", "LINKS": "LIGAÇÕES", "SESSION PREVIEW": "PRÉ-VISUALIZAÇÃO DA SESSÃO", "OPEN SESSION": "ABRIR SESSÃO", @@ -394,7 +397,7 @@ "QUOTA WATCH": "ATENÇÃO À QUOTA", "RANK": "RANKING", "AVG TOK/MIN ": "MÉDIA TOK/MIN ", - "CL(O)SE ALL": "FECHAR TUDO (O)", + "CL(O)SE\nALL": "FECHAR\nTUDO (O)", "C(O)NFIRM": "CONFIRMAR (O)", "(Z)ERO": "ZERAR (Z)", "READY": "PRONTO", diff --git a/internal/i18n/locales/ru.json b/internal/i18n/locales/ru.json index ee5e797..bb88bf9 100644 --- a/internal/i18n/locales/ru.json +++ b/internal/i18n/locales/ru.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "СКРЫТЬ ПРОВЕРКУ (K)", + "CONFIRM (K)": "ПОДТВЕРДИТЬ (K)", + "Copied %d chars": "Скопировано символов: %d", "LINKS": "ССЫЛКИ", "SESSION PREVIEW": "ПРОСМОТР СЕАНСА", "OPEN SESSION": "ОТКРЫТЬ СЕАНС", @@ -394,7 +397,7 @@ "QUOTA WATCH": "СЛЕДИТЕ ЗА КВОТОЙ", "RANK": "РАНГ", "AVG TOK/MIN ": "СР. ТОК/МИН ", - "CL(O)SE ALL": "ЗАКРЫТЬ ВСЕ (O)", + "CL(O)SE\nALL": "ЗАКРЫТЬ\nВСЕ (O)", "C(O)NFIRM": "ПОДТВЕРДИТЬ (O)", "(Z)ERO": "ОБНУЛИТЬ (Z)", "READY": "ГОТОВО", diff --git a/internal/i18n/locales/sv.json b/internal/i18n/locales/sv.json index 81c2db4..45a4bf7 100644 --- a/internal/i18n/locales/sv.json +++ b/internal/i18n/locales/sv.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "DÖLJ KOLLA (K)", + "CONFIRM (K)": "BEKRÄFTA (K)", + "Copied %d chars": "Kopierade %d tecken", "LINKS": "LÄNKAR", "SESSION PREVIEW": "FÖRHANDSVISNING AV SESSION", "OPEN SESSION": "ÖPPNA SESSION", @@ -394,7 +397,7 @@ "QUOTA WATCH": "BEVAKA KVOTEN", "RANK": "RANG", "AVG TOK/MIN ": "SNITT TOK/MIN ", - "CL(O)SE ALL": "STÄNG ALLA (O)", + "CL(O)SE\nALL": "STÄNG\nALLA (O)", "C(O)NFIRM": "BEKRÄFTA (O)", "(Z)ERO": "NOLLSTÄLL (Z)", "READY": "REDO", diff --git a/internal/i18n/locales/tr.json b/internal/i18n/locales/tr.json index f7fa26c..265384c 100644 --- a/internal/i18n/locales/tr.json +++ b/internal/i18n/locales/tr.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "KONTROL GİZLE (K)", + "CONFIRM (K)": "ONAYLA (K)", + "Copied %d chars": "%d karakter kopyalandı", "LINKS": "BAĞLANTILAR", "SESSION PREVIEW": "OTURUM ÖNİZLEMESİ", "OPEN SESSION": "OTURUMU AÇ", @@ -394,7 +397,7 @@ "QUOTA WATCH": "KOTAYI İZLE", "RANK": "SIRA", "AVG TOK/MIN ": "ORT. TOK/DK ", - "CL(O)SE ALL": "TÜMÜNÜ KAPAT (O)", + "CL(O)SE\nALL": "TÜMÜNÜ\nKAPAT (O)", "C(O)NFIRM": "ONAYLA (O)", "(Z)ERO": "SAYACI SIFIRLA (Z)", "READY": "HAZIR", diff --git a/internal/i18n/locales/zh-Hans.json b/internal/i18n/locales/zh-Hans.json index 52c83c1..837c0fb 100644 --- a/internal/i18n/locales/zh-Hans.json +++ b/internal/i18n/locales/zh-Hans.json @@ -1,4 +1,7 @@ { + "CLEAR CHEC(K)": "隐藏待检查 (K)", + "CONFIRM (K)": "确认 (K)", + "Copied %d chars": "已复制 %d 个字符", "LINKS": "链接", "SESSION PREVIEW": "会话预览", "OPEN SESSION": "打开会话", @@ -394,7 +397,7 @@ "QUOTA WATCH": "关注配额", "RANK": "排名", "AVG TOK/MIN ": "平均令牌/分钟 ", - "CL(O)SE ALL": "全部关闭 (O)", + "CL(O)SE\nALL": "全部\n关闭 (O)", "C(O)NFIRM": "确认 (O)", "(Z)ERO": "归零 (Z)", "READY": "就绪", diff --git a/internal/ui/english_snapshot_test.go b/internal/ui/english_snapshot_test.go index 211b981..0b413cd 100644 --- a/internal/ui/english_snapshot_test.go +++ b/internal/ui/english_snapshot_test.go @@ -37,12 +37,14 @@ func TestEnglishPresentationSnapshot(t *testing.T) { } got := fmt.Sprintf("%x", hash.Sum(nil)) // Baseline includes Pace graph controls, explicit panel/border - // backgrounds, Sessions Zero/Close All, ACTIVE/ERRORS categories and responsive - // summary filters and Sessions finder button. Refresh no longer occupies + // backgrounds, Sessions Zero/Close All/Clear Check, ACTIVE/ERRORS categories + // and responsive summary filters and Sessions finder button. Refresh no longer occupies // the Sessions footer. Every theme, view and size remains covered. // Pie labels usage and the reset ring without a horizontal reset bar. // The displayed pricing review date is now 2026-11-17. - const want = "034bbb1b4ece977142f93978ee5a8d19f34b5ecbf4bd3866c468ab19aceeac10" + // Sessions header buttons share one width; Close All takes two lines. + // Sessions border navigation uses the primary theme colour at rest. + const want = "c7bd1cbf3b9c4ccdfe94c92e8210d469f88fe1b0fe22116cad0a70e4ca105a13" if got != want { t.Fatalf("English presentation changed: got %s, want %s", got, want) } diff --git a/internal/ui/model.go b/internal/ui/model.go index a5aaf97..84315e8 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -71,6 +71,9 @@ type Model struct { monitorReadIntent string monitorReadDwell monitorReadDwell monitorReadBusy bool + monitorSelection *monitorTextSelection + monitorSelectionSequence uint64 + monitorSelectionCopied int monitorHistory map[string]monitorTurnHistory monitorHistorySequence uint64 monitorAttentionPage int @@ -220,6 +223,7 @@ type Model struct { monitorCopySequence uint64 monitorDismissSeq uint64 monitorCloseAllConfirm []string + monitorCheckOnly bool monitorCloseAllUntil time.Time monitorScroll int monitorError string @@ -400,6 +404,7 @@ const ( footerButtonQuit footerButtonMonitorReset footerButtonMonitorCloseAll + footerButtonMonitorClearCheck footerButtonMonitorNew footerButtonBenchmarkPrevious footerButtonBenchmarkNext @@ -654,23 +659,30 @@ func (m Model) update(message tea.Msg) (tea.Model, tea.Cmd) { return m, nil } if m.meterView == viewMonitor { - if m.monitorFilterKey(strings.ToLower(message.String())) { + keyName := strings.ToLower(message.String()) + if m.monitorFilterKey(keyName) { return m, nil } - if strings.EqualFold(message.String(), "o") { - if !message.IsRepeat && m.monitorContextDetail == "" && m.monitorCloseAllEnabled() { - return m.pressFooterButton(footerButtonMonitorCloseAll) + if keyName == "o" || keyName == "k" { + if !message.IsRepeat && m.monitorContextDetail == "" { + button, enabled := footerButtonMonitorCloseAll, m.monitorCloseAllEnabled() + if keyName == "k" { + button, enabled = footerButtonMonitorClearCheck, m.monitorClearCheckEnabled() + } + if enabled { + return m.pressFooterButton(button) + } } return m, nil } - if strings.EqualFold(message.String(), "n") && !message.IsRepeat && m.monitorContextDetail == "" && !m.monitorPrompt.input.Focused() { + if keyName == "n" && !message.IsRepeat && m.monitorContextDetail == "" && !m.monitorPrompt.input.Focused() { return m.pressFooterButton(footerButtonMonitorNew) } - if message.String() == "esc" && len(m.monitorCloseAllConfirm) > 0 { + if keyName == "esc" && len(m.monitorCloseAllConfirm) > 0 { m.clearMonitorCloseAllConfirmation() return m, nil } - next, cmd, handled := m.updateMonitorContextKey(strings.ToLower(message.String())) + next, cmd, handled := m.updateMonitorContextKey(keyName) m = next if handled { return next, cmd @@ -1479,6 +1491,10 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { if m.meterView == viewMonitor && m.monitorCloseAllEnabled() { m.requestMonitorCloseAll() } + case footerButtonMonitorClearCheck: + if m.meterView == viewMonitor && m.monitorContextDetail == "" && m.monitorClearCheckEnabled() { + m.requestMonitorBulkDismiss(true) + } case footerButtonMonitorNew: if m.meterView == viewMonitor { cmd := m.openNewSession() @@ -2725,11 +2741,16 @@ func (m *Model) dismissMonitorSession(id string) { if index < 0 { return } + m.recordMonitorDismissal(m.monitorSessionData[index]) + m.monitorSessions = m.visibleMonitorSessionCount() + m.scrollMonitorRows(0) +} + +func (m *Model) recordMonitorDismissal(session monitorSession) { if m.monitorDismissed == nil { m.monitorDismissed = make(map[string]monitorSessionDismissal) } - session := m.monitorSessionData[index] - m.monitorDismissed[id] = monitorSessionDismissal{ + m.monitorDismissed[session.id] = monitorSessionDismissal{ latest: session.latest, lastActivity: session.lastActivity, callSequence: session.callSequence, @@ -2737,9 +2758,6 @@ func (m *Model) dismissMonitorSession(id string) { attention: session.attention, preview: session.preview, } - m.monitorSessions = m.visibleMonitorSessionCount() - maximumScroll := max(m.monitorListSessionCount()-m.monitorPageSize(), 0) - m.monitorScroll = min(m.monitorScroll, maximumScroll) } // Dismiss the whole list, including rows outside the current page. Retain diff --git a/internal/ui/monitor.go b/internal/ui/monitor.go index d66cf78..5349b59 100644 --- a/internal/ui/monitor.go +++ b/internal/ui/monitor.go @@ -32,18 +32,19 @@ type monitorView struct { } type monitorGeometry struct { - attention []monitorNavigationButton - attentionRows int - finderRows int - width int - height int - gap int - topHeight int - graphHeight int - readoutWidth int - resetRect monitorRect - closeAllRect monitorRect - newRect monitorRect + attention []monitorNavigationButton + attentionRows int + finderRows int + width int + height int + gap int + topHeight int + graphHeight int + readoutWidth int + resetRect monitorRect + closeAllRect monitorRect + clearCheckRect monitorRect + newRect monitorRect } const monitorDismissLabel = "[×]" @@ -58,36 +59,52 @@ func layoutMonitorArea(width, height int, newButton ...bool) monitorGeometry { } graphHeight := max(height-topHeight-gap, 1) - // Keep the summary usable on narrow terminals; compact both controls when - // their full translated labels cannot fit. + // Fit the full group only when its shortcut labels have room. On very + // narrow terminals keep the existing controls and leave Clear Check on K. controlsWidth := min(max(width/4, 22), max(width*2/5, 3)) - newWidth := 0 - if len(newButton) > 0 && newButton[0] && width >= 27 { - total := min(max(width/3, 30), max(width/2, 13)) - newWidth = max((total-2*gap)/3, 1) - controlsWidth = total - newWidth - gap - } - resetWidth := max((controlsWidth-gap)/2, 1) - closeAllWidth := max(controlsWidth-resetWidth-gap, 1) - readoutWidth := max(width-controlsWidth-gap, 1) - if newWidth > 0 { - readoutWidth -= newWidth + gap + showNew := len(newButton) > 0 && newButton[0] && width >= 27 + showClear := width >= 43 && (!showNew || width >= 46) + count := 2 + if showClear { + count++ + controlsWidth = min(max(width/3+5, 34), width*2/5) + } + if showNew { + count++ + controlsWidth = min(max(width/3, 30), width/2) + if showClear { + controlsWidth = min(max(width*2/5, 42), width/2) + } } + buttonWidth := max((controlsWidth-(count-1)*gap)/count, 1) + // Give spare cells to the readout rather than widening individual buttons. + readoutWidth := max(width-count*(buttonWidth+gap), 1) if height >= 12 { topHeight = min(monitorSummaryHeight(readoutWidth), height-7) graphHeight = max(height-topHeight-gap, 1) } - return monitorGeometry{ + a := monitorGeometry{ width: width, height: height, gap: gap, topHeight: topHeight, graphHeight: graphHeight, readoutWidth: readoutWidth, - resetRect: monitorRect{x: readoutWidth + gap, width: resetWidth, height: topHeight}, - closeAllRect: monitorRect{x: readoutWidth + gap + resetWidth + gap, width: closeAllWidth, height: topHeight}, - newRect: monitorRect{x: width - newWidth, width: newWidth, height: topHeight}, } + x := readoutWidth + gap + next := func() monitorRect { + r := monitorRect{x: x, width: buttonWidth, height: topHeight} + x += buttonWidth + gap + return r + } + a.resetRect, a.closeAllRect = next(), next() + if showClear { + a.clearCheckRect = next() + } + if showNew { + a.newRect = next() + } + return a } func (m Model) renderMonitorArea(width, height int, colors palette) monitorView { @@ -121,39 +138,26 @@ func (m Model) renderMonitorArea(width, height int, colors palette) monitorView layout := m.monitorArea(width, height) readout := m.renderMonitorReadout(layout.readoutWidth, layout.topHeight, colors) - resetLabel := i18n.Text("(Z)ERO") - if layout.resetRect.width < lipgloss.Width(resetLabel)+2 { - resetLabel = "0 (Z)" - if layout.resetRect.width < lipgloss.Width(resetLabel)+2 { - resetLabel = "0\n(Z)" - } - } + resetLabel := fitMonitorButtonLabel(layout.resetRect, i18n.Text("(Z)ERO"), "0 (Z)", "0\n(Z)", "(Z)", "Z") resetButton := m.renderMonitorButton(layout.resetRect.width, layout.topHeight, resetLabel, footerButtonMonitorReset, m.monitorResetEnabled(), colors) - closeAllLabel := i18n.Text("CL(O)SE ALL") - if layout.closeAllRect.width < lipgloss.Width(closeAllLabel)+2 { - wrapped := strings.Replace(closeAllLabel, " ", "\n", 1) - if lipgloss.Width(wrapped)+2 <= layout.closeAllRect.width && lipgloss.Height(wrapped)+2 <= layout.topHeight { - closeAllLabel = wrapped - } else { - closeAllLabel = "[××]\n(O)" - } - } + closeAllLabel := fitMonitorButtonLabel(layout.closeAllRect, i18n.Text("CL(O)SE\nALL"), "[××]\n(O)", "××\n(O)", "×\nO", "(O)", "O") if m.monitorCloseAllArmed() { - closeAllLabel = i18n.Text("C(O)NFIRM") + "\nEsc" - if layout.closeAllRect.width < lipgloss.Width(i18n.Text("C(O)NFIRM"))+2 { - closeAllLabel = "(O)?\nEsc" - } + closeAllLabel = fitMonitorButtonLabel(layout.closeAllRect, i18n.Text("C(O)NFIRM")+"\nEsc", "(O)?\nEsc", "(O)\nEsc", "?\nO", "(O)", "O") } closeAllButton := m.renderMonitorButton(layout.closeAllRect.width, layout.topHeight, closeAllLabel, footerButtonMonitorCloseAll, m.monitorCloseAllEnabled(), colors) top := lipgloss.JoinHorizontal(lipgloss.Top, readout, strings.Repeat(" ", layout.resetRect.x-layout.readoutWidth), resetButton, strings.Repeat(" ", layout.closeAllRect.x-layout.resetRect.x-layout.resetRect.width), closeAllButton) - if layout.newRect.width > 0 { - label := i18n.Text("(N)EW SESSION") - if layout.newRect.width < lipgloss.Width(label)+2 { - label = strings.Replace(label, " ", "\n", 1) - } - if layout.newRect.width < lipgloss.Width(label)+2 || layout.topHeight < lipgloss.Height(label)+2 { - label = "(N)" + if r := layout.clearCheckRect; r.width > 0 { + full := i18n.Text("CLEAR CHEC(K)") + label := fitMonitorButtonLabel(r, full, strings.Replace(full, " ", "\n", 1), "CHK\n(K)", "(K)", "K") + if m.monitorBulkDismissArmed(true) { + label = fitMonitorButtonLabel(r, i18n.Text("CONFIRM (K)")+"\nEsc", "(K)?\nEsc", "(K)\nEsc", "(K)", "K") } + button := m.renderMonitorButton(r.width, r.height, label, footerButtonMonitorClearCheck, m.monitorClearCheckEnabled(), colors) + top = lipgloss.JoinHorizontal(lipgloss.Top, top, " ", button) + } + if layout.newRect.width > 0 { + full := i18n.Text("(N)EW SESSION") + label := fitMonitorButtonLabel(layout.newRect, full, strings.Replace(full, " ", "\n", 1), "(N)", "N") button := m.renderMonitorButton(layout.newRect.width, layout.topHeight, label, footerButtonMonitorNew, true, colors) top = lipgloss.JoinHorizontal(lipgloss.Top, top, " ", button) } @@ -177,6 +181,15 @@ func (m Model) renderMonitorArea(width, height int, colors palette) monitorView } } +func fitMonitorButtonLabel(r monitorRect, labels ...string) string { + for _, label := range labels { + if lipgloss.Width(label)+2 <= r.width && lipgloss.Height(label)+2 <= r.height { + return label + } + } + return "" +} + func (m Model) renderMonitorReadout(width, height int, colors palette) string { return m.renderMonitorSummary(width, height, colors, true) } @@ -375,7 +388,7 @@ func monitorSessionColumnWidths(width int) (int, int, bool) { available := max(width-gap, 2) // Keep rows aligned and give spare space to context/graphs. All rendering // and hit targets share this split, including the inline composer/menus. - metricsWidth := min(max(available/3, 1), 48) + metricsWidth := min(max(available/3, 1), 40) return metricsWidth, max(available-metricsWidth, 1), true } @@ -900,6 +913,9 @@ func (m Model) monitorButtonAt(x, y int) footerButtonID { if m.monitorCloseAllEnabled() && area.closeAllRect.contains(localX, localY) { return footerButtonMonitorCloseAll } + if area.clearCheckRect.contains(localX, localY) && m.monitorClearCheckEnabled() { + return footerButtonMonitorClearCheck + } if area.newRect.contains(localX, localY) { return footerButtonMonitorNew } diff --git a/internal/ui/monitor_clear_check_test.go b/internal/ui/monitor_clear_check_test.go new file mode 100644 index 0000000..91107b2 --- /dev/null +++ b/internal/ui/monitor_clear_check_test.go @@ -0,0 +1,180 @@ +package ui + +import ( + "slices" + "strings" + "testing" + "time" + + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" + "github.com/charmbracelet/x/ansi" + "github.com/merefield/codexometer/internal/codex" + "github.com/merefield/codexometer/internal/confirmation" + "github.com/merefield/codexometer/internal/i18n" +) + +func TestMonitorClearCheckDismissesOnlyMatchingRowsIncludingOffPage(t *testing.T) { + m := statusFilterTestModel() + m.height = 24 + m.finder.editInput().SetValue("match") + for i := range m.monitorSessionData { + m.monitorSessionData[i].name = "match" + } + m.setRowContext("work", contextWide) + m.monitorPrompt.session = "work" + m.monitorPrompt.input = newMonitorEditor() + m.monitorPrompt.input.SetValue("keep this draft") + check := &m.monitorSessionData[3] + check.latest, check.turnSequence, check.lastActivity = 42, 6, time.Unix(100, 0) + checkID := check.id + for _, id := range []string{"new-check", "off-page", "other-check", "priority"} { + name := "match" + if id == "other-check" { + name = "excluded" + } + m.monitorSessionData = append(m.monitorSessionData, monitorSession{id: id, name: name, displayed: true, attention: codex.SessionAttentionCheck}) + } + m.quotaStepPending = &codex.QuotaStep{Threshold: 80} + m.quota.sessions = []codex.QuotaSession{{ID: "priority"}} + geometry := m.monitorDashboardLayout() + r := m.monitorArea(geometry.contentWidth, geometry.meterHeight).clearCheckRect + x, y := 2+r.x+1, geometry.meterY+r.y+1 + next, _ := m.Update(tea.MouseMotionMsg{X: x, Y: y}) + if next.(Model).hoveredButton != footerButtonMonitorClearCheck { + t.Fatal("Clear Check* did not hover") + } + next, cmd := next.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) + n := next.(Model) + if cmd == nil || n.flashedButton != footerButtonMonitorClearCheck || n.monitorClearCheckEnabled() { + t.Fatal("Clear Check* should flash and then disable with no matching candidates") + } + if len(n.monitorDismissed) != 4 || len(m.monitorDismissed) != 1 || n.monitorRecordedTokens() != 625 || + n.monitorSelectedID != "work" || n.monitorPrompt.input.Value() != "keep this draft" { + t.Fatalf("unexpected bookkeeping, accounting, selection or draft: got %d new/%d previous dismissals, %d tokens, selection %q, editor %q", + len(n.monitorDismissed), len(m.monitorDismissed), n.monitorRecordedTokens(), n.monitorSelectedID, n.monitorPrompt.input.Value()) + } + for _, id := range []string{checkID, "new-check", "off-page"} { + if _, ok := n.monitorDismissed[id]; !ok { + t.Fatal("matching Check* left visible:", id) + } + } + want := []string{"work", "approval", "input", "complete", "idle", "priority"} + if got, _ := n.monitorListSelection(); !slices.Equal(got, want) { + t.Fatalf("unexpected remaining rows %v; want %v", got, want) + } + row := n.monitorSessionData[3] + n.restoreMonitorSessionOnActivity(&row) + if n.monitorSessionVisible(row) { + t.Fatal("unchanged Check* returned immediately") + } + row.turnSequence++ + n.restoreMonitorSessionOnActivity(&row) + if !n.monitorSessionVisible(row) { + t.Fatal("new activity did not restore the row") + } +} + +func TestMonitorClearCheckStrictConfirmationIsSeparateFromCloseAll(t *testing.T) { + m := statusFilterTestModel() + m.monitorFilter = monitorFilterCheck // Both actions now have exactly the same targets. + m.monitorSummaryFocused = true + m.monitorSelectedID = "check" + m.SetConfirmationMode(confirmation.Require) + press := func(k rune) { + next, _ := m.Update(key(k)) + m = next.(Model) + } + press('o') + if !m.monitorCloseAllArmed() { + t.Fatal("Close All did not arm") + } + press('K') + if !m.monitorBulkDismissArmed(true) || m.monitorCloseAllArmed() || m.monitorListSessionCount() != 1 { + t.Fatal("Clear Check* reused a different action's confirmation") + } + m.monitorSessionData[2].attention = codex.SessionAttentionCheck + press('k') + if !m.monitorBulkDismissArmed(true) || m.monitorListSessionCount() != 2 { + t.Fatal("changed targets did not require fresh confirmation") + } + press('k') + if m.monitorListSessionCount() != 0 || m.monitorFilter != monitorFilterCheck || m.monitorSelectedID != "" { + t.Fatal("confirmed clear did not update the list while preserving its filter") + } +} + +func TestMonitorClearCheckShortcutDoesNotInterruptTyping(t *testing.T) { + m, _ := inlinePromptTestModel() + m.monitorSessionData = append(m.monitorSessionData, monitorSession{ + id: "check", displayed: true, attention: codex.SessionAttentionCheck, + }) + m, _ = promptKey(m, tea.KeyEnter, "") + if !m.monitorPrompt.input.Focused() { + t.Fatal("test needs a focused inline composer") + } + next, _ := m.Update(key('k')) + m = next.(Model) + if m.monitorPrompt.input.Value() != "k" || !m.monitorClearCheckEnabled() || m.flashedButton != footerButtonNone { + t.Fatal("K typed in the composer unexpectedly dismissed Check*") + } +} + +func TestMonitorClearCheckResponsiveHitTargets(t *testing.T) { + for _, size := range []struct{ w, h int }{{40, 16}, {48, 20}, {52, 24}, {84, 25}, {136, 40}, {240, 42}} { + m := statusFilterTestModel() + m.width, m.height = size.w, size.h + g := m.monitorDashboardLayout() + a := m.monitorArea(g.contentWidth, g.meterHeight) + view := m.renderMonitorArea(g.contentWidth, g.meterHeight, paletteFor(m.theme)).view + if lipgloss.Width(view) > g.contentWidth || lipgloss.Height(view) > g.meterHeight { + t.Fatalf("header overflow at %v", size) + } + r := a.clearCheckRect + if r.width == 0 { + next, _ := m.Update(key('k')) + if size.w != 40 || next.(Model).monitorClearCheckEnabled() { + t.Fatalf("missing Clear Check* button or keyboard fallback at %v", size) + } + continue + } + x, y := 2+r.x, g.meterY+r.y + if m.monitorButtonAt(x, y) != footerButtonMonitorClearCheck || + m.monitorButtonAt(x+r.width-1, y+r.height-1) != footerButtonMonitorClearCheck || + m.monitorButtonAt(x-1, y) != footerButtonNone || m.monitorButtonAt(x+r.width, y) != footerButtonNone { + t.Fatalf("misaligned Clear Check* button at %v", size) + } + lines := strings.Split(view, "\n")[r.y+1 : r.y+r.height-1] + top, bottom := -1, -1 + var label []string + for i, line := range lines { + inner := ansi.Strip(ansi.Cut(line, r.x+1, r.x+r.width-1)) + trimmed := strings.TrimSpace(inner) + if trimmed == "" { + continue + } + if top < 0 { + top = i + } + bottom = i + label = append(label, trimmed) + left := strings.Index(inner, trimmed) + right := r.width - 2 - left - ansi.StringWidth(trimmed) + if left-right < -1 || left-right > 1 { + t.Fatalf("label %q not centred horizontally at %v: padding %d/%d", trimmed, size, left, right) + } + } + below := len(lines) - 1 - bottom + if top < 0 || top-below < -1 || top-below > 1 { + t.Fatalf("label not centred vertically at %v: padding %d/%d", size, top, below) + } + text := strings.Join(label, " ") + if strings.Contains(text, "*") || (size.w == 240 && text != i18n.Text("CLEAR CHEC(K)")) { + t.Fatalf("unexpected button label at %v: %q", size, text) + } + m.monitorFilter = monitorFilterWorking + if m.monitorButtonAt(x, y) != footerButtonNone { + t.Fatal("excluded Check* still gave the button a hit target") + } + } +} diff --git a/internal/ui/monitor_close_all.go b/internal/ui/monitor_close_all.go index 9f68fed..3b75e48 100644 --- a/internal/ui/monitor_close_all.go +++ b/internal/ui/monitor_close_all.go @@ -1,15 +1,35 @@ package ui import ( - "github.com/merefield/codexometer/internal/confirmation" + "maps" "slices" "time" + + "github.com/merefield/codexometer/internal/confirmation" ) -func (m Model) visibleMonitorSessionIDs() []string { +func (m Model) monitorDismissCandidate(s monitorSession, checksOnly bool) bool { + if checksOnly { + if monitorSessionStatus(s) != monitorFilterCheck { + return false + } + if _, pending := m.quotaSessionCandidate(s); pending { + return false + } + } + return m.monitorSessionInList(s) +} + +func (m Model) monitorClearCheckEnabled() bool { + return m.monitorState == monitorRunning && slices.ContainsFunc(m.monitorSessionData, func(s monitorSession) bool { + return m.monitorDismissCandidate(s, true) + }) +} + +func (m Model) visibleMonitorSessionIDs(checksOnly bool) []string { var ids []string for _, s := range m.monitorSessionData { - if m.monitorSessionInList(s) { + if m.monitorDismissCandidate(s, checksOnly) { ids = append(ids, s.id) } } @@ -17,21 +37,57 @@ func (m Model) visibleMonitorSessionIDs() []string { } func (m Model) monitorCloseAllArmed() bool { - return len(m.monitorCloseAllConfirm) > 0 && time.Now().Before(m.monitorCloseAllUntil) && - slices.Equal(m.monitorCloseAllConfirm, m.visibleMonitorSessionIDs()) + return m.monitorBulkDismissArmed(false) +} + +func (m Model) monitorBulkDismissArmed(checksOnly bool) bool { + return len(m.monitorCloseAllConfirm) > 0 && m.monitorCheckOnly == checksOnly && + time.Now().Before(m.monitorCloseAllUntil) && + slices.Equal(m.monitorCloseAllConfirm, m.visibleMonitorSessionIDs(checksOnly)) } func (m *Model) clearMonitorCloseAllConfirmation() { m.monitorCloseAllConfirm = nil + m.monitorCheckOnly = false m.monitorCloseAllUntil = time.Time{} } func (m *Model) requestMonitorCloseAll() { - if !m.confirmations.Required(confirmation.Narrow) || m.monitorCloseAllArmed() { - m.dismissAllMonitorSessions() + m.requestMonitorBulkDismiss(false) +} + +func (m *Model) requestMonitorBulkDismiss(checksOnly bool) { + if !m.confirmations.Required(confirmation.Narrow) || m.monitorBulkDismissArmed(checksOnly) { + if checksOnly { + m.dismissMonitorChecks() + } else { + m.dismissAllMonitorSessions() + } return } m.monitorPrompt.input.Blur() - m.monitorCloseAllConfirm = m.visibleMonitorSessionIDs() + m.monitorCloseAllConfirm = m.visibleMonitorSessionIDs(checksOnly) + m.monitorCheckOnly = checksOnly m.monitorCloseAllUntil = time.Now().Add(5 * time.Second) } + +func (m *Model) dismissMonitorChecks() { + m.clearMonitorCloseAllConfirmation() + m.monitorDismissed = maps.Clone(m.monitorDismissed) + for _, s := range m.monitorSessionData { + if !m.monitorDismissCandidate(s, true) { + continue + } + m.recordMonitorDismissal(s) + if m.monitorDismissHover == s.id { + m.monitorDismissHover = "" + } + if m.monitorDismissFlash == s.id { + m.monitorDismissFlash = "" + m.monitorDismissSeq++ + } + } + m.reconcileMonitorFilterSelection() + m.monitorSessions = m.visibleMonitorSessionCount() + m.scrollMonitorRows(0) +} diff --git a/internal/ui/monitor_close_all_test.go b/internal/ui/monitor_close_all_test.go index 76696d7..8ee5b50 100644 --- a/internal/ui/monitor_close_all_test.go +++ b/internal/ui/monitor_close_all_test.go @@ -98,7 +98,7 @@ func TestMonitorCloseAllRenderedControlAndEmptyList(t *testing.T) { if a.closeAllRect.x <= a.resetRect.x+a.resetRect.width || a.closeAllRect.y != a.resetRect.y || a.closeAllRect.height != a.resetRect.height { t.Fatal("Close All is not beside Zero") } - if !strings.Contains(ansi.Strip(view.view), i18n.Text("CL(O)SE ALL")) || lipgloss.Width(view.view) > g.contentWidth { + if text := strings.Join(monitorHeaderButtonLabel(view.view, a.closeAllRect), "\n"); text != i18n.Text("CL(O)SE\nALL") || lipgloss.Width(view.view) > g.contentWidth { t.Fatal("Close All label is missing or overflows the header") } updated, cmd := m.Update(tea.MouseMotionMsg{X: 2 + a.closeAllRect.x + 1, Y: g.meterY + 1}) @@ -112,6 +112,52 @@ func TestMonitorCloseAllRenderedControlAndEmptyList(t *testing.T) { } } +func monitorHeaderButtonLabel(view string, r monitorRect) []string { + rows := strings.Split(view, "\n") + var label []string + for _, row := range rows[r.y+1 : r.y+r.height-1] { + line := strings.TrimSpace(ansi.Strip(ansi.Cut(row, r.x+1, r.x+r.width-1))) + if line != "" { + label = append(label, line) + } + } + return label +} + +func TestMonitorHeaderButtonsShareOneWidth(t *testing.T) { + for _, newSession := range []bool{false, true} { + for _, width := range []int{29, 35, 40, 47, 49, 50, 84, 120, 136, 241} { + m := statusFilterTestModel() + m.width, m.height = width, 36 + if newSession { + m.fetcher = &newSessionProbe{} + m.finder.setScope("account") + } + g := m.monitorDashboardLayout() + a := m.monitorArea(g.contentWidth, g.meterHeight) + view := m.renderMonitorArea(g.contentWidth, g.meterHeight, paletteFor(m.theme)).view + border := strings.SplitN(view, "\n", 2)[0] + nextX := a.readoutWidth + 1 + for _, r := range []monitorRect{a.resetRect, a.closeAllRect, a.clearCheckRect, a.newRect} { + if r.width == 0 { + continue + } + if r.width != a.resetRect.width || r.x != nextX || r.height != a.topHeight { + t.Fatalf("unequal button geometry at width %d (new=%v): %+v", width, newSession, r) + } + edge := ansi.Strip(ansi.Cut(border, r.x, r.x+r.width)) + if !strings.HasPrefix(edge, "╭") || !strings.HasSuffix(edge, "╮") { + t.Fatalf("button border did not match its hit box at width %d (new=%v): %q", width, newSession, edge) + } + nextX += r.width + 1 + } + if nextX-1 != g.contentWidth { + t.Fatalf("header did not use available width %d (new=%v)", width, newSession) + } + } + } +} + func TestMonitorControlsHaveDistinctScopedShortcuts(t *testing.T) { for _, k := range []tea.KeyPressMsg{key('z'), key('Z')} { m := contextTestModel() diff --git a/internal/ui/monitor_columns_test.go b/internal/ui/monitor_columns_test.go index 2e2f31e..0230bae 100644 --- a/internal/ui/monitor_columns_test.go +++ b/internal/ui/monitor_columns_test.go @@ -11,8 +11,8 @@ import ( func TestMonitorSessionColumnsCapTelemetryAndPreserveSpace(t *testing.T) { for _, tc := range []struct{ width, metrics, detail int }{ - {3, 1, 1}, {80, 26, 53}, {144, 47, 96}, {145, 48, 96}, - {147, 48, 98}, {148, 48, 99}, {240, 48, 191}, {320, 48, 271}, + {3, 1, 1}, {80, 26, 53}, {120, 39, 80}, {121, 40, 80}, + {124, 40, 83}, {145, 40, 104}, {240, 40, 199}, {320, 40, 279}, } { metrics, detail, ok := monitorSessionColumnWidths(tc.width) if !ok || metrics != tc.metrics || detail != tc.detail || metrics+detail+1 != tc.width { @@ -38,7 +38,7 @@ func TestMonitorTelemetryCapResizeKeepsRenderedTargetsAligned(t *testing.T) { if id, ok := m.monitorSessionDismissAt(x, y); !ok || id != "root-one" { t.Fatalf("width %d dismiss target missed: %s, %v", width, id, ok) } - if x+lipgloss.Width(monitorDismissLabel) > 2+48 { + if x+lipgloss.Width(monitorDismissLabel) > 2+40 { t.Fatalf("width %d dismiss target exceeds capped box", width) } for _, delta := range []int{-1, 1} { @@ -55,7 +55,7 @@ func TestMonitorTelemetryCapResizeKeepsRenderedTargetsAligned(t *testing.T) { } func TestMonitorSessionTelemetryRenderedWidthIsCappedInEveryRowMode(t *testing.T) { - for _, width := range []int{145, 148, 240, 320} { + for _, width := range []int{121, 124, 240, 320} { for _, mode := range []int{contextGraph, contextSplit, contextWide} { m := contextTestModel() m.setRowContext("root-one", mode) @@ -68,8 +68,8 @@ func TestMonitorSessionTelemetryRenderedWidthIsCappedInEveryRowMode(t *testing.T } top := strings.Split(row, "\n")[0] end := strings.Index(top, "╮") - if end < 0 || lipgloss.Width(top[:end])+1 != 48 { - t.Fatalf("mode %d width %d telemetry border not at 48: %q", mode, width, top) + if end < 0 || lipgloss.Width(top[:end])+1 != 40 { + t.Fatalf("mode %d width %d telemetry border not at 40: %q", mode, width, top) } } } diff --git a/internal/ui/monitor_context.go b/internal/ui/monitor_context.go index beeadfd..2fae042 100644 --- a/internal/ui/monitor_context.go +++ b/internal/ui/monitor_context.go @@ -73,7 +73,10 @@ func (m Model) monitorCycleLabel(widths ...int) string { } func (m Model) renderContextAction(id, label string, colors palette) string { - s := colors.label() + return m.renderContextActionStyled(id, label, colors.label(), colors) +} + +func (m Model) renderContextActionStyled(id, label string, s lipgloss.Style, colors palette) string { if m.monitorContextHover == id { s = s.Foreground(colors.background).Background(colors.primary) } @@ -147,14 +150,7 @@ func (m Model) renderMonitorContextRow(width, height int, metrics string, s moni } lines := wrap(text, inner) bodyRows := max(height-2, 1) - dots := m.sessionActivityDots(s) - if bodyRows < 3 || inner < 3 { - dots = "" - } - contentRows := bodyRows - if dots != "" { - contentRows-- - } + contentRows, dots := m.monitorSplitContextBody(s, inner, bodyRows) // At most two text rows keep the preview compact; the detail has the rest. textRows := min(contentRows, 2) if len(lines) > textRows { @@ -187,6 +183,17 @@ func (m Model) renderMonitorContextRow(width, height int, metrics string, s moni return row } +func (m Model) monitorSplitContextBody(s monitorSession, width, rows int) (int, string) { + if rows < 3 || width < 3 { + return rows, "" + } + dots := m.sessionActivityDots(s) + if dots != "" { + rows-- + } + return rows, dots +} + func (m Model) contextDetailSession() (monitorSession, bool) { for _, s := range m.monitorSessionData { if s.id == m.monitorContextTarget() && m.monitorSessionVisible(s) { @@ -222,7 +229,7 @@ func (m Model) renderMonitorContextDetail(width, height int, colors palette) str start, end := m.detailVisibleRange(len(lines), page.rows) bodyLines := append([]string(nil), lines[start:end]...) if len(page.buttons) > 0 { - timeline := m.renderMonitorNavigationButtons(page.buttons, colors) + colors.dimmed().Render(page.right) + timeline := m.renderMonitorNavigationButtons(page.buttons, colors.label(), colors) + colors.dimmed().Render(page.right) bodyLines = append([]string{timeline}, bodyLines...) } if controls != "" { diff --git a/internal/ui/monitor_context_modes.go b/internal/ui/monitor_context_modes.go index 8489639..9c8f127 100644 --- a/internal/ui/monitor_context_modes.go +++ b/internal/ui/monitor_context_modes.go @@ -360,7 +360,7 @@ func (m Model) renderExpandedContext(width, height int, s monitorSession, colors } lines = append(lines, controls) } - action := m.renderMonitorNavigationButtons(m.expandedContextNavigation(width, height, s), colors) + action := m.renderMonitorNavigationButtons(m.expandedContextNavigation(width, height, s), colors.header(), colors) return frameSizedWithActions(width, max(height-2, 1), contextTitle(s.preview), action, m.renderMonitorCopy(width, s.id, colors), strings.Join(lines, "\n"), colors.primary, colors) } diff --git a/internal/ui/monitor_detail_test.go b/internal/ui/monitor_detail_test.go index d730c39..e38d993 100644 --- a/internal/ui/monitor_detail_test.go +++ b/internal/ui/monitor_detail_test.go @@ -20,7 +20,7 @@ func TestDetailMetadataSharesTimelineOnlyWhenItFits(t *testing.T) { metadata := "LIVE // 界-session // --" colors := paletteFor(m.theme) buttons := m.historyNavigationButtons(120, 30) - minWidth := 4 + lipgloss.Width(m.renderMonitorNavigationButtons(buttons, colors)+" "+metadata) + minWidth := 4 + lipgloss.Width(m.renderMonitorNavigationButtons(buttons, colors.label(), colors)+" "+metadata) for _, width := range []int{minWidth - 1, minWidth, minWidth + 10} { frame := strings.Split(m.renderMonitorContextDetail(width, 30, colors), "\n") lines := stripLinkLines(frame) diff --git a/internal/ui/monitor_header_focus.go b/internal/ui/monitor_header_focus.go index 3e35789..5543b7b 100644 --- a/internal/ui/monitor_header_focus.go +++ b/internal/ui/monitor_header_focus.go @@ -75,7 +75,7 @@ func (m *Model) monitorHeaderBlocksAction(key string) bool { case "q", "ctrl+c", "tab", "shift+tab": m.clearMonitorHeaderFocus() return false - case "t", "h", "z", "o": + case "t", "h", "z", "o", "k": return false default: return true @@ -84,7 +84,7 @@ func (m *Model) monitorHeaderBlocksAction(key string) bool { func (m *Model) monitorAttentionKey(key string) bool { switch key { - case "q", "ctrl+c", "tab", "shift+tab", "t", "h", "z", "o": + case "q", "ctrl+c", "tab", "shift+tab", "t", "h", "z", "o", "k": return m.monitorHeaderBlocksAction(key) } _, buttons := m.visibleMonitorHeader() diff --git a/internal/ui/monitor_navigation.go b/internal/ui/monitor_navigation.go index ffdb0fc..ca94b29 100644 --- a/internal/ui/monitor_navigation.go +++ b/internal/ui/monitor_navigation.go @@ -92,10 +92,10 @@ func layoutNavigationButtons(buttons []monitorNavigationButton, x, y int) int { } func (m Model) renderMonitorNavigation(width int, id string, full bool, colors palette) string { - return m.renderMonitorNavigationButtons(m.monitorNavigationButtons(width, id, full), colors) + return m.renderMonitorNavigationButtons(m.monitorNavigationButtons(width, id, full), colors.header(), colors) } -func (m Model) renderMonitorNavigationButtons(buttons []monitorNavigationButton, colors palette) string { +func (m Model) renderMonitorNavigationButtons(buttons []monitorNavigationButton, resting lipgloss.Style, colors palette) string { var labels []string for _, b := range buttons { if !b.enabled { @@ -107,7 +107,7 @@ func (m Model) renderMonitorNavigationButtons(buttons []monitorNavigationButton, } labels = append(labels, style.Render(b.label)) } else { - labels = append(labels, m.renderContextAction(b.action, b.label, colors)) + labels = append(labels, m.renderContextActionStyled(b.action, b.label, resting, colors)) } } return strings.Join(labels, " ") diff --git a/internal/ui/monitor_navigation_test.go b/internal/ui/monitor_navigation_test.go index c186494..4dd68d3 100644 --- a/internal/ui/monitor_navigation_test.go +++ b/internal/ui/monitor_navigation_test.go @@ -9,6 +9,34 @@ import ( "github.com/charmbracelet/x/ansi" ) +func TestMonitorBorderNavigationColoursAcrossThemes(t *testing.T) { + for theme := themeHacker; theme < themeCount; theme++ { + colors := paletteFor(theme) + m := contextTestModel() + m.setRowContext("root-one", contextFull) + box := m.renderMonitorNavigation(100, "root-one", true, colors) + for _, want := range []string{ + colors.header().Render("[←]"), + colors.dimmed().Render("[→]"), + colors.header().Render(monitorDismissLabel), + } { + if !strings.Contains(box, want) { + t.Fatalf("theme %v: border controls use the wrong resting colour: %q", theme, box) + } + } + m.monitorContextHover = "less:root-one" + box = m.renderMonitorNavigation(100, "root-one", true, colors) + hover := colors.label().Foreground(colors.background).Background(colors.primary).Render("[←]") + if !strings.Contains(box, hover) { + t.Fatalf("theme %v: hover no longer uses the original highlight", theme) + } + warning := monitorNavigationButton{label: "APPROVAL →", action: "detail:root-one", enabled: true} + if got := m.renderMonitorNavigationButtons([]monitorNavigationButton{warning}, colors.header(), colors); got != colors.label().Foreground(colors.warning).Render(warning.label) { + t.Fatalf("theme %v: approval lost its warning colour", theme) + } + } +} + func TestMonitorNavigationRenderedButtons(t *testing.T) { for _, size := range [][2]int{{40, 16}, {60, 24}, {80, 30}, {120, 40}, {148, 40}, {200, 50}, {320, 50}} { for _, mode := range []int{contextGraph, contextSplit, contextWide, contextFull} { diff --git a/internal/ui/monitor_profile.go b/internal/ui/monitor_profile.go index a209387..a91ae54 100644 --- a/internal/ui/monitor_profile.go +++ b/internal/ui/monitor_profile.go @@ -138,14 +138,19 @@ func (m Model) renderProfileControls(buttons []monitorApprovalButton, colors pal return renderMonitorButtonRows(buttons, colors, m.renderContextAction) } -func (m Model) renderSessionProfile(width, height int, s monitorSession, colors palette) string { - doc := m.profileDocument(s, max(width-4, 1)) - buttons := m.profileButtons(width, height, s) +func monitorProfileBodyLayout(height int, buttons []monitorApprovalButton) (rows, gap int) { n := 0 if len(buttons) > 0 { n = buttons[len(buttons)-1].y + 1 } - rows, gap, _ := monitorContextBodyLayout(height, n) + rows, gap, _ = monitorContextBodyLayout(height, n) + return +} + +func (m Model) renderSessionProfile(width, height int, s monitorSession, colors palette) string { + doc := m.profileDocument(s, max(width-4, 1)) + buttons := m.profileButtons(width, height, s) + rows, gap := monitorProfileBodyLayout(height, buttons) var body []string for _, line := range doc[:min(len(doc), rows)] { body = append(body, line.render(colors)) @@ -153,7 +158,7 @@ func (m Model) renderSessionProfile(width, height int, s monitorSession, colors if len(doc) > rows && rows > 0 { body[rows-1] = colors.label().Render(ansi.Truncate(i18n.Text("QUOTA THRESHOLD")+" →", max(width-4, 1), "")) } - if n > 0 { + if len(buttons) > 0 { for len(body) < rows+gap { body = append(body, "") } diff --git a/internal/ui/monitor_queue_compact.go b/internal/ui/monitor_queue_compact.go index e2dec09..7145dd6 100644 --- a/internal/ui/monitor_queue_compact.go +++ b/internal/ui/monitor_queue_compact.go @@ -63,7 +63,7 @@ func (m Model) renderFollowupBadge(id, label string, colors palette) string { if m.monitorQueue.compactFocus == id && m.monitorContextHover != "followups:"+id { return colors.label().Underline(true).Foreground(colors.primary).Render(label) } - return m.renderContextAction("followups:"+id, label, colors) + return m.renderContextActionStyled("followups:"+id, label, colors.header(), colors) } func (m Model) detailFollowupFooter(width, height, rows int, colors palette) (string, monitorRect) { @@ -129,13 +129,13 @@ func (m Model) compactPanelHeader(width int) (label, close string) { func (m Model) renderCompactFollowups(width, height int, colors palette) string { label, close := m.compactPanelHeader(width) - title := m.renderContextAction("followups:toggle", label, colors) + title := m.renderContextActionStyled("followups:toggle", label, colors.header(), colors) if s, ok := m.contextDetailSession(); ok { title += colors.dimmed().Render(" // " + monitorSessionIdentity(s)) } body := m.renderMonitorQueue(width, max(height-1, 1), colors) return frameSizedWithTitleAction(width, max(height-2, 1), title, - m.renderContextAction("followups:close", close, colors), body, colors.primary, colors) + m.renderContextActionStyled("followups:close", close, colors.header(), colors), body, colors.primary, colors) } func (m *Model) closeCompactFollowups() { diff --git a/internal/ui/monitor_read.go b/internal/ui/monitor_read.go index b24d079..93e0a02 100644 --- a/internal/ui/monitor_read.go +++ b/internal/ui/monitor_read.go @@ -29,6 +29,10 @@ type monitorReadDwellElapsed monitorReadDwell // Only deliberate selection/expansion starts the wide-row dwell. Full detail // reviews immediately; rendering, restored layouts and result arrival do not. func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { + var selectionCmd tea.Cmd + if m, message, selectionCmd = m.updateMonitorSelection(message); message == nil { + return m, selectionCmd + } if elapsed, ok := message.(monitorReadDwellElapsed); ok { command := m.finishMonitorReadDwell(monitorReadDwell(elapsed), time.Now()) return m, command @@ -198,21 +202,30 @@ func (m Model) monitorResultRect(id string) (monitorRect, bool) { } for _, pane := range m.monitorPartialContextPanes() { if pane.session.id == id { - r := pane.frame - rows, _, _ := monitorContextBodyLayout(r.height, 0) - if m.rowContextMode(id) == contextWide { - controls := m.expandedControlRows(r.width, r.height, pane.session) - if id == m.monitorContextTarget() { - controls += m.monitorQueueRows(r.width, r.height, controls) - } - rows, _, _ = monitorContextBodyLayout(r.height, controls) - } else { - rows = min(rows, 2) // split previews display at most two reply rows - } - rect := monitorRect{x: r.x + 4, y: g.meterY + r.y + 1, width: r.width - 4, height: rows} + rect := m.monitorPartialResultRect(pane, g.meterY) return rect, rect.width > 0 && rect.height > 0 } } return monitorRect{}, false } + +func (m Model) monitorPartialResultRect(pane monitorContextPane, meterY int) monitorRect { + r, id := pane.frame, pane.session.id + rows, _, _ := monitorContextBodyLayout(r.height, 0) + if m.hasSessionProfile(pane.session) { + rows, _ = monitorProfileBodyLayout(r.height, m.profileButtons(r.width, r.height, pane.session)) + } else if m.rowContextMode(id) == contextWide { + controls := m.expandedControlRows(r.width, r.height, pane.session) + if id == m.monitorContextTarget() { + controls += m.monitorQueueRows(r.width, r.height, controls) + } + rows, _, _ = monitorContextBodyLayout(r.height, controls) + } else { + rows, _ = m.monitorSplitContextBody(pane.session, r.width-4, rows) + if !hasWorkingCommand(pane.session.preview) { + rows = min(rows, 2) // exclude split preview metadata + } + } + return monitorRect{x: r.x + 4, y: meterY + r.y + 1, width: r.width - 4, height: rows} +} diff --git a/internal/ui/monitor_selection.go b/internal/ui/monitor_selection.go new file mode 100644 index 0000000..dce59a4 --- /dev/null +++ b/internal/ui/monitor_selection.go @@ -0,0 +1,240 @@ +package ui + +import ( + "strings" + "time" + + tea "charm.land/bubbletea/v2" + "github.com/charmbracelet/x/ansi" +) + +const ( + monitorSelectionFlash = 2 * time.Second + monitorCopyReceipt = 5 * time.Second +) + +// Capture what was actually visible, not the underlying Markdown or offscreen +// reply. Coordinates and a text check prevent a live redraw from copying a +// different selection (or replaying a click on a different line). +type monitorTextSelection struct { + press tea.MouseClickMsg + rect monitorRect + id string + rows []string + first, last int // first and last nonblank display rows, relative to the pane + x, y int + dragged, released bool +} + +type monitorSelectionExpired uint64 +type monitorCopyReceiptExpired uint64 + +func (m Model) updateMonitorSelection(msg tea.Msg) (Model, tea.Msg, tea.Cmd) { + s := m.monitorSelection + switch event := msg.(type) { + case monitorSelectionExpired: + if uint64(event) == m.monitorSelectionSequence && s != nil && s.released { + m.monitorSelection = nil + } + return m, nil, nil + case monitorCopyReceiptExpired: + if uint64(event) == m.monitorSelectionSequence { + m.monitorSelectionCopied = 0 + } + return m, nil, nil + case tea.MouseClickMsg: + m.monitorSelection = nil + if event.Button != tea.MouseLeft { + break + } + id, rect := m.monitorSelectionPane(event.X, event.Y) + if id == "" { + break + } + if hit := m.monitorContextAt(event.X, event.Y); hit != "" && + !strings.HasPrefix(hit, "less:") && !strings.HasPrefix(hit, "more:") { + break // Explicit controls retain their normal press handling. + } + rows := monitorSelectionRows(m.render(), rect) + if event.X-rect.x >= ansi.StringWidth(rows[event.Y-rect.y]) { + break // Empty cells retain their ordinary click behaviour. + } + first, last := event.Y-rect.y, event.Y-rect.y + for i, line := range rows { + if line != "" { + first, last = min(first, i), max(last, i) + } + } + m.monitorSelection = &monitorTextSelection{ + press: event, rect: rect, id: id, rows: rows, first: first, last: last, x: event.X, y: event.Y, + } + return m, nil, nil + case tea.MouseMotionMsg: + if s == nil || s.released { + break + } + if event.Button == tea.MouseNone { + m.monitorSelection = nil // The terminal lost the release. + break + } + if event.Button == tea.MouseLeft { + next := s.move(event.X, event.Y) + m.monitorSelection = &next + return m, nil, nil + } + case tea.MouseReleaseMsg: + if s == nil || s.released || (event.Button != tea.MouseLeft && event.Button != tea.MouseNone) { + break + } + m.monitorSelection = nil + next := s.move(event.X, event.Y) + id, rect := m.monitorSelectionPane(s.press.X, s.press.Y) + if id != s.id || rect != s.rect { + return m, nil, nil + } + rows := monitorSelectionRows(m.render(), rect) + if !next.dragged { + row := s.press.Y - rect.y + if rows[row] != s.rows[row] { + return m, nil, nil + } + return m, s.press, nil + } + selected, count := next.text(s.rows) + if count == 0 || !next.matches(rows, selected) { + return m, nil, nil + } + next.released = true + m.monitorSelection = &next + m.monitorSelectionCopied = count + m.monitorSelectionSequence++ + sequence := m.monitorSelectionSequence + return m, nil, tea.Batch(tea.SetClipboard(selected), + tea.Tick(monitorSelectionFlash, func(time.Time) tea.Msg { return monitorSelectionExpired(sequence) }), + tea.Tick(monitorCopyReceipt, func(time.Time) tea.Msg { return monitorCopyReceiptExpired(sequence) }), + ) + case tea.KeyPressMsg, tea.PasteMsg, tea.MouseWheelMsg, tea.WindowSizeMsg, tea.BlurMsg: + m.monitorSelection = nil + } + return m, msg, nil +} + +func (m Model) monitorSelectionPane(x, y int) (string, monitorRect) { + if m.meterView != viewMonitor || m.width <= 0 || m.height <= 0 || m.startup.active() || + m.loading && len(m.snapshot.Meters()) == 0 || m.finder.include || m.newSession.open() || + m.inspector.root != "" || m.actionReview != nil || m.hasThreadLinkPanel() || + m.scheduleUI.open || m.monitorQueue.open || m.monitorQueue.compact != "" || + m.monitorCommands.open || m.suggestionsActive() { + return "", monitorRect{} + } + if id := m.monitorContextDetail; id != "" { + if r, ok := m.monitorResultRect(id); ok && r.contains(x, y) { + return id, r + } + return "", monitorRect{} + } + g := m.monitorDashboardLayout() + for _, pane := range m.monitorPartialContextPanes() { + if pane.frame.contains(x, y-g.meterY) { + r := m.monitorPartialResultRect(pane, g.meterY) + if r.contains(x, y) { + return pane.session.id, r + } + } + } + return "", monitorRect{} +} + +func monitorSelectionRows(content string, r monitorRect) []string { + lines := strings.SplitN(content, "\n", r.y+r.height+1) + rows := make([]string, r.height) + for i := range min(r.height, len(lines)-r.y) { + line := ansi.Cut(lines[r.y+i], r.x, r.x+r.width) + rows[i] = strings.TrimRight(ansi.Strip(line), " ") + } + return rows +} + +func (s monitorTextSelection) move(x, y int) monitorTextSelection { + s.dragged = s.dragged || x != s.press.X || y != s.press.Y + top, bottom := s.rect.y+s.first, s.rect.y+s.last + if y < top { + x = s.rect.x + } else if y > bottom { + x = s.rect.x + s.rect.width - 1 + } + s.x = min(max(x, s.rect.x), s.rect.x+s.rect.width-1) + s.y = min(max(y, top), bottom) + return s +} + +func (s monitorTextSelection) bounds() (x1, y1, x2, y2 int) { + x1, y1, x2, y2 = s.press.X, s.press.Y, s.x, s.y + if y2 < y1 || y2 == y1 && x2 < x1 { + return x2, y2, x1, y1 + } + return +} + +func (s monitorTextSelection) text(rows []string) (string, int) { + x1, y1, x2, y2 := s.bounds() + var out strings.Builder + count := 0 + for y := y1; y <= y2; y++ { + if y != y1 { + out.WriteByte('\n') + } + x := s.rect.x + walkTerminalText(rows[y-s.rect.y], func(seq string, width int, _ *ansi.Parser) { + if selectedTerminalCell(x, y, width, x1, y1, x2, y2) { + out.WriteString(seq) + count++ + } + x += width + }) + } + return out.String(), count +} + +func (s monitorTextSelection) matches(rows []string, text string) bool { + current, _ := s.text(rows) + return current == text +} + +func selectedTerminalCell(x, y, width, x1, y1, x2, y2 int) bool { + return width > 0 && (y != y1 || x+width > x1) && (y != y2 || x <= x2) +} + +func (m Model) highlightMonitorSelection(content string) string { + s := m.monitorSelection + if s == nil || !s.dragged { + return content + } + id, r := m.monitorSelectionPane(s.press.X, s.press.Y) + if id != s.id || r != s.rect { + return content + } + rows := monitorSelectionRows(content, r) + if selected, count := s.text(rows); count == 0 || !s.matches(s.rows, selected) { + return content + } + lines := strings.Split(content, "\n") + x1, y1, x2, y2 := s.bounds() + for y := y1; y <= y2 && y < len(lines); y++ { + right := r.x + ansi.StringWidth(rows[y-r.y]) + var line strings.Builder + x := 0 + walkTerminalText(lines[y], func(seq string, width int, _ *ansi.Parser) { + if x >= r.x && x < right && selectedTerminalCell(x, y, width, x1, y1, x2, y2) { + line.WriteString("\x1b[7m") + line.WriteString(seq) + line.WriteString("\x1b[27m") + } else { + line.WriteString(seq) + } + x += width + }) + lines[y] = line.String() + } + return strings.Join(lines, "\n") +} diff --git a/internal/ui/monitor_text_selection_test.go b/internal/ui/monitor_text_selection_test.go new file mode 100644 index 0000000..ef8a842 --- /dev/null +++ b/internal/ui/monitor_text_selection_test.go @@ -0,0 +1,153 @@ +package ui + +import ( + "strings" + "testing" + + tea "charm.land/bubbletea/v2" + "github.com/charmbracelet/x/ansi" +) + +func TestMonitorOutputDragAcrossDetailModes(t *testing.T) { + for mode, label := range map[int]string{contextSplit: "split", contextWide: "wide", contextFull: "full"} { + t.Run(label, func(t *testing.T) { + m := contextTestModel() + const id = "root-one" + m.monitorSessionData = m.monitorSessionData[:1] + m.monitorSessionData[0].preview.Text = "Select alpha\nBeta ends here" + m.setRowContext(id, mode) + firstX, firstY := renderedTextStart(t, m, "alpha") + lastX, lastY := renderedTextStart(t, m, "Beta ends here") + // Select bottom to top, exercising the reverse endpoint order. + next, command := m.Update(tea.MouseClickMsg{X: lastX + 3, Y: lastY, Button: tea.MouseLeft}) + if command != nil || next.(Model).rowContextMode(id) != mode { + t.Fatal("press navigated instead of waiting for a drag") + } + next, _ = next.Update(tea.MouseMotionMsg{X: firstX, Y: firstY, Button: tea.MouseLeft}) + n := next.(Model) + preview := n.View().Content + if !strings.Contains(preview, "\x1b[7m") || ansi.Strip(preview) != ansi.Strip(m.View().Content) { + t.Fatal("drag should highlight without altering the displayed text") + } + next, command = n.Update(tea.MouseReleaseMsg{X: firstX, Y: firstY, Button: tea.MouseLeft}) + n = next.(Model) + if !commandCopiesText(command, "alpha\nBeta") || n.rowContextMode(id) != mode || n.monitorSelectionCopied != 9 { + t.Fatal("release did not copy only the selection or changed detail mode") + } + if view := n.View().Content; !strings.Contains(ansi.Strip(view), "Copied 9 chars") || !strings.Contains(view, "\x1b[7m") { + t.Fatal("missing selection flash or copy receipt") + } + next, _ = n.Update(monitorSelectionExpired(n.monitorSelectionSequence - 1)) + next, _ = next.Update(monitorCopyReceiptExpired(n.monitorSelectionSequence - 1)) + if updated := next.(Model); updated.monitorSelection == nil || updated.monitorSelectionCopied != 9 { + t.Fatal("an old timer cleared the new copy highlight or receipt") + } + next, _ = next.Update(monitorSelectionExpired(n.monitorSelectionSequence)) + if updated := next.(Model); updated.monitorSelection != nil || !strings.Contains(ansi.Strip(updated.View().Content), "Copied 9 chars") { + t.Fatal("the receipt should outlast the selection flash") + } + next, _ = next.Update(monitorCopyReceiptExpired(n.monitorSelectionSequence)) + if strings.Contains(ansi.Strip(next.(Model).View().Content), "Copied 9 chars") { + t.Fatal("copy receipt did not clear") + } + }) + } +} + +func TestMonitorCopyReceiptCentresWithoutDisplacingFooterButtons(t *testing.T) { + const receipt = "Copied 123 chars" + for _, tc := range []struct{ width, row int }{{36, 0}, {56, 0}, {80, 1}, {121, 1}} { + m := contextTestModel() + m.width = tc.width + 4 + colors := paletteFor(m.theme) + before := strings.Split(ansi.Strip(m.renderFooter(tc.width, colors)), "\n") + m.monitorSelectionCopied = 123 + got := strings.Split(ansi.Strip(m.renderFooter(tc.width, colors)), "\n") + row := got[tc.row] + index := strings.Index(row, receipt) + if index < 0 || index != (tc.width-ansi.StringWidth(receipt))/2 || ansi.StringWidth(row) > tc.width { + t.Fatalf("width %d: receipt not centred on row %d: %q", tc.width, tc.row, got) + } + if got[1-tc.row] != before[1-tc.row] { + t.Fatalf("width %d: unaffected footer row changed: %q -> %q", tc.width, before, got) + } + buttons, separator := footerButtonLayoutWithTheme(tc.width, colors.name, viewMonitor) + y, x := m.dashboardLayout().footerY+1, 0 + for _, b := range buttons { + if !strings.HasPrefix(got[1][x:], b.label) || m.footerButtonAt(2+x, y) != b.id { + t.Fatalf("width %d: footer button %q moved or lost its click target", tc.width, b.label) + } + x += ansi.StringWidth(b.label) + len(separator) + } + if tc.row == 1 && (!strings.HasSuffix(got[1], "THEME // "+colors.name) || m.footerButtonAt(2+index, y) != footerButtonNone) { + t.Fatal("badge displaced the theme or gained a click target") + } + } +} + +func TestMonitorOutputSelectionCopiesWholeGraphemesAndStripsStyles(t *testing.T) { + rect := monitorRect{x: 2, y: 1, width: 8, height: 3} + rows := monitorSelectionRows("ignored\n│ \x1b[31mAé界Z\x1b[0m │\n│ │\n│ Done │", rect) + press := tea.MouseClickMsg{X: 3, Y: 1, Button: tea.MouseLeft} + s := monitorTextSelection{press: press, rect: rect, last: 2, x: press.X, y: press.Y} + s = s.move(5, 1) // the second terminal cell of 界 + if got, count := s.text(rows); got != "é界" || count != 2 { + t.Fatalf("unicode selection = %q (%d chars)", got, count) + } + s = s.move(3, 3) + if got, count := s.text(rows); got != "é界Z\n\nDo" || count != 5 { + t.Fatalf("multiline selection = %q (%d chars)", got, count) + } +} + +func TestMonitorOutputDragDoesNotNavigateOrCopyStaleOrOtherPaneContent(t *testing.T) { + m := contextTestModel() + const id = "root-one" + m.setRowContext(id, contextWide) + m.monitorSessionData[0].preview.Text = "Alpha begins here" + m.monitorSessionData[1].preview.Text = "Unrelated second row" + m.setRowContext("root-two", contextWide) + x, y := renderedTextStart(t, m, "Alpha begins here") + press := tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft} + release := tea.MouseReleaseMsg{X: x + 4, Y: y, Button: tea.MouseLeft} + next, _ := m.Update(press) + changed := next.(Model) + changed.monitorSessionData = append([]monitorSession(nil), changed.monitorSessionData...) + changed.monitorSessionData[0].preview.Text = "Freshly streamed text" + if state, command := changed.Update(release); command != nil || state.(Model).monitorSelection != nil { + t.Fatal("changed output was copied") + } + next, _ = m.Update(press) + _, otherRowY := renderedTextStart(t, m, "Unrelated second row") + other := tea.MouseReleaseMsg{X: x + 6, Y: otherRowY, Button: tea.MouseLeft} + next, command := next.Update(other) + n := next.(Model) + s := n.monitorSelection + if !commandCopiesText(command, "Alpha begins here") || s == nil || s.y != y || n.monitorSelectedID != m.monitorSelectedID { + t.Fatal("drag did not stay inside its origin pane") + } +} + +func TestMonitorOutputStationaryClickKeepsNavigationAndComposerClick(t *testing.T) { + m := contextTestModel() + m.setRowContext("root-one", contextWide) + x, y := renderedTextStart(t, m, "Finished updating") + next, _ := m.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) + next, _ = next.Update(tea.MouseReleaseMsg{X: x, Y: y, Button: tea.MouseLeft}) + n := next.(Model) + if n.rowContextMode("root-one") != contextSplit || n.monitorSelection != nil || n.monitorSelectionCopied != 0 { + t.Fatal("stationary click did not perform the normal wide-to-split action") + } + + m, _ = promptTestModel() + g := m.monitorDashboardLayout() + controls := m.layoutDetailControls(g.contentWidth, g.meterHeight) + if controls.rows == 0 { + t.Fatal("fixture needs a visible composer") + } + composerX, composerY := renderedTextStart(t, m, "Click here") + next, _ = m.Update(tea.MouseClickMsg{X: composerX, Y: composerY, Button: tea.MouseLeft}) + if n := next.(Model); n.monitorSelection != nil || !n.monitorPrompt.input.Focused() { + t.Fatal("composer did not retain immediate click-to-focus") + } +} diff --git a/internal/ui/session_finder.go b/internal/ui/session_finder.go index 4001a92..87f4b6c 100644 --- a/internal/ui/session_finder.go +++ b/internal/ui/session_finder.go @@ -422,7 +422,7 @@ func (m Model) renderSessionFinder(w, h int, colors palette) string { lines = append(lines, m.renderSavedResults(g, colors)...) } if g.framed { - arrows := m.renderMonitorNavigationButtons(m.savedListButtons(g, w), colors) + arrows := m.renderMonitorNavigationButtons(m.savedListButtons(g, w), colors.header(), colors) return frameSizedWithTitleAction(w, h-2, savedFinderTitle(), arrows, strings.Join(lines, "\n"), colors.primary, colors) } for len(lines) < h { @@ -513,7 +513,7 @@ func (m Model) renderSavedResults(g finderGeometry, colors palette) []string { if f.detail != "" { for _, r := range rows { if r.ID == f.detail { - header := m.renderMonitorNavigationButtons(m.savedPreviewButtons(g), colors) + header := m.renderMonitorNavigationButtons(m.savedPreviewButtons(g), colors.label(), colors) separator := "" if header != "" { separator = " " diff --git a/internal/ui/session_links.go b/internal/ui/session_links.go index e4a1df1..a5a6c74 100644 --- a/internal/ui/session_links.go +++ b/internal/ui/session_links.go @@ -360,6 +360,12 @@ func walkTerminalText(text string, visit func(string, int, *ansi.Parser)) { var state byte for len(text) > 0 { seq, width, n, next := ansi.DecodeSequence(text, state, p) + // DecodeSequence fast-paths ASCII bytes. Keep a letter and any + // following combining marks together, just as the layout does. + if width == 1 && n == 1 && len(text) > 1 && text[1] >= 0xc0 { + seq, width = ansi.FirstGraphemeCluster(text, ansi.GraphemeWidth) + n = len(seq) + } visit(seq, width, p) text, state = text[n:], next } diff --git a/internal/ui/session_links_darwin_test.go b/internal/ui/session_links_darwin_test.go index efebce5..4b8332a 100644 --- a/internal/ui/session_links_darwin_test.go +++ b/internal/ui/session_links_darwin_test.go @@ -44,7 +44,8 @@ func TestMacWebLinkClickDoesNotNavigateOrApprove(t *testing.T) { if sessionWebLinkAt(line, x, 0) != target { continue } - next, cmd := m.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) + next, _ := m.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) + next, cmd := next.Update(tea.MouseReleaseMsg{X: x, Y: y, Button: tea.MouseLeft}) n := next.(Model) // Do not execute cmd: regression tests must never launch a real browser. if cmd == nil || n.monitorContextDetail != m.monitorContextDetail || n.monitorApprovalConfirm != "" || n.monitorPrompt.input.Focused() { diff --git a/internal/ui/session_thread_links_test.go b/internal/ui/session_thread_links_test.go index b66caf0..8312c43 100644 --- a/internal/ui/session_thread_links_test.go +++ b/internal/ui/session_thread_links_test.go @@ -69,6 +69,7 @@ func TestThreadLinkClickAndKeyboardPreviewPreserveSource(t *testing.T) { } else { x, y := renderedTextStart(t, m, "work") apply(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) + apply(tea.MouseReleaseMsg{X: x, Y: y, Button: tea.MouseLeft}) } if cmd == nil || m.threadLinks.id != previewID { t.Fatal("link activation did not request preview", m.threadLinks) @@ -104,7 +105,8 @@ func TestThreadLinkPreviewLeavesHiddenSourceUnread(t *testing.T) { dwell := m.monitorReadDwell x, y := renderedTextStart(t, m, "Earlier work") wheel := tea.MouseWheelMsg{X: x, Y: y, Button: tea.MouseWheelDown} - next, cmd := m.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) + next, _ := m.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) + next, cmd := next.Update(tea.MouseReleaseMsg{X: x, Y: y, Button: tea.MouseLeft}) if cmd == nil { t.Fatal("no preview request") } diff --git a/internal/ui/view.go b/internal/ui/view.go index 8613705..e669d40 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -16,7 +16,7 @@ import ( ) func (m Model) View() tea.View { - content := m.render() + content := m.highlightMonitorSelection(m.render()) if !m.inline && m.width > 0 && m.height > 0 { // Paint the complete alternate screen without changing the user's // terminal profile. Inline mode only paints its own content. @@ -231,7 +231,22 @@ func (m Model) renderFooter(width int, colors palette) string { ).Render(button.label)) } theme := colors.dimmed().Render(i18n.Format("THEME // %s", colors.name)) - controlRow := joinRight(strings.Join(controls, separator), theme, width) + controlLabels := strings.Join(controls, separator) + controlRow := joinRight(controlLabels, theme, width) + if m.meterView == viewMonitor && m.monitorSelectionCopied > 0 { + label := ansi.Truncate(" "+i18n.Format("Copied %d chars", m.monitorSelectionCopied)+" ", width, "") + badge := colors.header().Foreground(colors.background).Background(colors.primary).Render(label) + badgeWidth := lipgloss.Width(badge) + start := (width - badgeWidth) / 2 + leftGap := start - lipgloss.Width(controlLabels) + rightGap := width - start - badgeWidth - lipgloss.Width(theme) + if leftGap >= 1 && rightGap >= 1 { + controlRow = controlLabels + strings.Repeat(" ", leftGap) + badge + strings.Repeat(" ", rightGap) + theme + } else { + // Keep the shortcut labels and their mouse targets in place on narrow terminals. + status = strings.Repeat(" ", start) + badge + } + } return status + "\n" + controlRow }