Read replaced output rows in full away from the cursor
This commit is contained in:
1 parent
5d3453ad6b
commit
bafbeee6e2
6 files changed
+143
-7
No files matched your search
@@ -112,6 +112,13 @@ func changesExceptRow(previous, next screen.Snapshot, cursorEcho bool, excludedR
|
||||
}
|
||||
inserted := after[start:endAfter]
|
||||
if len(inserted) != 0 && strings.TrimSpace(string(inserted)) != "" {
|
||||
// A replaced output row is a complete message, not an edit at
|
||||
// the application cursor. Diffing it can omit a player's name
|
||||
// or a shared ending. Keep cursor-line edits and output that
|
||||
// only adds text incremental, including streamed output.
|
||||
if row != previous.Y && row != next.Y && strings.TrimSpace(string(before[start:endBefore])) != "" {
|
||||
return []presentation.Message{{Text: next.Text(row)}}
|
||||
}
|
||||
if len(inserted) == 1 {
|
||||
return []presentation.Message{presentation.CharacterMessage(inserted[0])}
|
||||
}
|
||||
|
||||
@@ -70,13 +70,13 @@ func TestReaderDiagnosticsCursorAndStatusWithoutText(t *testing.T) {
|
||||
next := fixture("PRIVATE first", "PRIVATE second", "2/2 PRIVATE")
|
||||
next.Y = 1
|
||||
r.NoteInput(true, false, false)
|
||||
want := []presentation.Message{presentation.CharacterMessage('2'), {Text: "PRIVATE second"}}
|
||||
want := []presentation.Message{{Text: "2/2 PRIVATE"}, {Text: "PRIVATE second"}}
|
||||
if got := r.Update(next); !reflect.DeepEqual(got, want) {
|
||||
t.Fatal("diagnostics changed cursor feedback", got)
|
||||
}
|
||||
checkUpdateRecord(t, log, map[string]string{
|
||||
"cursor": "[0,1]", "previous_cursor": "[0,0]", "mode": `"cursor"`,
|
||||
"text_rows": "[2]", "text_cells": "1", "messages": "2", "message_lengths": "[1,14]",
|
||||
"text_rows": "[2]", "text_cells": "1", "messages": "2", "message_lengths": "[11,14]",
|
||||
"path": `"cursor-feedback"`, "review": "false", "cursor_echo": "true",
|
||||
})
|
||||
log.Reset()
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package reader
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.stormux.org/storm/fenrir/internal/command"
|
||||
"git.stormux.org/storm/fenrir/internal/presentation"
|
||||
"git.stormux.org/storm/fenrir/internal/screen"
|
||||
)
|
||||
|
||||
func gameMessageSnapshot(text string) screen.Snapshot {
|
||||
// Match the reproduction: row 0 is replaced while the cursor stays at
|
||||
// column 0 of row 66, independently of the displayed message.
|
||||
snapshot := screen.Snapshot{Terminal: 1, Active: true, Rows: 67, Cols: 240, Y: 66}
|
||||
snapshot.Cells = make([]rune, snapshot.Rows*snapshot.Cols)
|
||||
for index := range snapshot.Cells {
|
||||
snapshot.Cells[index] = ' '
|
||||
}
|
||||
copy(snapshot.Line(0), []rune(text))
|
||||
return snapshot
|
||||
}
|
||||
|
||||
func TestReplacedGameMessagesReadWholeLine(t *testing.T) {
|
||||
for _, name := range []string{"Player", "Joueuré"} {
|
||||
for _, input := range []bool{false, true} {
|
||||
r := New()
|
||||
entered, left := name+" entered the game.", name+" left the game."
|
||||
r.Update(gameMessageSnapshot(entered))
|
||||
for _, text := range []string{left, entered, left} {
|
||||
if input {
|
||||
// Game message review need not use shell-history keys.
|
||||
r.NoteInput(true, false, false)
|
||||
}
|
||||
next := gameMessageSnapshot(text)
|
||||
if got := r.Update(next); !reflect.DeepEqual(got, []presentation.Message{{Text: text}}) {
|
||||
t.Fatalf("input=%v: got %+v, want whole message %q", input, got, text)
|
||||
}
|
||||
if got := r.Update(next); len(got) != 0 {
|
||||
t.Fatal("unchanged message repeated", got)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplacedOutputRespectsReadingPolicy(t *testing.T) {
|
||||
for _, mode := range []string{"cursor off", "table", "highlight", "review", "automatic off", "live region", "window"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
r := New()
|
||||
r.Update(gameMessageSnapshot("Player entered the game."))
|
||||
switch mode {
|
||||
case "cursor off":
|
||||
r.Configure(true, false)
|
||||
case "table", "highlight":
|
||||
r.ConfigureTracking(mode)
|
||||
case "review":
|
||||
r.Command(command.CurrentLine)
|
||||
case "automatic off":
|
||||
r.Configure(false, true)
|
||||
case "live region":
|
||||
r.ensureRegions().live[0] = &screen.Region{Left: 0, Top: 0, Right: 239, Bottom: 0}
|
||||
case "window":
|
||||
if err := r.SetWindow(0, 1, 239, 66); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var want []presentation.Message
|
||||
if mode != "automatic off" && mode != "live region" && mode != "window" {
|
||||
want = []presentation.Message{{Text: "Player left the game."}}
|
||||
}
|
||||
if got := r.Update(gameMessageSnapshot("Player left the game.")); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("got %+v, want %+v", got, want)
|
||||
}
|
||||
if mode == "review" && !r.review.Active() {
|
||||
t.Fatal("passive output displaced review")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputInsertionsStayIncremental(t *testing.T) {
|
||||
for _, trial := range []struct{ before, after, want string }{
|
||||
{"Player", "Player entered the game.", "entered the game."},
|
||||
{"Player left.", "Player has left.", "has"},
|
||||
{"Player", "Players", "s"},
|
||||
} {
|
||||
r := New()
|
||||
r.Update(gameMessageSnapshot(trial.before))
|
||||
want := presentation.Message{Text: trial.want}
|
||||
if chars := []rune(trial.want); len(chars) == 1 {
|
||||
want = presentation.CharacterMessage(chars[0])
|
||||
}
|
||||
if got := r.Update(gameMessageSnapshot(trial.after)); !reflect.DeepEqual(got, []presentation.Message{want}) {
|
||||
t.Fatalf("%q -> %q: got %+v, want %+v", trial.before, trial.after, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplacedOutputDoesNotStripNamesOrSharedSuffixes(t *testing.T) {
|
||||
for _, trial := range []struct{ before, after string }{
|
||||
{"Player1 left the game.", "Player2 left the game."},
|
||||
{"Player entered the game.", "Visitor entered the game."},
|
||||
{"[notice] Player entered the game.", "[notice] Player left the game."},
|
||||
} {
|
||||
r := New()
|
||||
r.Update(gameMessageSnapshot(trial.before))
|
||||
if got := r.Update(gameMessageSnapshot(trial.after)); !reflect.DeepEqual(got, []presentation.Message{{Text: trial.after}}) {
|
||||
t.Fatalf("got %+v, want whole message %q", got, trial.after)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func TestReadingWindowAndLiveRegionComposeWithoutRestrictingReview(t *testing.T)
|
||||
}
|
||||
next = fixture("changed outer", "IN qbc NEW", "IN XYZ NEW")
|
||||
next.X, next.Y = r.screen.X, r.screen.Y
|
||||
if got := r.Update(next); !reflect.DeepEqual(got, []presentation.Message{presentation.CharacterMessage('q')}) {
|
||||
if got := r.Update(next); !reflect.DeepEqual(got, []presentation.Message{{Text: " qbc"}}) {
|
||||
t.Fatal("inside window did not speak", got)
|
||||
}
|
||||
regionCommand(t, r, command.ClearWindow, "Window Mode off for terminal 2")
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestCursorNavigationWithStatusChanges(t *testing.T) {
|
||||
after := fixture("Message one", "Message two", "2/2 messages")
|
||||
after.Y = 1
|
||||
r.NoteInput(true, false, false)
|
||||
want := []presentation.Message{presentation.CharacterMessage('2'), {Text: "Message two"}}
|
||||
want := []presentation.Message{{Text: "2/2 messages"}, {Text: "Message two"}}
|
||||
if got := r.Update(after); !reflect.DeepEqual(got, want) {
|
||||
t.Fatal("status line hid focused message", got)
|
||||
}
|
||||
@@ -47,13 +47,13 @@ func TestCursorNavigationWithStatusChanges(t *testing.T) {
|
||||
horizontal := fixture("Message one", "Message two", "3/2 messages")
|
||||
horizontal.Y, horizontal.X = 1, 1
|
||||
r.NoteInput(true, false, false)
|
||||
want = []presentation.Message{presentation.CharacterMessage('3'), presentation.CharacterMessage('e')}
|
||||
want = []presentation.Message{{Text: "3/2 messages"}, presentation.CharacterMessage('e')}
|
||||
if got := r.Update(horizontal); !reflect.DeepEqual(got, want) {
|
||||
t.Fatal("status line hid horizontal navigation", got)
|
||||
}
|
||||
// Cursor feedback disabled still leaves incoming text available.
|
||||
r.Configure(true, false)
|
||||
if got := r.Update(before); !reflect.DeepEqual(got, []presentation.Message{presentation.CharacterMessage('1')}) {
|
||||
if got := r.Update(before); !reflect.DeepEqual(got, []presentation.Message{{Text: "1/2 messages"}}) {
|
||||
t.Fatal("cursor setting suppressed status output", got)
|
||||
}
|
||||
// New command output commonly leaves the cursor on an unchanged blank row.
|
||||
|
||||
+15
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2026 Storm Dragon
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Replay split dialog redraws through a real PTY and capture automatic SSIP.
|
||||
"""Replay dialog and message-row redraws through a real PTY and capture SSIP.
|
||||
|
||||
Run: xvfb-run -a env FENRIR_PRIVATE_X11=1 python3 tests/native_dialogs.py
|
||||
No installed I38, dialog, GNU Screen, live audio, or live keyboard is used.
|
||||
@@ -14,6 +14,7 @@ import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from native_terminal import KeyboardFixture, SpeechServer, wait_for
|
||||
|
||||
@@ -86,6 +87,19 @@ def main():
|
||||
# No review key was used to obtain the missing text.
|
||||
assert not (root / "input").exists() or not (root / "input").read_bytes()
|
||||
print(f"PASS: {name}: automatic body speech followed by focused button", flush=True)
|
||||
|
||||
# A game's message browser replaces one output row while leaving
|
||||
# the cursor parked on a blank bottom row. Shared player names
|
||||
# and endings belong to each announcement.
|
||||
start = emit_output(b"\x1b[2J\x1b[HPlayer entered the game.\x1b[25;1H")
|
||||
spoken("Player entered the game", start)
|
||||
for text in ("Player left the game", "Player entered the game", "Player left the game"):
|
||||
start = emit_output(b"\x1b[H\x1b[2K" + text.encode() + b".\x1b[25;1H")
|
||||
spoken(text, start)
|
||||
time.sleep(0.1) # Include duplicate speech from delayed redraws.
|
||||
utterances = [item for item in server.events[start:] if item != "CANCEL"]
|
||||
assert len(utterances) == 1 and text in utterances[0], (text, utterances)
|
||||
print(f"PASS: replaced message reads {text!r} once in full", flush=True)
|
||||
keyboard.key("Insert+q")
|
||||
wait_for(lambda: (root / "finished").exists(), "reader shutdown")
|
||||
result = json.loads((root / "finished").read_text())
|
||||
|
||||
Reference in new issue
Block a user