Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cadd4c8f64 | |||
| 98d1c059cf | |||
| cf65d5d707 | |||
| ef9b8e71c6 | |||
| e64060e40f | |||
| e4ab8c2136 | |||
| f312b6d345 | |||
| e6f5a94fae | |||
| c1ecba0624 | |||
| 878e9370bc |
@@ -11,14 +11,19 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: jdx/mise-action@v2
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
- uses: mlugg/setup-zig@v2
|
- name: Cache Go modules
|
||||||
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
version: 0.15.2
|
path: |
|
||||||
|
~/.cache/go-build
|
||||||
|
~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
- name: Build libghostty-vt
|
- name: Build libghostty-vt
|
||||||
run: make deps
|
run: make deps
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
# libghostty-vt is built from a pinned upstream Ghostty commit; that
|
# libghostty-vt is built from a pinned upstream Ghostty commit; that
|
||||||
# commit's build.zig.zon pins minimum_zig_version = 0.15.2. We match
|
# commit's build.zig.zon pins minimum_zig_version = 0.15.2. We match
|
||||||
# it here so contributors don't have to puzzle out the version from
|
# it here so contributors don't have to puzzle out the version from
|
||||||
# a deep upstream file.
|
# a deep upstream file. The go pin matches go.mod so CI and local
|
||||||
|
# builds use the same toolchain.
|
||||||
[tools]
|
[tools]
|
||||||
zig = "0.15.2"
|
zig = "0.15.2"
|
||||||
|
go = "1.26.3"
|
||||||
|
|||||||
68
CHANGELOG.md
68
CHANGELOG.md
@@ -6,6 +6,72 @@ loosely follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.0.6] - 2026-05-15
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Toast notifications now reserve three content rows and word-wrap
|
||||||
|
the message body inside the box, replacing the previous
|
||||||
|
single-line+ellipsis layout. The `Ctrl-N · N more` inline hint is
|
||||||
|
gone; instead the host status strip surfaces a `Ctrl-N · dismiss`
|
||||||
|
hint, shown only while a notification is on screen so the chord
|
||||||
|
doesn't advertise itself when it has nothing to dismiss.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Auto-summary no longer fails immediately with `codex summarizer:
|
||||||
|
error: unexpected argument '--ask-for-approval' found`. The codex
|
||||||
|
CLI dropped that flag; we now rely on `--sandbox read-only` (which
|
||||||
|
already implies no approvals) instead of passing it.
|
||||||
|
- Toast box no longer flickers / half-erases while the focused
|
||||||
|
child (claude, codex, opencode, etc.) repaints its TUI. The
|
||||||
|
overlay is now stitched onto the end of the per-chunk PTY write
|
||||||
|
under `outMu`, and wrapped in DECSET 2026 (synchronized output)
|
||||||
|
brackets so terminals that support it batch the child's redraw +
|
||||||
|
the box paint into a single frame instead of racing cell-by-cell.
|
||||||
|
|
||||||
|
## [0.0.5] - 2026-05-15
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Replaced the single-slot status-line "flash" with a stackable toast
|
||||||
|
surface anchored at the top-right of the focused pane. `flashError`,
|
||||||
|
`flashTransient`, and MCP `request_human_attention` now push onto
|
||||||
|
the toast stack (cap 5, oldest drops). Toasts persist until
|
||||||
|
dismissed with `Ctrl-N`, or cleared via the new
|
||||||
|
"Clear notifications" palette command. The status line no longer
|
||||||
|
shows the `[!]` prefix.
|
||||||
|
- `Ctrl-N` is consumed by the host only when there is a toast to
|
||||||
|
dismiss; an empty stack lets `Ctrl-N` pass through to the focused
|
||||||
|
child so readline / nano / emacs / opencode keep their bindings.
|
||||||
|
- Command palette is calmer when something is focused. Focused-section
|
||||||
|
rows now read as bare verbs (`Rename`, `Close`, `Stop`, `Restart`,
|
||||||
|
`Delete`, `Edit`) instead of repeating the focused name (`Close
|
||||||
|
agent: codex`); the title bar's `on: codex` / `pad: notes.md`
|
||||||
|
carries the subject. Fuzzy queries still match the dropped context
|
||||||
|
through the row hint (e.g. typing `close codex` still finds the
|
||||||
|
Close row).
|
||||||
|
- Dashed `── Focused ──` / `── Open ──` / `── Spawn ──` section
|
||||||
|
banners are gone. Sections are separated by a single blank spacer
|
||||||
|
row, so the action labels themselves carry the visual weight.
|
||||||
|
- The Open section no longer lists a `Switch to <current>` row for
|
||||||
|
the pane you're already focused on.
|
||||||
|
|
||||||
|
## [0.0.4] - 2026-05-15
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Release workflow (`.gitea/workflows/release.yml`) now provisions
|
||||||
|
Zig and Go through `jdx/mise-action@v2`, reading the versions from
|
||||||
|
`.mise.toml` (zig 0.15.2, go 1.26.3). Both toolchains were
|
||||||
|
previously installed via `mlugg/setup-zig` and `actions/setup-go`,
|
||||||
|
whose mirror chase / GitHub fetch combined for ~8 minutes per run
|
||||||
|
before any patterm code compiled. mise pulls each tool once and
|
||||||
|
caches the install dir, so subsequent runs hit the cache instead of
|
||||||
|
re-downloading. `make deps` still resolves zig via `mise which zig`
|
||||||
|
with a PATH fallback; `go.mod` already pinned `go 1.26.3`, so the
|
||||||
|
new `go` entry in `.mise.toml` just keeps CI and local builds on
|
||||||
|
the same toolchain.
|
||||||
|
- A Go module/build cache step (`actions/cache@v4`, keyed on
|
||||||
|
`go.sum`) was added so `go build` doesn't re-download dependencies
|
||||||
|
on every tag push.
|
||||||
|
|
||||||
## [0.0.3] - 2026-05-15
|
## [0.0.3] - 2026-05-15
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -70,6 +136,8 @@ loosely follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|||||||
the command field.
|
the command field.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- Error/status flashes now restore the currently focused pane instead
|
||||||
|
of drawing the empty-state hint over a running agent or process.
|
||||||
- Release workflow (`.gitea/workflows/release.yml`) now uses
|
- Release workflow (`.gitea/workflows/release.yml`) now uses
|
||||||
`mlugg/setup-zig@v2` instead of the deprecated `@v1`. v1 hard-coded
|
`mlugg/setup-zig@v2` instead of the deprecated `@v1`. v1 hard-coded
|
||||||
the pre-0.14 tarball name (`zig-linux-x86_64-<ver>.tar.xz`), so
|
the pre-0.14 tarball name (`zig-linux-x86_64-<ver>.tar.xz`), so
|
||||||
|
|||||||
115
TODO.md
115
TODO.md
@@ -1,115 +0,0 @@
|
|||||||
# Perf Audit (reviewed 2026-05-15)
|
|
||||||
Findings that survived the 2026-05-15 review pass. Low and marginal
|
|
||||||
items from the original sweep were removed; remaining items have enough
|
|
||||||
measured or workflow evidence to justify action.
|
|
||||||
|
|
||||||
Baseline benchmark numbers (`go test -bench=. ./internal/app/`, AMD
|
|
||||||
Ryzen 7 7800X3D, libghostty-vt **ReleaseFast** after the Makefile
|
|
||||||
fix landed):
|
|
||||||
|
|
||||||
```
|
|
||||||
# Renderer alone
|
|
||||||
ViewportRenderer_PlainASCII 229 MB/s 1.3 KB/op 6 allocs/op
|
|
||||||
ViewportRenderer_StyledLines 89 MB/s 91 KB/op 4325 allocs/op
|
|
||||||
ViewportRenderer_RatatuiBurst 40 MB/s 365 KB/op 17306 allocs/op
|
|
||||||
RendererThroughput_ReuseInstance 90 MB/s 316 KB/op 17380 allocs/op
|
|
||||||
ContainsOSC_NoOSC 3050 MB/s 0 B/op 0 allocs/op
|
|
||||||
|
|
||||||
# ASCII-video stream (renderer only — 3 sec at the target fps)
|
|
||||||
ASCIIVideo_Stream_8Color_120fps 260 µs/frame 3845 fps_ceiling 3.1% budget
|
|
||||||
ASCIIVideo_Stream_TrueColor_120fps 576 µs/frame 1735 fps_ceiling 6.9% budget
|
|
||||||
|
|
||||||
# Full pipeline (em.Write + renderer + io.Discard write)
|
|
||||||
Pipeline_ASCIIVideo_8Color_120fps 493 µs/frame 2030 fps_ceiling 5.9% budget
|
|
||||||
Pipeline_ASCIIVideo_TrueColor_120fps 1075 µs/frame 931 fps_ceiling 12.9% budget
|
|
||||||
|
|
||||||
# Emulator alone (libghostty-vt CSI/SGR parser)
|
|
||||||
Emulator_Write_Stream_8Color_120fps 257 µs/frame 3890 fps_ceiling
|
|
||||||
Emulator_Write_Stream_TrueColor_120fps 488 µs/frame 2051 fps_ceiling
|
|
||||||
```
|
|
||||||
|
|
||||||
The current pipeline still has large 120 fps headroom. The remaining
|
|
||||||
renderer concern is multi-MiB styled replay latency and allocation
|
|
||||||
churn, not normal steady-state frame budget.
|
|
||||||
|
|
||||||
|
|
||||||
- [ ] **viewport renderer allocates heavily on SGR/CSI-heavy chunks.** [MEDIUM]
|
|
||||||
- Review evidence: five benchmark reps confirmed
|
|
||||||
`ViewportRenderer_StyledLines` at about 4,325 allocs per 16 KiB
|
|
||||||
chunk (~91.5 KB/op, roughly 1 alloc per 3.8 input bytes), and
|
|
||||||
`ViewportRenderer_RatatuiBurst` at about 17,306 allocs per chunk
|
|
||||||
(~365 KB/op). A 5 MiB styled resume benchmark allocated about
|
|
||||||
31 MB across 1.38M objects.
|
|
||||||
- Likely hot paths: generic CSI/SGR output in
|
|
||||||
`internal/app/viewport_renderer.go` sends many sequences through
|
|
||||||
`vr.shifter.Shift(vr.buf)`, while `internal/app/cursorshift.go`
|
|
||||||
returns a fresh `[]byte` via `pending.String()` on every
|
|
||||||
`Shift` call and parses CSI params through `string(raw)` /
|
|
||||||
`strings.Split`. The mode-helper `string(params)` conversions
|
|
||||||
are real, but probably not the main SGR-heavy cost.
|
|
||||||
- Fix direction: make `cursorShifter` write into caller-owned
|
|
||||||
scratch output or directly into the viewport renderer's pending
|
|
||||||
builder; parse CSI params from byte slices; pre-grow/reuse
|
|
||||||
renderer and shifter buffers. Re-run styled-lines, ratatui, and
|
|
||||||
5 MiB resume benchmarks; use pprof when available to confirm the
|
|
||||||
top allocation sites.
|
|
||||||
|
|
||||||
- [ ] **large styled resume/replay dumps spend visible time in viewport rendering.** [MEDIUM]
|
|
||||||
- Review evidence: `BenchmarkSessionResume_5MiBStyled` measured
|
|
||||||
about 58 ms median and 63 ms p95 over five reps. The plain 5 MiB
|
|
||||||
benchmark was about 23-24 ms with only 21 allocs. The live path
|
|
||||||
renders focused PTY chunks through `renderer.Render`, then still
|
|
||||||
pays emulator writes, ring writes, event dispatch, stdout writes,
|
|
||||||
and real terminal paint.
|
|
||||||
- Scope: this is not a Codex steady-state throughput limit. A
|
|
||||||
100 KB/s stream is far below the styled renderer's ~80-90 MB/s
|
|
||||||
ceiling. It matters for multi-MiB burst replay, resume/startup
|
|
||||||
dumps, and dense full-screen churn.
|
|
||||||
- Fix direction: do the allocation fix first, since it should also
|
|
||||||
improve throughput. After that, invest further only if styled
|
|
||||||
resume traces remain user-visible or the styled-lines benchmark
|
|
||||||
is still under roughly 300 MB/s.
|
|
||||||
|
|
||||||
- [ ] **wait_for_pattern re-scans the entire stream/grid while waiting.** [MEDIUM]
|
|
||||||
- `internal/app/host.go:476-493` (the `check` closure). On
|
|
||||||
`scope="scrollback"` it calls `c.StreamRead(0)` followed by
|
|
||||||
`stripANSIBytes(nil, b)`, so each check can copy, strip, and
|
|
||||||
search the full 1 MiB ring. On `scope="grid"` it calls
|
|
||||||
`PlainText()` and runs the regex against the full grid string.
|
|
||||||
- Caveat from review: the current chunk notifier coalesces bursts
|
|
||||||
with a buffered channel and has a 500 ms fallback, so this is not
|
|
||||||
necessarily one full scan per PTY chunk. It is still meaningful
|
|
||||||
for active waits on chatty panes.
|
|
||||||
- Fix direction: for `scrollback`, track the last checked stream
|
|
||||||
offset and search only new output plus a bounded overlap/scratch
|
|
||||||
buffer so matches spanning chunks are not missed. For `grid`,
|
|
||||||
dedupe on `ScreenVersion()` and skip work when the version has
|
|
||||||
not changed.
|
|
||||||
|
|
||||||
- [ ] **search_output rebuilds and searches whole scrollback on every call.** [MEDIUM]
|
|
||||||
- `internal/app/host.go:428-437` compiles a fresh regex, reads the
|
|
||||||
stream from offset 0, strips ANSI for `kind="rendered"`, converts
|
|
||||||
the full buffer to a string, and splits it into lines before
|
|
||||||
applying `limit`. This is meaningful when agents poll the same
|
|
||||||
pattern; it is low impact for ad hoc searches.
|
|
||||||
- Fix direction: cache compiled regexes by pattern; cache stripped
|
|
||||||
rendered output by child id and stream end offset; avoid
|
|
||||||
`strings.Split` over the whole ring when only the first `limit`
|
|
||||||
matches are needed. Prefer an incremental search shape if this
|
|
||||||
becomes the standard "watch for marker" path.
|
|
||||||
|
|
||||||
# On Hold
|
|
||||||
- [ ] There's a unicode <?> being displayed in opencode [ON HOLD]
|
|
||||||
- Investigated 2026-05-14: patterm passes ghostty grapheme codepoints
|
|
||||||
through unchanged (vt/ghostty.go:452-462), so the `<?>` glyph is
|
|
||||||
most likely the *host* terminal's font fallback for opencode's
|
|
||||||
Nerd Font private-use codepoints, not a patterm substitution.
|
|
||||||
Need a concrete reproduction (which codepoint, which host
|
|
||||||
terminal/font) before changing rendering.
|
|
||||||
- [ ] After codex rips for like 15 minutes, the terminal becomes quite slow. [ON HOLD / VERIFYING]
|
|
||||||
- 2026-05-14: Perf plan P1-P11 landed (see CHANGELOG). Needs a real
|
|
||||||
long-running codex session to confirm whether the steady-state
|
|
||||||
slowdown is gone or some hotspot remains. Capture a pprof if it
|
|
||||||
still feels slow after ≥15 minutes — the structural drivers the
|
|
||||||
audit named are all addressed, so a remaining symptom is a new
|
|
||||||
one and probably wants fresh profiling.
|
|
||||||
|
|||||||
@@ -187,9 +187,7 @@ func Run(ctx context.Context, opts Options) error {
|
|||||||
}, func(_ string, result summaryState) {
|
}, func(_ string, result summaryState) {
|
||||||
if result.Error != "" {
|
if result.Error != "" {
|
||||||
st.flashError(fmt.Sprintf("summary: %v", result.Error))
|
st.flashError(fmt.Sprintf("summary: %v", result.Error))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
st.flashTransient("summary updated")
|
|
||||||
})
|
})
|
||||||
sess.SetMetrics(metrics)
|
sess.SetMetrics(metrics)
|
||||||
host.attention = st
|
host.attention = st
|
||||||
@@ -432,10 +430,11 @@ type uiState struct {
|
|||||||
repaintNextPTY string
|
repaintNextPTY string
|
||||||
repaintNextPTYBudget int
|
repaintNextPTYBudget int
|
||||||
|
|
||||||
// attention is the latest request_human_attention surfaced via MCP;
|
// toasts is the stackable notification surface. flashError,
|
||||||
// rendered in the status line until cleared.
|
// flashTransient, and notifyAttention all push onto it; the user
|
||||||
attentionText string
|
// dismisses entries with Ctrl-N or the "Clear notifications"
|
||||||
attentionAt string
|
// palette command.
|
||||||
|
toasts toastStack
|
||||||
|
|
||||||
// pendingTrust is the most recent trust prompt — surfaced in the
|
// pendingTrust is the most recent trust prompt — surfaced in the
|
||||||
// status line until the user resolves it with Ctrl-K. v1 keeps the
|
// status line until the user resolves it with Ctrl-K. v1 keeps the
|
||||||
@@ -722,20 +721,15 @@ func (st *uiState) updateActiveAgentLocked(c *Child) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// notifyAttention is the request_human_attention sink (SPEC §7). We
|
// notifyAttention is the request_human_attention sink (SPEC §7). We
|
||||||
// surface a one-line toast in the status row and remember the most
|
// push a toast onto the stack; the focused-pane render path picks it
|
||||||
// recent ask so the status line keeps showing it. The sidebar-blink is
|
// up. The sidebar-blink is deferred until the §4 chrome lands.
|
||||||
// deferred until the §4 chrome lands.
|
|
||||||
func (st *uiState) notifyAttention(childID, reason string) {
|
func (st *uiState) notifyAttention(childID, reason string) {
|
||||||
c := st.sess.FindChild(childID)
|
c := st.sess.FindChild(childID)
|
||||||
name := childID
|
name := childID
|
||||||
if c != nil {
|
if c != nil {
|
||||||
name = c.DisplayName()
|
name = c.DisplayName()
|
||||||
}
|
}
|
||||||
st.mu.Lock()
|
st.notifyToast(toastAttention, fmt.Sprintf("%s — %s", name, reason))
|
||||||
st.attentionText = fmt.Sprintf("attention: %s — %s", name, reason)
|
|
||||||
st.attentionAt = childID
|
|
||||||
st.mu.Unlock()
|
|
||||||
st.drawStatusLine()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *uiState) scratchpadsChanged() {
|
func (st *uiState) scratchpadsChanged() {
|
||||||
@@ -973,14 +967,19 @@ func (st *uiState) OnPTYOut(childID string, chunk []byte) {
|
|||||||
st.metrics.recordRender(time.Since(rstart))
|
st.metrics.recordRender(time.Since(rstart))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// One write covers the autowrap-disable prelude, the chunk, and the
|
// One write covers the autowrap-disable prelude, the chunk, the
|
||||||
// autowrap-restore postlude — three syscalls collapsed into one
|
// autowrap-restore postlude, and (when a toast is up) the toast
|
||||||
// under outMu. The three sequences were already emitted atomically
|
// overlay — four syscalls collapsed into one under outMu. The
|
||||||
// under the lock; coalescing just halves the syscall count.
|
// sequences were already emitted atomically under the lock;
|
||||||
wrapped := make([]byte, 0, len(out)+10)
|
// coalescing just halves the syscall count and makes claude's
|
||||||
|
// continuous redraws + our toast layer land in the same frame so
|
||||||
|
// the box doesn't flicker as the child paints over its cells.
|
||||||
|
overlay := st.toastOverlayBytes()
|
||||||
|
wrapped := make([]byte, 0, len(out)+len(overlay)+10)
|
||||||
wrapped = append(wrapped, "\x1b[?7l"...)
|
wrapped = append(wrapped, "\x1b[?7l"...)
|
||||||
wrapped = append(wrapped, out...)
|
wrapped = append(wrapped, out...)
|
||||||
wrapped = append(wrapped, "\x1b[?7h"...)
|
wrapped = append(wrapped, "\x1b[?7h"...)
|
||||||
|
wrapped = append(wrapped, overlay...)
|
||||||
var wstart time.Time
|
var wstart time.Time
|
||||||
if st.metrics != nil {
|
if st.metrics != nil {
|
||||||
wstart = time.Now()
|
wstart = time.Now()
|
||||||
@@ -1167,8 +1166,6 @@ func (st *uiState) drawStatusLine() {
|
|||||||
palOpen := st.palette != nil
|
palOpen := st.palette != nil
|
||||||
focusID := st.focusedID
|
focusID := st.focusedID
|
||||||
focusName := st.focusedName
|
focusName := st.focusedName
|
||||||
attention := st.attentionText
|
|
||||||
attentionAt := st.attentionAt
|
|
||||||
var trustMsg string
|
var trustMsg string
|
||||||
if st.pendingTrust != nil {
|
if st.pendingTrust != nil {
|
||||||
trustMsg = fmt.Sprintf("trust preset %q? [y]es / [n]o", st.pendingTrust.presetName)
|
trustMsg = fmt.Sprintf("trust preset %q? [y]es / [n]o", st.pendingTrust.presetName)
|
||||||
@@ -1208,13 +1205,6 @@ func (st *uiState) drawStatusLine() {
|
|||||||
left = owner
|
left = owner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if attention != "" && attentionAt == focusID {
|
|
||||||
left = "[!] " + attention
|
|
||||||
}
|
|
||||||
if attention != "" && attentionAt == "" {
|
|
||||||
// Sticky attention/flash from somewhere outside the focused pane.
|
|
||||||
left = "[!] " + attention
|
|
||||||
}
|
|
||||||
if trustMsg != "" {
|
if trustMsg != "" {
|
||||||
left = "[trust] " + trustMsg
|
left = "[trust] " + trustMsg
|
||||||
}
|
}
|
||||||
@@ -1232,6 +1222,12 @@ func (st *uiState) drawStatusLine() {
|
|||||||
hints = append(hints, "Ctrl-R · restart")
|
hints = append(hints, "Ctrl-R · restart")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Surface the toast-dismiss chord only while a notification is on
|
||||||
|
// screen — the hint is noise otherwise, and Ctrl-N falls through
|
||||||
|
// to the focused PTY when the stack is empty.
|
||||||
|
if st.toasts.length() > 0 {
|
||||||
|
hints = append(hints, "Ctrl-N · dismiss")
|
||||||
|
}
|
||||||
right := strings.Join(hints, " · ")
|
right := strings.Join(hints, " · ")
|
||||||
for len(hints) > 1 && int(cols)-len(left)-len(right) < 1 {
|
for len(hints) > 1 && int(cols)-len(left)-len(right) < 1 {
|
||||||
hints = hints[1:]
|
hints = hints[1:]
|
||||||
@@ -1270,8 +1266,6 @@ func (st *uiState) drawStatusLine() {
|
|||||||
// child is focused.
|
// child is focused.
|
||||||
func (st *uiState) renderEmptyState() {
|
func (st *uiState) renderEmptyState() {
|
||||||
layout := st.layoutSnapshot()
|
layout := st.layoutSnapshot()
|
||||||
st.outMu.Lock()
|
|
||||||
defer st.outMu.Unlock()
|
|
||||||
line := "Press Ctrl-K to spawn an agent or process"
|
line := "Press Ctrl-K to spawn an agent or process"
|
||||||
row := int(layout.mainTop) + (int(layout.childRows()) / 2)
|
row := int(layout.mainTop) + (int(layout.childRows()) / 2)
|
||||||
col := int(layout.mainLeft) + ((int(layout.childCols()) - len(line)) / 2)
|
col := int(layout.mainLeft) + ((int(layout.childCols()) - len(line)) / 2)
|
||||||
@@ -1281,7 +1275,10 @@ func (st *uiState) renderEmptyState() {
|
|||||||
if col < int(layout.mainLeft) {
|
if col < int(layout.mainLeft) {
|
||||||
col = int(layout.mainLeft)
|
col = int(layout.mainLeft)
|
||||||
}
|
}
|
||||||
|
st.outMu.Lock()
|
||||||
fmt.Fprintf(os.Stdout, "\x1b[?25l\x1b[H\x1b[2J\x1b[%d;%dH\x1b[2m%s\x1b[0m", row, col, line)
|
fmt.Fprintf(os.Stdout, "\x1b[?25l\x1b[H\x1b[2J\x1b[%d;%dH\x1b[2m%s\x1b[0m", row, col, line)
|
||||||
|
st.outMu.Unlock()
|
||||||
|
st.renderToasts()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *uiState) hostSizeSnapshot() (uint16, uint16) {
|
func (st *uiState) hostSizeSnapshot() (uint16, uint16) {
|
||||||
@@ -1412,6 +1409,7 @@ func (st *uiState) processStdin(chunk []byte) {
|
|||||||
var pendingViewportBottom bool
|
var pendingViewportBottom bool
|
||||||
var pendingPadStep int
|
var pendingPadStep int
|
||||||
var pendingPadExit bool
|
var pendingPadExit bool
|
||||||
|
var pendingDismissToast bool
|
||||||
|
|
||||||
flushForward := func() {
|
flushForward := func() {
|
||||||
if len(forward) == 0 {
|
if len(forward) == 0 {
|
||||||
@@ -1598,6 +1596,11 @@ func (st *uiState) processStdin(chunk []byte) {
|
|||||||
} else if hit, _ := matchCtrlChar(chunk, i, 'd'); hit {
|
} else if hit, _ := matchCtrlChar(chunk, i, 'd'); hit {
|
||||||
} else if hit, _ := matchCtrlChar(chunk, i, 'w'); hit {
|
} else if hit, _ := matchCtrlChar(chunk, i, 'w'); hit {
|
||||||
} else if hit, _ := matchCtrlChar(chunk, i, 's'); hit {
|
} else if hit, _ := matchCtrlChar(chunk, i, 's'); hit {
|
||||||
|
} else if hit, _ := matchCtrlChar(chunk, i, 'n'); hit {
|
||||||
|
// Ctrl-N is the toast dismiss key. In pad view we
|
||||||
|
// allow it through the chord block so the handler
|
||||||
|
// below can fire even though pads otherwise swallow
|
||||||
|
// bytes.
|
||||||
} else {
|
} else {
|
||||||
i++
|
i++
|
||||||
continue
|
continue
|
||||||
@@ -1696,6 +1699,22 @@ func (st *uiState) processStdin(chunk []byte) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Ctrl-N dismisses the most recent toast. We only consume the
|
||||||
|
// chord when there's actually a toast to dismiss; otherwise the
|
||||||
|
// bytes fall through to the focused PTY so readline /
|
||||||
|
// nano / emacs / opencode keep working in shells and editors.
|
||||||
|
if hit, adv := matchCtrlChar(chunk, i, 'n'); hit {
|
||||||
|
if st.toasts.length() > 0 {
|
||||||
|
flushForward()
|
||||||
|
pendingDismissToast = true
|
||||||
|
i += adv
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
forward = append(forward, chunk[i:i+adv]...)
|
||||||
|
i += adv
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Ctrl-B snaps the focused child's emulator viewport back to the
|
// Ctrl-B snaps the focused child's emulator viewport back to the
|
||||||
// active area. Use this as the escape hatch from a scrolled-up
|
// active area. Use this as the escape hatch from a scrolled-up
|
||||||
// state — wheel scrolls move the viewport into the libghostty
|
// state — wheel scrolls move the viewport into the libghostty
|
||||||
@@ -1777,6 +1796,11 @@ func (st *uiState) processStdin(chunk []byte) {
|
|||||||
if pendingPadExit {
|
if pendingPadExit {
|
||||||
st.exitPadView()
|
st.exitPadView()
|
||||||
}
|
}
|
||||||
|
if pendingDismissToast {
|
||||||
|
if st.toasts.dismissTop() {
|
||||||
|
st.refreshToastSurface()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// scrollFocusedViewport scrolls the focused child's emulator viewport by
|
// scrollFocusedViewport scrolls the focused child's emulator viewport by
|
||||||
@@ -1985,6 +2009,11 @@ func (st *uiState) closePalette(action paletteAction) {
|
|||||||
case "quit":
|
case "quit":
|
||||||
st.requestExit()
|
st.requestExit()
|
||||||
|
|
||||||
|
case "toasts-clear":
|
||||||
|
if st.toasts.clear() {
|
||||||
|
st.refreshToastSurface()
|
||||||
|
}
|
||||||
|
|
||||||
case "pad-delete":
|
case "pad-delete":
|
||||||
st.handlePadDelete(action.padName)
|
st.handlePadDelete(action.padName)
|
||||||
|
|
||||||
@@ -2261,28 +2290,18 @@ func (st *uiState) handleProcRestart(childID string) {
|
|||||||
st.drawStatusLine()
|
st.drawStatusLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
// flashError surfaces a spawn/etc. failure in the status line until the
|
// flashError surfaces a spawn/etc. failure as an error toast over the
|
||||||
// next attention update overwrites it. stderr is hidden under the alt
|
// focused pane. stderr is hidden under the alt screen so we can't rely
|
||||||
// screen so we can't rely on Fprintln(os.Stderr).
|
// on Fprintln(os.Stderr).
|
||||||
func (st *uiState) flashError(msg string) {
|
func (st *uiState) flashError(msg string) {
|
||||||
st.mu.Lock()
|
st.notifyToast(toastError, msg)
|
||||||
st.attentionText = msg
|
|
||||||
st.attentionAt = "" // shows on every focus until cleared
|
|
||||||
st.mu.Unlock()
|
|
||||||
st.renderEmptyState()
|
|
||||||
st.drawTabBar()
|
|
||||||
st.drawSidebar()
|
|
||||||
st.drawStatusLine()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// flashTransient is the softer cousin of flashError used for
|
// flashTransient is the softer cousin of flashError used for
|
||||||
// trust-prompt resolutions. Same status-line surface; the prefix differs.
|
// trust-prompt resolutions and other ack-style notices. Same
|
||||||
|
// stackable surface, info styling.
|
||||||
func (st *uiState) flashTransient(msg string) {
|
func (st *uiState) flashTransient(msg string) {
|
||||||
st.mu.Lock()
|
st.notifyToast(toastInfo, msg)
|
||||||
st.attentionText = msg
|
|
||||||
st.attentionAt = ""
|
|
||||||
st.mu.Unlock()
|
|
||||||
st.drawStatusLine()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// repaintFocused redraws the current focused child's screen snapshot.
|
// repaintFocused redraws the current focused child's screen snapshot.
|
||||||
@@ -2326,8 +2345,9 @@ func (st *uiState) repaintFocused() {
|
|||||||
}
|
}
|
||||||
st.mu.Unlock()
|
st.mu.Unlock()
|
||||||
st.outMu.Lock()
|
st.outMu.Lock()
|
||||||
defer st.outMu.Unlock()
|
|
||||||
_, _ = os.Stdout.Write(out)
|
_, _ = os.Stdout.Write(out)
|
||||||
|
st.outMu.Unlock()
|
||||||
|
st.renderToasts()
|
||||||
}
|
}
|
||||||
|
|
||||||
// repaintFocusedPad paints the focused scratchpad's content into the
|
// repaintFocusedPad paints the focused scratchpad's content into the
|
||||||
@@ -2351,8 +2371,9 @@ func (st *uiState) repaintFocusedPad() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
st.outMu.Lock()
|
st.outMu.Lock()
|
||||||
defer st.outMu.Unlock()
|
|
||||||
_, _ = os.Stdout.Write(out)
|
_, _ = os.Stdout.Write(out)
|
||||||
|
st.outMu.Unlock()
|
||||||
|
st.renderToasts()
|
||||||
}
|
}
|
||||||
|
|
||||||
// renderPadView builds the bytes that paint a scratchpad's content
|
// renderPadView builds the bytes that paint a scratchpad's content
|
||||||
|
|||||||
@@ -54,14 +54,6 @@ const (
|
|||||||
groupQuit
|
groupQuit
|
||||||
)
|
)
|
||||||
|
|
||||||
var groupLabels = map[int]string{
|
|
||||||
groupFocused: "Focused",
|
|
||||||
groupOpen: "Open",
|
|
||||||
groupSpawn: "Spawn",
|
|
||||||
groupSettings: "Settings",
|
|
||||||
groupQuit: "Quit",
|
|
||||||
}
|
|
||||||
|
|
||||||
type paletteItem struct {
|
type paletteItem struct {
|
||||||
label string
|
label string
|
||||||
hint string
|
hint string
|
||||||
@@ -205,8 +197,10 @@ func (p *paletteState) rebuild() {
|
|||||||
all := p.buildItems(macro)
|
all := p.buildItems(macro)
|
||||||
|
|
||||||
if rest == "" {
|
if rest == "" {
|
||||||
// No textual filter: render with section headers between groups.
|
// No textual filter: render with blank spacer rows between
|
||||||
p.items = itemsWithHeaders(all)
|
// groups so sections read as scannable bands without dashed
|
||||||
|
// headers stealing visual weight.
|
||||||
|
p.items = itemsWithSpacers(all)
|
||||||
p.clampCursor()
|
p.clampCursor()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -243,25 +237,28 @@ func (p *paletteState) rebuild() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buildItems assembles every selectable row in fixed group order
|
// buildItems assembles every selectable row in fixed group order
|
||||||
// (Focused → Open → Spawn → Quit). Headers are added by
|
// (Focused → Open → Spawn → Quit). Blank spacer rows are added by
|
||||||
// itemsWithHeaders for the no-query case; scored mode drops them.
|
// itemsWithSpacers for the no-query case; scored mode drops them.
|
||||||
// When macro is non-empty the result is filtered down to the kinds
|
// When macro is non-empty the result is filtered down to the kinds
|
||||||
// that macro retains.
|
// that macro retains.
|
||||||
func (p *paletteState) buildItems(macro string) []paletteItem {
|
func (p *paletteState) buildItems(macro string) []paletteItem {
|
||||||
var out []paletteItem
|
var out []paletteItem
|
||||||
|
|
||||||
// Group 0: Focused — context-aware actions for whatever owns focus.
|
// Group 0: Focused — context-aware actions for whatever owns focus.
|
||||||
// A focused scratchpad shadows any focused child.
|
// A focused scratchpad shadows any focused child. Labels are bare
|
||||||
|
// verbs because the title bar already carries the subject ("on:
|
||||||
|
// codex" / "pad: notes.md"); the noun + name move into the hint so
|
||||||
|
// fuzzy queries like "close codex" still surface the row.
|
||||||
switch {
|
switch {
|
||||||
case p.focusedPad != "":
|
case p.focusedPad != "":
|
||||||
name := p.focusedPad
|
name := p.focusedPad
|
||||||
out = append(out,
|
out = append(out,
|
||||||
paletteItem{label: "Delete scratchpad: " + name, hint: "remove the file from disk",
|
paletteItem{label: "Edit", hint: "edit scratchpad · " + name + " (opens $EDITOR)",
|
||||||
action: paletteAction{kind: "pad-delete", padName: name}, group: groupFocused},
|
|
||||||
paletteItem{label: "Rename scratchpad: " + name, hint: "inline rename · enter to commit",
|
|
||||||
action: paletteAction{kind: "pad-rename-form", padName: name}, group: groupFocused},
|
|
||||||
paletteItem{label: "Edit scratchpad: " + name, hint: "open in external editor (zed)",
|
|
||||||
action: paletteAction{kind: "pad-edit", padName: name}, group: groupFocused},
|
action: paletteAction{kind: "pad-edit", padName: name}, group: groupFocused},
|
||||||
|
paletteItem{label: "Rename", hint: "rename scratchpad · " + name,
|
||||||
|
action: paletteAction{kind: "pad-rename-form", padName: name}, group: groupFocused},
|
||||||
|
paletteItem{label: "Delete", hint: "delete scratchpad · " + name,
|
||||||
|
action: paletteAction{kind: "pad-delete", padName: name}, group: groupFocused},
|
||||||
)
|
)
|
||||||
case p.focused != "":
|
case p.focused != "":
|
||||||
if c := findChildByID(p.children, p.focused); c != nil {
|
if c := findChildByID(p.children, p.focused); c != nil {
|
||||||
@@ -269,40 +266,39 @@ func (p *paletteState) buildItems(macro string) []paletteItem {
|
|||||||
switch c.Kind {
|
switch c.Kind {
|
||||||
case KindAgent:
|
case KindAgent:
|
||||||
out = append(out,
|
out = append(out,
|
||||||
paletteItem{label: "Rename agent: " + name, hint: "inline rename · enter to commit",
|
paletteItem{label: "Rename", hint: "rename agent · " + name,
|
||||||
action: paletteAction{kind: "agent-rename-form", childID: c.ID}, group: groupFocused},
|
action: paletteAction{kind: "agent-rename-form", childID: c.ID}, group: groupFocused},
|
||||||
paletteItem{label: "Close agent: " + name, hint: "SIGTERM " + strings.Join(c.Argv, " "),
|
paletteItem{label: "Close", hint: "close agent · " + name + " (SIGTERM)",
|
||||||
action: paletteAction{kind: "agent-close", childID: c.ID}, group: groupFocused},
|
action: paletteAction{kind: "agent-close", childID: c.ID}, group: groupFocused},
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
out = append(out,
|
out = append(out,
|
||||||
paletteItem{label: "Rename process: " + name, hint: "inline rename · enter to commit",
|
paletteItem{label: "Rename", hint: "rename process · " + name,
|
||||||
action: paletteAction{kind: "proc-rename-form", childID: c.ID}, group: groupFocused},
|
action: paletteAction{kind: "proc-rename-form", childID: c.ID}, group: groupFocused},
|
||||||
paletteItem{label: "Delete process: " + name, hint: "remove entry; SIGKILL if alive",
|
paletteItem{label: "Stop", hint: "stop process · " + name + " (SIGTERM, keeps entry)",
|
||||||
action: paletteAction{kind: "proc-delete", childID: c.ID}, group: groupFocused},
|
|
||||||
paletteItem{label: "Stop process: " + name, hint: "SIGTERM · keep entry for restart",
|
|
||||||
action: paletteAction{kind: "proc-stop", childID: c.ID}, group: groupFocused},
|
action: paletteAction{kind: "proc-stop", childID: c.ID}, group: groupFocused},
|
||||||
paletteItem{label: "Restart process: " + name, hint: "SIGTERM then start with same argv",
|
paletteItem{label: "Restart", hint: "restart process · " + name,
|
||||||
action: paletteAction{kind: "proc-restart", childID: c.ID}, group: groupFocused},
|
action: paletteAction{kind: "proc-restart", childID: c.ID}, group: groupFocused},
|
||||||
|
paletteItem{label: "Delete", hint: "delete process · " + name + " (SIGKILL if alive)",
|
||||||
|
action: paletteAction{kind: "proc-delete", childID: c.ID}, group: groupFocused},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group 1: Open — switch entries for every running child. Dead
|
// Group 1: Open — switch entries for every running child *other than*
|
||||||
|
// the one already focused (no point offering a no-op switch). Dead
|
||||||
// agents are filtered out (no restart path); dead command processes
|
// agents are filtered out (no restart path); dead command processes
|
||||||
// remain so they can be restarted. The currently-focused child is
|
// remain so they can be restarted.
|
||||||
// marked with a leading ▶ instead of the older "• … (current)" suffix
|
|
||||||
// so the row reads cleaner.
|
|
||||||
for _, c := range p.children {
|
for _, c := range p.children {
|
||||||
|
if c.ID == p.focused {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if c.Kind == KindAgent && c.Status() != StatusRunning {
|
if c.Kind == KindAgent && c.Status() != StatusRunning {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
label := "Switch to " + c.DisplayName()
|
label := "Switch to " + c.DisplayName()
|
||||||
hint := strings.Join(c.Argv, " ")
|
hint := strings.Join(c.Argv, " ")
|
||||||
if c.ID == p.focused {
|
|
||||||
label = "▶ " + label
|
|
||||||
}
|
|
||||||
if c.Status() != StatusRunning {
|
if c.Status() != StatusRunning {
|
||||||
label = label + " [" + string(c.Status()) + "]"
|
label = label + " [" + string(c.Status()) + "]"
|
||||||
}
|
}
|
||||||
@@ -353,6 +349,12 @@ func (p *paletteState) buildItems(macro string) []paletteItem {
|
|||||||
action: paletteAction{kind: "settings-open"},
|
action: paletteAction{kind: "settings-open"},
|
||||||
group: groupSettings,
|
group: groupSettings,
|
||||||
})
|
})
|
||||||
|
out = append(out, paletteItem{
|
||||||
|
label: "Clear notifications",
|
||||||
|
hint: "dismiss all toasts in the top-right of the focused pane",
|
||||||
|
action: paletteAction{kind: "toasts-clear"},
|
||||||
|
group: groupSettings,
|
||||||
|
})
|
||||||
|
|
||||||
// Group 4: Quit.
|
// Group 4: Quit.
|
||||||
out = append(out, paletteItem{
|
out = append(out, paletteItem{
|
||||||
@@ -378,9 +380,11 @@ func (p *paletteState) buildItems(macro string) []paletteItem {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// itemsWithHeaders splices a non-selectable header row in front of
|
// itemsWithSpacers splices a non-selectable blank row between groups
|
||||||
// each new group so the (unfiltered) list reads as scannable bands.
|
// so the (unfiltered) list reads as scannable bands without dashed
|
||||||
func itemsWithHeaders(items []paletteItem) []paletteItem {
|
// section headers stealing weight from the actions themselves. The
|
||||||
|
// first group never gets a leading spacer.
|
||||||
|
func itemsWithSpacers(items []paletteItem) []paletteItem {
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -388,16 +392,13 @@ func itemsWithHeaders(items []paletteItem) []paletteItem {
|
|||||||
currentGroup := -1
|
currentGroup := -1
|
||||||
for _, it := range items {
|
for _, it := range items {
|
||||||
if it.group != currentGroup {
|
if it.group != currentGroup {
|
||||||
currentGroup = it.group
|
if currentGroup != -1 {
|
||||||
label, ok := groupLabels[it.group]
|
result = append(result, paletteItem{
|
||||||
if !ok {
|
action: paletteAction{kind: "header"},
|
||||||
label = ""
|
group: it.group,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
result = append(result, paletteItem{
|
currentGroup = it.group
|
||||||
label: "── " + label + " ──",
|
|
||||||
action: paletteAction{kind: "header"},
|
|
||||||
group: it.group,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
result = append(result, it)
|
result = append(result, it)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,16 +31,17 @@ func findItem(p *paletteState, want string) (int, *paletteItem) {
|
|||||||
|
|
||||||
func TestContextItemsScratchpad(t *testing.T) {
|
func TestContextItemsScratchpad(t *testing.T) {
|
||||||
p := newPalette(nil, "", "notes.md", preset.Set{})
|
p := newPalette(nil, "", "notes.md", preset.Set{})
|
||||||
// pad-delete is the first selectable row; the Focused section header
|
// With the dashed section header gone, pad-edit is the first row;
|
||||||
// (a non-selectable row) sits above it.
|
// pad-rename-form follows, with destructive pad-delete last in the
|
||||||
if i, _ := findItem(p, "pad-delete"); i != 1 {
|
// Focused section.
|
||||||
t.Fatalf("pad-delete at %d; want 1 (after Focused header)", i)
|
if i, _ := findItem(p, "pad-edit"); i != 0 {
|
||||||
|
t.Fatalf("pad-edit at %d; want 0", i)
|
||||||
}
|
}
|
||||||
if _, it := findItem(p, "pad-rename-form"); it == nil || it.action.padName != "notes.md" {
|
if _, it := findItem(p, "pad-rename-form"); it == nil || it.action.padName != "notes.md" {
|
||||||
t.Fatalf("pad-rename-form missing or wrong padName: %+v", it)
|
t.Fatalf("pad-rename-form missing or wrong padName: %+v", it)
|
||||||
}
|
}
|
||||||
if _, it := findItem(p, "pad-edit"); it == nil {
|
if i, _ := findItem(p, "pad-delete"); i < 0 {
|
||||||
t.Fatalf("pad-edit missing")
|
t.Fatalf("pad-delete missing")
|
||||||
}
|
}
|
||||||
// No focused child → no agent/proc context items.
|
// No focused child → no agent/proc context items.
|
||||||
if i, _ := findItem(p, "agent-rename-form"); i != -1 {
|
if i, _ := findItem(p, "agent-rename-form"); i != -1 {
|
||||||
@@ -83,8 +84,11 @@ func TestContextItemsProcess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestContextItemsAppearAboveSwitch(t *testing.T) {
|
func TestContextItemsAppearAboveSwitch(t *testing.T) {
|
||||||
c := makeFakeChild("pid", "devserver", KindCommand)
|
// Two children so there's still a non-focused switch entry to compare
|
||||||
p := newPalette([]*Child{c}, "pid", "", preset.Set{})
|
// against (the focused child is suppressed from the Open section).
|
||||||
|
focused := makeFakeChild("pid", "devserver", KindCommand)
|
||||||
|
other := makeFakeChild("oid", "worker", KindCommand)
|
||||||
|
p := newPalette([]*Child{focused, other}, "pid", "", preset.Set{})
|
||||||
procIdx, _ := findItem(p, "proc-rename-form")
|
procIdx, _ := findItem(p, "proc-rename-form")
|
||||||
switchIdx, _ := findItem(p, "switch")
|
switchIdx, _ := findItem(p, "switch")
|
||||||
if procIdx < 0 || switchIdx < 0 {
|
if procIdx < 0 || switchIdx < 0 {
|
||||||
|
|||||||
@@ -57,22 +57,45 @@ func TestPaletteDropsGlobalCloseList(t *testing.T) {
|
|||||||
|
|
||||||
// -- Phase 2: section headers and cursor skip ------------------------
|
// -- Phase 2: section headers and cursor skip ------------------------
|
||||||
|
|
||||||
func TestPaletteSectionHeadersPresent(t *testing.T) {
|
func TestPaletteSectionsSeparatedBySpacers(t *testing.T) {
|
||||||
|
// Section-named dashed headers are gone; groups are visually
|
||||||
|
// separated by a single non-selectable blank row. Verify that the
|
||||||
|
// build emits one such spacer between every pair of adjacent groups
|
||||||
|
// and never a leading spacer.
|
||||||
c := makeFakeChild("a", "claude", KindAgent)
|
c := makeFakeChild("a", "claude", KindAgent)
|
||||||
p := newPalette([]*Child{c}, "a", "", preset.Set{Agents: []*preset.Preset{{Name: "codex"}}})
|
other := makeFakeChild("b", "worker", KindCommand)
|
||||||
wantSections := []string{"Focused", "Open", "Spawn", "Quit"}
|
p := newPalette([]*Child{c, other}, "a", "",
|
||||||
for _, w := range wantSections {
|
preset.Set{Agents: []*preset.Preset{{Name: "codex"}}})
|
||||||
found := false
|
|
||||||
for _, it := range p.items {
|
if len(p.items) == 0 {
|
||||||
if it.action.kind == "header" && strings.Contains(it.label, w) {
|
t.Fatalf("palette built no items")
|
||||||
found = true
|
}
|
||||||
break
|
if p.items[0].action.kind == "header" {
|
||||||
|
t.Fatalf("first row is a spacer; should be a selectable item")
|
||||||
|
}
|
||||||
|
transitions := 0
|
||||||
|
prevGroup := p.items[0].group
|
||||||
|
for i := 1; i < len(p.items); i++ {
|
||||||
|
it := p.items[i]
|
||||||
|
if it.group != prevGroup {
|
||||||
|
if it.action.kind != "header" || it.label != "" {
|
||||||
|
t.Fatalf("group transition at %d not a blank spacer: %+v", i, it)
|
||||||
}
|
}
|
||||||
|
transitions++
|
||||||
|
// The row immediately after the spacer must be selectable.
|
||||||
|
if i+1 >= len(p.items) || p.items[i+1].action.kind == "header" {
|
||||||
|
t.Fatalf("spacer at %d not followed by selectable row", i)
|
||||||
|
}
|
||||||
|
prevGroup = p.items[i+1].group
|
||||||
}
|
}
|
||||||
if !found {
|
// No dashed banners anywhere.
|
||||||
t.Errorf("section header %q missing from items", w)
|
if it.action.kind == "header" && strings.Contains(it.label, "──") {
|
||||||
|
t.Errorf("dashed section header still present at %d: %q", i, it.label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if transitions == 0 {
|
||||||
|
t.Fatalf("no section transitions found in palette items")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPaletteCursorSkipsHeaders(t *testing.T) {
|
func TestPaletteCursorSkipsHeaders(t *testing.T) {
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ func runSummarizerCommand(ctx context.Context, cfg autoSummarySettings, projectD
|
|||||||
case "claude":
|
case "claude":
|
||||||
cmd = exec.CommandContext(ctx, "claude", "--print", "--model", model, prompt)
|
cmd = exec.CommandContext(ctx, "claude", "--print", "--model", model, prompt)
|
||||||
default:
|
default:
|
||||||
cmd = exec.CommandContext(ctx, "codex", "exec", "--ephemeral", "--skip-git-repo-check", "--sandbox", "read-only", "--ask-for-approval", "never", "--model", model, "-")
|
cmd = exec.CommandContext(ctx, "codex", "exec", "--ephemeral", "--skip-git-repo-check", "--sandbox", "read-only", "--model", model, "-")
|
||||||
cmd.Stdin = strings.NewReader(prompt)
|
cmd.Stdin = strings.NewReader(prompt)
|
||||||
}
|
}
|
||||||
cmd.Dir = projectDir
|
cmd.Dir = projectDir
|
||||||
|
|||||||
361
internal/app/toast.go
Normal file
361
internal/app/toast.go
Normal file
@@ -0,0 +1,361 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// toastKind classifies a toast for styling and for migrating the
|
||||||
|
// pre-existing flashError / flashTransient / notifyAttention call
|
||||||
|
// sites onto the new stack.
|
||||||
|
type toastKind int
|
||||||
|
|
||||||
|
const (
|
||||||
|
toastInfo toastKind = iota
|
||||||
|
toastError
|
||||||
|
toastAttention
|
||||||
|
)
|
||||||
|
|
||||||
|
// toast is one entry in the host-level notification stack. Toasts
|
||||||
|
// persist until the user dismisses them with Ctrl-N or the
|
||||||
|
// "Clear notifications" palette command — there's no auto-expiry.
|
||||||
|
type toast struct {
|
||||||
|
id uint64
|
||||||
|
kind toastKind
|
||||||
|
text string
|
||||||
|
}
|
||||||
|
|
||||||
|
// toastStackCap caps how many toasts can be visible at once.
|
||||||
|
// Older entries drop off the bottom when a new push would exceed it.
|
||||||
|
const toastStackCap = 5
|
||||||
|
|
||||||
|
// toastBoxMaxWidth bounds the rendered box width so a wide pane
|
||||||
|
// doesn't produce huge toasts. Boxes shrink below this when the pane
|
||||||
|
// is narrow.
|
||||||
|
const toastBoxMaxWidth = 50
|
||||||
|
|
||||||
|
// toastBoxMinWidth is the floor below which we refuse to render —
|
||||||
|
// any narrower and there's not enough room for borders + content.
|
||||||
|
const toastBoxMinWidth = 20
|
||||||
|
|
||||||
|
// toastContentRows is how many lines of message body each toast box
|
||||||
|
// reserves. The dismiss hint lives on the host status strip, so the
|
||||||
|
// box itself is purely the message.
|
||||||
|
const toastContentRows = 3
|
||||||
|
|
||||||
|
// toastStack owns the ordered list of live toasts. Oldest at
|
||||||
|
// index 0, newest (visually topmost) at the end. The stack's own
|
||||||
|
// mutex is intentionally separate from uiState.mu so push / dismiss
|
||||||
|
// can be called from any goroutine without participating in the
|
||||||
|
// host's bigger lock-ordering rules.
|
||||||
|
type toastStack struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
items []toast
|
||||||
|
next uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *toastStack) push(kind toastKind, text string) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
s.next++
|
||||||
|
s.items = append(s.items, toast{id: s.next, kind: kind, text: text})
|
||||||
|
if len(s.items) > toastStackCap {
|
||||||
|
s.items = s.items[len(s.items)-toastStackCap:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// dismissTop pops the most recent toast (the one rendered at the
|
||||||
|
// top of the stack). Returns true if something was removed so
|
||||||
|
// callers can decide whether to repaint.
|
||||||
|
func (s *toastStack) dismissTop() bool {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
if len(s.items) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
s.items = s.items[:len(s.items)-1]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *toastStack) clear() bool {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
if len(s.items) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
s.items = s.items[:0]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *toastStack) snapshot() []toast {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
if len(s.items) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := make([]toast, len(s.items))
|
||||||
|
copy(out, s.items)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *toastStack) length() int {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return len(s.items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// notifyToast is the single entry point that the former flash
|
||||||
|
// helpers now delegate to. It pushes onto the stack and triggers a
|
||||||
|
// repaint of the focused surface so the new toast appears
|
||||||
|
// immediately; the repaint path also re-renders the stack on top.
|
||||||
|
func (st *uiState) notifyToast(kind toastKind, text string) {
|
||||||
|
st.toasts.push(kind, text)
|
||||||
|
st.refreshToastSurface()
|
||||||
|
}
|
||||||
|
|
||||||
|
// refreshToastSurface re-renders whatever surface the toasts are
|
||||||
|
// drawn over (focused child, focused pad, or the empty-state
|
||||||
|
// canvas). Each of those paths calls renderToasts at the end, so
|
||||||
|
// the toast layer is always reapplied on top of a freshly-drawn
|
||||||
|
// pane. Centralised so push / dismiss / clear share one code path.
|
||||||
|
//
|
||||||
|
// The status strip also gains/loses the "Ctrl-N · dismiss" hint as
|
||||||
|
// the stack toggles between empty and non-empty, so we redraw it
|
||||||
|
// here too rather than waiting for the chrome ticker.
|
||||||
|
func (st *uiState) refreshToastSurface() {
|
||||||
|
st.mu.Lock()
|
||||||
|
focusedPad := st.focusedPad
|
||||||
|
focusedID := st.focusedID
|
||||||
|
palOpen := st.palette != nil
|
||||||
|
st.mu.Unlock()
|
||||||
|
if palOpen {
|
||||||
|
// Palette owns the whole screen while it's open; toasts will
|
||||||
|
// repaint via closePalette's restore path.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case focusedPad != "":
|
||||||
|
st.repaintFocusedPad()
|
||||||
|
case focusedID != "":
|
||||||
|
st.repaintFocused()
|
||||||
|
default:
|
||||||
|
st.renderEmptyState()
|
||||||
|
}
|
||||||
|
st.drawStatusLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
// renderToasts draws the toast stack over the top-right of the
|
||||||
|
// focused pane. Called from repaintFocused / repaintFocusedPad /
|
||||||
|
// renderEmptyState after they finish so toasts always sit on top of
|
||||||
|
// freshly-redrawn pane content. Safe to call when the stack is
|
||||||
|
// empty (no-op).
|
||||||
|
func (st *uiState) renderToasts() {
|
||||||
|
bytes := st.toastOverlayBytes()
|
||||||
|
if len(bytes) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
st.outMu.Lock()
|
||||||
|
defer st.outMu.Unlock()
|
||||||
|
_, _ = os.Stdout.Write(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// toastOverlayBytes builds the toast layer as a single byte buffer
|
||||||
|
// without writing to stdout. Returns nil when the stack is empty or
|
||||||
|
// the layout can't accommodate a box. Callers either write it
|
||||||
|
// directly (renderToasts) or stitch it onto the end of another
|
||||||
|
// stdout write so claude/codex/opencode redraws that paint over the
|
||||||
|
// top-right region can't leave the toast half-erased.
|
||||||
|
func (st *uiState) toastOverlayBytes() []byte {
|
||||||
|
items := st.toasts.snapshot()
|
||||||
|
if len(items) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
st.mu.Lock()
|
||||||
|
palOpen := st.palette != nil
|
||||||
|
st.mu.Unlock()
|
||||||
|
if palOpen {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
layout := st.layoutSnapshot()
|
||||||
|
paneCols := int(layout.childCols())
|
||||||
|
paneRows := int(layout.childRows())
|
||||||
|
if paneCols < toastBoxMinWidth+2 || paneRows < toastContentRows+2 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
boxWidth := toastBoxMaxWidth
|
||||||
|
if max := paneCols - 4; max < boxWidth {
|
||||||
|
boxWidth = max
|
||||||
|
}
|
||||||
|
if boxWidth < toastBoxMinWidth {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
contentWidth := boxWidth - 4 // 2 border cells + 2 inner padding
|
||||||
|
// Reserve two columns for the icon prefix on row 1 so wrapped rows
|
||||||
|
// indent under the body text rather than under the glyph.
|
||||||
|
const iconCols = 2
|
||||||
|
bodyRoom := contentWidth - iconCols
|
||||||
|
if bodyRoom < 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var b strings.Builder
|
||||||
|
// Wrap the whole overlay in DECSET 2026 (synchronized output)
|
||||||
|
// brackets so terminals that support BSU/ESU buffer the box paint
|
||||||
|
// into a single frame — without this, claude's continuous redraws
|
||||||
|
// and our overlay race on each cell, producing visible flicker.
|
||||||
|
// Terminals that don't recognise 2026 ignore the brackets, so the
|
||||||
|
// fallback behaviour is the same as before.
|
||||||
|
b.WriteString("\x1b[?2026h\x1b7\x1b[?25l")
|
||||||
|
|
||||||
|
row := int(layout.mainTop) + 1
|
||||||
|
col := int(layout.mainLeft) + paneCols - boxWidth - 1
|
||||||
|
if col < int(layout.mainLeft) {
|
||||||
|
col = int(layout.mainLeft)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render newest first (visually on top), iterating items in
|
||||||
|
// reverse so the most recent push lands at the smallest row.
|
||||||
|
for idx := len(items) - 1; idx >= 0; idx-- {
|
||||||
|
t := items[idx]
|
||||||
|
height := toastContentRows + 2
|
||||||
|
// Stop if we'd run off the bottom of the pane.
|
||||||
|
if row+height > int(layout.mainTop)+paneRows {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
border := toastBorderStyle(t.kind)
|
||||||
|
wrapped := wrapToastBody(t.text, bodyRoom)
|
||||||
|
|
||||||
|
// Top border.
|
||||||
|
moveTo(&b, row, col)
|
||||||
|
b.WriteString(border)
|
||||||
|
b.WriteString("╭")
|
||||||
|
b.WriteString(strings.Repeat("─", boxWidth-2))
|
||||||
|
b.WriteString("╮")
|
||||||
|
b.WriteString(styleReset)
|
||||||
|
row++
|
||||||
|
|
||||||
|
// Content rows. Row 0 carries the kind glyph; rows 1..N indent
|
||||||
|
// by iconCols spaces so wrapped text lines up under the body.
|
||||||
|
for i := 0; i < toastContentRows; i++ {
|
||||||
|
moveTo(&b, row, col)
|
||||||
|
b.WriteString(border)
|
||||||
|
b.WriteString("│")
|
||||||
|
b.WriteString(styleReset)
|
||||||
|
b.WriteString(" ")
|
||||||
|
if i == 0 {
|
||||||
|
b.WriteString(toastIcon(t.kind))
|
||||||
|
} else {
|
||||||
|
b.WriteString(strings.Repeat(" ", iconCols))
|
||||||
|
}
|
||||||
|
line := wrapped[i]
|
||||||
|
b.WriteString(line)
|
||||||
|
b.WriteString(strings.Repeat(" ", max(0, bodyRoom-visibleLen(line))))
|
||||||
|
b.WriteString(" ")
|
||||||
|
b.WriteString(border)
|
||||||
|
b.WriteString("│")
|
||||||
|
b.WriteString(styleReset)
|
||||||
|
row++
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom border.
|
||||||
|
moveTo(&b, row, col)
|
||||||
|
b.WriteString(border)
|
||||||
|
b.WriteString("╰")
|
||||||
|
b.WriteString(strings.Repeat("─", boxWidth-2))
|
||||||
|
b.WriteString("╯")
|
||||||
|
b.WriteString(styleReset)
|
||||||
|
row++
|
||||||
|
|
||||||
|
// 1-row gap between stacked toasts.
|
||||||
|
row++
|
||||||
|
}
|
||||||
|
|
||||||
|
b.WriteString("\x1b[?25h\x1b8\x1b[?2026l")
|
||||||
|
return []byte(b.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func toastBorderStyle(kind toastKind) string {
|
||||||
|
switch kind {
|
||||||
|
case toastError:
|
||||||
|
return styleError
|
||||||
|
case toastAttention:
|
||||||
|
return styleAccent
|
||||||
|
default:
|
||||||
|
return styleBorder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrapToastBody word-wraps text into exactly toastContentRows lines,
|
||||||
|
// each at most width visible runes wide. Short messages are padded
|
||||||
|
// with empty trailing lines so callers can iterate a fixed-size
|
||||||
|
// slice; messages that don't fit get ellipsized on the last line.
|
||||||
|
func wrapToastBody(text string, width int) []string {
|
||||||
|
out := make([]string, toastContentRows)
|
||||||
|
if width < 1 {
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
all := wrapToastWords(text, width)
|
||||||
|
if len(all) > toastContentRows {
|
||||||
|
all = all[:toastContentRows]
|
||||||
|
last := all[len(all)-1]
|
||||||
|
if visibleLen(last) >= width {
|
||||||
|
last = clipRunes(last, width-1) + "…"
|
||||||
|
} else {
|
||||||
|
last = last + "…"
|
||||||
|
}
|
||||||
|
all[len(all)-1] = last
|
||||||
|
}
|
||||||
|
for i, l := range all {
|
||||||
|
out[i] = l
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrapToastWords is a small word-wrapper sized for toast bodies:
|
||||||
|
// greedy, breaks overlong words on rune boundaries, drops collapsing
|
||||||
|
// whitespace via strings.Fields.
|
||||||
|
func wrapToastWords(text string, width int) []string {
|
||||||
|
var lines []string
|
||||||
|
var cur string
|
||||||
|
flush := func() {
|
||||||
|
if cur != "" {
|
||||||
|
lines = append(lines, cur)
|
||||||
|
cur = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, word := range strings.Fields(text) {
|
||||||
|
for visibleLen(word) > width {
|
||||||
|
flush()
|
||||||
|
head := clipRunes(word, width)
|
||||||
|
lines = append(lines, head)
|
||||||
|
word = word[len(head):]
|
||||||
|
}
|
||||||
|
if word == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if cur == "" {
|
||||||
|
cur = word
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if visibleLen(cur)+1+visibleLen(word) <= width {
|
||||||
|
cur += " " + word
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
flush()
|
||||||
|
cur = word
|
||||||
|
}
|
||||||
|
flush()
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func toastIcon(kind toastKind) string {
|
||||||
|
switch kind {
|
||||||
|
case toastError:
|
||||||
|
return styleError + "✗ " + styleReset
|
||||||
|
case toastAttention:
|
||||||
|
return styleAccent + "! " + styleReset
|
||||||
|
default:
|
||||||
|
return styleHint + "• " + styleReset
|
||||||
|
}
|
||||||
|
}
|
||||||
164
internal/app/toast_test.go
Normal file
164
internal/app/toast_test.go
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestToastStackPushAndOrder(t *testing.T) {
|
||||||
|
var s toastStack
|
||||||
|
s.push(toastInfo, "one")
|
||||||
|
s.push(toastError, "two")
|
||||||
|
s.push(toastAttention, "three")
|
||||||
|
|
||||||
|
snap := s.snapshot()
|
||||||
|
if len(snap) != 3 {
|
||||||
|
t.Fatalf("snapshot len = %d, want 3", len(snap))
|
||||||
|
}
|
||||||
|
if snap[0].text != "one" || snap[1].text != "two" || snap[2].text != "three" {
|
||||||
|
t.Fatalf("snapshot order wrong: %#v", snap)
|
||||||
|
}
|
||||||
|
if snap[0].kind != toastInfo || snap[1].kind != toastError || snap[2].kind != toastAttention {
|
||||||
|
t.Fatalf("snapshot kinds wrong: %#v", snap)
|
||||||
|
}
|
||||||
|
// IDs strictly increase.
|
||||||
|
if !(snap[0].id < snap[1].id && snap[1].id < snap[2].id) {
|
||||||
|
t.Fatalf("ids not increasing: %#v", snap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestToastStackCapDropsOldest(t *testing.T) {
|
||||||
|
var s toastStack
|
||||||
|
for i := 0; i < toastStackCap+3; i++ {
|
||||||
|
s.push(toastInfo, "msg")
|
||||||
|
}
|
||||||
|
snap := s.snapshot()
|
||||||
|
if len(snap) != toastStackCap {
|
||||||
|
t.Fatalf("len = %d, want %d", len(snap), toastStackCap)
|
||||||
|
}
|
||||||
|
// The earliest IDs should have been dropped, leaving the highest
|
||||||
|
// toastStackCap IDs.
|
||||||
|
for i := 1; i < len(snap); i++ {
|
||||||
|
if snap[i].id <= snap[i-1].id {
|
||||||
|
t.Fatalf("ordering broken after cap: %#v", snap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// First retained id should be 4 (1,2,3 dropped; cap=5 leaves 4..8).
|
||||||
|
want := uint64(toastStackCap + 3 - toastStackCap + 1)
|
||||||
|
if snap[0].id != want {
|
||||||
|
t.Fatalf("first retained id = %d, want %d", snap[0].id, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestToastStackDismissTop(t *testing.T) {
|
||||||
|
var s toastStack
|
||||||
|
if s.dismissTop() {
|
||||||
|
t.Fatalf("dismissTop on empty stack returned true")
|
||||||
|
}
|
||||||
|
s.push(toastInfo, "a")
|
||||||
|
s.push(toastError, "b")
|
||||||
|
if !s.dismissTop() {
|
||||||
|
t.Fatalf("dismissTop returned false with items present")
|
||||||
|
}
|
||||||
|
snap := s.snapshot()
|
||||||
|
if len(snap) != 1 || snap[0].text != "a" {
|
||||||
|
t.Fatalf("after dismissTop: %#v", snap)
|
||||||
|
}
|
||||||
|
if !s.dismissTop() {
|
||||||
|
t.Fatalf("dismissTop on last item returned false")
|
||||||
|
}
|
||||||
|
if s.length() != 0 {
|
||||||
|
t.Fatalf("length after final dismiss = %d, want 0", s.length())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestToastStackClear(t *testing.T) {
|
||||||
|
var s toastStack
|
||||||
|
if s.clear() {
|
||||||
|
t.Fatalf("clear on empty returned true")
|
||||||
|
}
|
||||||
|
s.push(toastInfo, "a")
|
||||||
|
s.push(toastError, "b")
|
||||||
|
s.push(toastAttention, "c")
|
||||||
|
if !s.clear() {
|
||||||
|
t.Fatalf("clear returned false with items present")
|
||||||
|
}
|
||||||
|
if s.length() != 0 {
|
||||||
|
t.Fatalf("length after clear = %d, want 0", s.length())
|
||||||
|
}
|
||||||
|
if snap := s.snapshot(); snap != nil {
|
||||||
|
t.Fatalf("snapshot after clear = %#v, want nil", snap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestToastStackSnapshotIsCopy(t *testing.T) {
|
||||||
|
var s toastStack
|
||||||
|
s.push(toastInfo, "a")
|
||||||
|
snap := s.snapshot()
|
||||||
|
snap[0].text = "mutated"
|
||||||
|
again := s.snapshot()
|
||||||
|
if again[0].text != "a" {
|
||||||
|
t.Fatalf("snapshot is not an independent copy: %#v", again)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapToastBodyFixedHeight(t *testing.T) {
|
||||||
|
got := wrapToastBody("short", 20)
|
||||||
|
if len(got) != toastContentRows {
|
||||||
|
t.Fatalf("len = %d, want %d", len(got), toastContentRows)
|
||||||
|
}
|
||||||
|
if got[0] != "short" {
|
||||||
|
t.Fatalf("line 0 = %q, want \"short\"", got[0])
|
||||||
|
}
|
||||||
|
if got[1] != "" || got[2] != "" {
|
||||||
|
t.Fatalf("trailing pads not empty: %#v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapToastBodyWrapsOnWordBoundary(t *testing.T) {
|
||||||
|
got := wrapToastBody("the quick brown fox jumps over", 10)
|
||||||
|
// Expect greedy fill: "the quick" (9), "brown fox" (9), "jumps over" (10).
|
||||||
|
want := []string{"the quick", "brown fox", "jumps over"}
|
||||||
|
for i, w := range want {
|
||||||
|
if got[i] != w {
|
||||||
|
t.Fatalf("line %d = %q, want %q (full=%#v)", i, got[i], w, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapToastBodyEllipsizesOverflow(t *testing.T) {
|
||||||
|
got := wrapToastBody("alpha beta gamma delta epsilon zeta eta theta", 6)
|
||||||
|
if len(got) != toastContentRows {
|
||||||
|
t.Fatalf("len = %d, want %d", len(got), toastContentRows)
|
||||||
|
}
|
||||||
|
last := got[toastContentRows-1]
|
||||||
|
if !strings.HasSuffix(last, "…") {
|
||||||
|
t.Fatalf("overflow should ellipsize last line, got %q (full=%#v)", last, got)
|
||||||
|
}
|
||||||
|
if visibleLen(last) > 6 {
|
||||||
|
t.Fatalf("last line %q exceeds width 6", last)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapToastBodyBreaksOverlongWord(t *testing.T) {
|
||||||
|
got := wrapToastBody("supercalifragilistic", 6)
|
||||||
|
if got[0] != "superc" {
|
||||||
|
t.Fatalf("line 0 = %q, want \"superc\"", got[0])
|
||||||
|
}
|
||||||
|
if got[1] != "alifra" {
|
||||||
|
t.Fatalf("line 1 = %q, want \"alifra\"", got[1])
|
||||||
|
}
|
||||||
|
// Third line should hold the rest (possibly ellipsized).
|
||||||
|
if got[2] == "" {
|
||||||
|
t.Fatalf("line 2 unexpectedly empty: %#v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapToastBodyEmptyInput(t *testing.T) {
|
||||||
|
got := wrapToastBody("", 20)
|
||||||
|
for i, l := range got {
|
||||||
|
if l != "" {
|
||||||
|
t.Fatalf("line %d = %q, want \"\"", i, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"name": "error_flash_preserves_focused_pane",
|
||||||
|
"presets": {
|
||||||
|
"processes": [
|
||||||
|
{
|
||||||
|
"name": "steady",
|
||||||
|
"argv": ["sh", "-lc", "printf 'STEADY READY\\n'; sleep 5"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"trust": ["steady"],
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"type": "mcp_call",
|
||||||
|
"method": "spawn_process",
|
||||||
|
"params": {"kind": "command", "preset": "steady", "name": "steady"},
|
||||||
|
"save_as": "proc"
|
||||||
|
},
|
||||||
|
{ "type": "wait_text", "contains": "STEADY READY", "timeout_ms": 5000 },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-k" },
|
||||||
|
{ "type": "send_text", "text": "Open Settings" },
|
||||||
|
{ "type": "send_chord", "chord": "enter" },
|
||||||
|
{ "type": "send_chord", "chord": "enter" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "send_chord", "chord": "enter" },
|
||||||
|
{ "type": "wait_text", "contains": "no active top-level agent to summarize", "timeout_ms": 5000 },
|
||||||
|
{ "type": "wait_text", "contains": "STEADY READY", "timeout_ms": 5000 },
|
||||||
|
{ "type": "assert_contains", "contains": "STEADY READY" },
|
||||||
|
{ "type": "assert_not_contains", "contains": "Press Ctrl-K to spawn an agent or process" }
|
||||||
|
]
|
||||||
|
}
|
||||||
32
internal/harness/scenarios/toast_dismiss.json
Normal file
32
internal/harness/scenarios/toast_dismiss.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"name": "toast_dismiss",
|
||||||
|
"presets": {
|
||||||
|
"processes": [
|
||||||
|
{
|
||||||
|
"name": "steady",
|
||||||
|
"argv": ["sh", "-lc", "printf 'STEADY READY\\n'; sleep 30"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"trust": ["steady"],
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"type": "mcp_call",
|
||||||
|
"method": "spawn_process",
|
||||||
|
"params": {"kind": "command", "preset": "steady", "name": "steady"},
|
||||||
|
"save_as": "proc"
|
||||||
|
},
|
||||||
|
{ "type": "wait_text", "contains": "STEADY READY", "timeout_ms": 5000 },
|
||||||
|
{
|
||||||
|
"type": "mcp_call",
|
||||||
|
"method": "request_human_attention",
|
||||||
|
"params": {"process_id": "{{proc.process_id}}", "reason": "needs eyes on the deploy"}
|
||||||
|
},
|
||||||
|
{ "type": "wait_text", "contains": "needs eyes on the deploy", "timeout_ms": 5000 },
|
||||||
|
{ "type": "assert_contains", "contains": "STEADY READY" },
|
||||||
|
{ "type": "send_chord", "chord": "ctrl-n" },
|
||||||
|
{ "type": "wait_stable", "timeout_ms": 2000 },
|
||||||
|
{ "type": "assert_contains", "contains": "STEADY READY" },
|
||||||
|
{ "type": "assert_not_contains", "contains": "needs eyes on the deploy" }
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user