Use common v0.8.0 UI, transport, and translation APIs

This commit is contained in:
Storm Dragon committed 2026-11-16 20:10:47 -05:00
1 parent 317303adb7
commit 92fd479336
344 files changed
+4102 -4973

No files matched your search

@@ -11,7 +11,7 @@ import (
"git.stormux.org/storm/fenrir/internal/screen"
)
func accept_event(t *testing.T, a *Adapter, event Event) {
func acceptEvent(t *testing.T, a *Adapter, event Event) {
t.Helper()
event.Version, event.Session, event.Epoch = 1, "fixture-session", 1
if err := a.Accept(event); err != nil {
@@ -21,21 +21,21 @@ func accept_event(t *testing.T, a *Adapter, event Event) {
func TestCompleteChunksDeduplicationHistoryAndStatus(t *testing.T) {
a := &Adapter{}
accept_event(t, a, Event{Kind: "status", Status: "working"})
accept_event(t, a, Event{Kind: "message", ID: "first", Text: "Whole ", Parts: 2})
acceptEvent(t, a, Event{Kind: "status", Status: "working"})
acceptEvent(t, a, Event{Kind: "message", ID: "first", Text: "Whole ", Parts: 2})
if frame := a.Observe(screen.Snapshot{}); len(frame.Updates) != 0 {
t.Fatal("partial message spoken")
}
accept_event(t, a, Event{Kind: "message", ID: "first", Text: "reply", Part: 1, Parts: 2})
acceptEvent(t, a, Event{Kind: "message", ID: "first", Text: "reply", Part: 1, Parts: 2})
frame := a.Observe(screen.Snapshot{})
if !frame.OwnsPresentation || len(frame.Updates) != 1 || frame.Updates[0].Text != "Whole reply" {
t.Fatal(frame)
}
accept_event(t, a, Event{Kind: "message", ID: "first", Text: "Whole reply", Parts: 1})
acceptEvent(t, a, Event{Kind: "message", ID: "first", Text: "Whole reply", Parts: 1})
if len(a.Observe(screen.Snapshot{}).Updates) != 0 {
t.Fatal("duplicate spoken")
}
accept_event(t, a, Event{Kind: "message", ID: "second", Text: "Old reply", Parts: 1, Baseline: true})
acceptEvent(t, a, Event{Kind: "message", ID: "second", Text: "Old reply", Parts: 1, Baseline: true})
if len(a.Observe(screen.Snapshot{}).Updates) != 0 {
t.Fatal("baseline spoken")
}
@@ -52,7 +52,7 @@ func TestCompleteChunksDeduplicationHistoryAndStatus(t *testing.T) {
if got, _ := a.Command(command.ReadLiveRegion2); got.Text != "Whole reply" {
t.Fatal("suspension lost history")
}
accept_event(t, a, Event{Kind: "status", Status: "closed"})
acceptEvent(t, a, Event{Kind: "status", Status: "closed"})
if a.Observe(screen.Snapshot{}).Recognized {
t.Fatal("exit retained presentation ownership")
}
@@ -60,7 +60,7 @@ func TestCompleteChunksDeduplicationHistoryAndStatus(t *testing.T) {
func TestRejectInterleavedSessionOutOfOrderAndOversize(t *testing.T) {
a := &Adapter{}
accept_event(t, a, Event{Kind: "status", Status: "idle"})
acceptEvent(t, a, Event{Kind: "status", Status: "idle"})
if err := a.Accept(Event{Version: 1, Epoch: 1, Session: "another-session", Kind: "status", Status: "working"}); err == nil {
t.Fatal("another session attached")
}
@@ -74,8 +74,8 @@ func TestRejectInterleavedSessionOutOfOrderAndOversize(t *testing.T) {
func TestConversationSwitchRejectsPreviousFollower(t *testing.T) {
a := &Adapter{}
accept_event(t, a, Event{Kind: "status", Status: "working"})
accept_event(t, a, Event{Kind: "message", ID: "old", Text: "Previous conversation", Parts: 1})
acceptEvent(t, a, Event{Kind: "status", Status: "working"})
acceptEvent(t, a, Event{Kind: "message", ID: "old", Text: "Previous conversation", Parts: 1})
if err := a.Accept(Event{Version: 1, Epoch: 2, Session: "new-session", Kind: "status", Status: "idle"}); err != nil {
t.Fatal(err)
}
+12 -12
View File
@@ -45,7 +45,7 @@ func (a *Adapter) Close() { a.Reset(); a.latest = "" }
// PageUp/PageDown browse existing chat. Rebaseline the next redraw instead of
// announcing it as incoming traffic. Linux input key codes are protocol data.
func (a *Adapter) Note_key(key uint16) {
func (a *Adapter) NoteKey(key uint16) {
if key == 104 || key == 109 {
a.historyNavigation = true
a.historyAt = time.Now()
@@ -100,7 +100,7 @@ func (a *Adapter) Observe(next screen.Snapshot) applicationoverrides.Frame {
stable := a.previous.Active && a.previous.Terminal == next.Terminal && a.previous.Generation == next.Generation && a.previous.Rows == next.Rows && a.previous.Cols == next.Cols
chatHeight := max(next.Rows/4, 4)
chatTop := next.Rows - 2 - chatHeight
focusID, focusText, volumePan := selected_control(next, chatTop)
focusID, focusText, volumePan := selectedControl(next, chatTop)
if next.Y == next.Rows-3 {
focusID, focusText = "chat", i18n.T("Chat message")
frame.Input = &screen.Region{Left: 0, Top: next.Y, Right: next.Cols - 1, Bottom: next.Y}
@@ -121,10 +121,10 @@ func (a *Adapter) Observe(next screen.Snapshot) applicationoverrides.Frame {
before, after := strings.Fields(a.volumePan), strings.Fields(volumePan)
var changed []string
if before[0] != after[0] {
changed = append(changed, spoken_volume(after[0]))
changed = append(changed, spokenVolume(after[0]))
}
if before[1] != after[1] {
changed = append(changed, spoken_pan(after[1]))
changed = append(changed, spokenPan(after[1]))
}
spoken = strings.Join(changed, " ")
}
@@ -134,14 +134,14 @@ func (a *Adapter) Observe(next screen.Snapshot) applicationoverrides.Frame {
frame.Updates = append(frame.Updates, presentation.Message{Text: instruction})
}
chat := chat_lines(next, chatTop+1, next.Rows-4)
chat := chatLines(next, chatTop+1, next.Rows-4)
if stable && len(chat) == 0 && len(a.chat) != 0 {
// A transient cleared chat area during redraw is not new history.
chat = slices.Clone(a.chat)
}
historyNavigation := a.historyNavigation && time.Since(a.historyAt) < 2*time.Second
if stable && !historyNavigation {
for _, text := range appended_lines(a.chat, chat) {
for _, text := range appendedLines(a.chat, chat) {
frame.Updates = append(frame.Updates, presentation.Message{Text: text})
a.latest = text
}
@@ -194,7 +194,7 @@ func fields(line []rune) []field {
return result
}
func selected_control(snapshot screen.Snapshot, chatTop int) (string, string, string) {
func selectedControl(snapshot screen.Snapshot, chatTop int) (string, string, string) {
if len(snapshot.Attributes) != len(snapshot.Cells) {
return "", "", ""
}
@@ -267,7 +267,7 @@ func selected_control(snapshot screen.Snapshot, chatTop int) (string, string, st
default:
if parts := strings.Fields(value); len(parts) == 2 && strings.HasSuffix(parts[0], "dB") {
volumePan = value
value = i18n.Format("Volume and pan {0}", spoken_volume(parts[0])+" "+spoken_pan(parts[1]))
value = i18n.Format("Volume and pan {0}", spokenVolume(parts[0])+" "+spokenPan(parts[1]))
}
if len(controls) >= 5 && index == 0 {
value = i18n.Format("Channel name {0}", value)
@@ -295,7 +295,7 @@ func selected_control(snapshot screen.Snapshot, chatTop int) (string, string, st
}
// Keep signs and pan directions audible regardless of the punctuation profile.
func spoken_volume(value string) string {
func spokenVolume(value string) string {
if strings.HasPrefix(value, "-") {
return i18n.Format("minus {0}", value[1:])
}
@@ -305,7 +305,7 @@ func spoken_volume(value string) string {
return value
}
func spoken_pan(value string) string {
func spokenPan(value string) string {
if value == "center" {
return i18n.T("center")
}
@@ -318,7 +318,7 @@ func spoken_pan(value string) string {
return value
}
func chat_lines(snapshot screen.Snapshot, first, last int) []string {
func chatLines(snapshot screen.Snapshot, first, last int) []string {
var result []string
previousFull := false
for row := first; row <= last; row++ {
@@ -338,7 +338,7 @@ func chat_lines(snapshot screen.Snapshot, first, last int) []string {
return result
}
func appended_lines(previous, next []string) []string {
func appendedLines(previous, next []string) []string {
if slices.Equal(previous, next) {
return nil
}
@@ -87,7 +87,7 @@ func TestControlsHaveContextAndState(t *testing.T) {
func TestFocusChatMetersAndValueReflow(t *testing.T) {
a := &ninjam.Adapter{}
r := reader.New()
update := func(s screen.Snapshot) []string { return texts(r.Update_application(s, a.Observe(s))) }
update := func(s screen.Snapshot) []string { return texts(r.UpdateApplication(s, a.Observe(s))) }
update(snapshot(0, " ", "0.0dB center", "<Username> first"))
got := update(snapshot(1, " ", "0.0dB center", "<Username> first", "<Username> second"))
if !slices.Equal(got, []string{"Master Volume and pan 0.0dB center", "<Username> second"}) {
@@ -115,13 +115,13 @@ func TestReviewResumesOnlyOnApplicationNavigation(t *testing.T) {
for _, direct := range []bool{false, true} {
a, r := &ninjam.Adapter{}, reader.New()
s := snapshot(0, " ", "0.0dB center", "<Username> old")
r.Update_application(s, a.Observe(s))
r.UpdateApplication(s, a.Observe(s))
r.Command(command.CurrentLine)
if direct {
r.Note_input(true, false, false)
r.NoteInput(true, false, false)
}
s = snapshot(1, " ", "0.0dB center", "<Username> old", "<Username> new")
got := texts(r.Update_application(s, a.Observe(s)))
got := texts(r.UpdateApplication(s, a.Observe(s)))
want := []string{"<Username> new"}
if direct {
want = append([]string{"Master Volume and pan 0.0dB center"}, want...)
@@ -139,7 +139,7 @@ func TestChatScrollPagingRepetitionAndResize(t *testing.T) {
if got := texts(frame.Updates); !slices.Equal(got, []string{"<Username> d"}) {
t.Fatal("repeated message", got)
}
a.Note_key(104)
a.NoteKey(104)
// An interval update can arrive before the application's history redraw.
a.Observe(snapshot(0, " ", "0.0dB center", "<Username> b", "<Username> c", "<Username> d", "<Username> d"))
frame = a.Observe(snapshot(0, " ", "0.0dB center", "<Username> old", "<Username> b", "<Username> c", "<Username> d"))
@@ -161,19 +161,19 @@ func TestChatAlongsideTypingAndMutedAutomaticReading(t *testing.T) {
a, r := &ninjam.Adapter{}, reader.New()
s := snapshot(-1, " ", "0.0dB center", "<Username> old")
s.Y = 21
r.Update_application(s, a.Observe(s))
r.Note_input(true, true, false)
r.UpdateApplication(s, a.Observe(s))
r.NoteInput(true, true, false)
s = snapshot(-1, " ", "0.0dB center", "<Username> old", "<Username> incoming")
s.Y, s.X = 21, 1
s.Line(21)[0] = 'a'
got := texts(r.Update_application(s, a.Observe(s)))
got := texts(r.UpdateApplication(s, a.Observe(s)))
if !slices.Equal(got, []string{"a", "<Username> incoming"}) {
t.Fatal(got)
}
r.Configure(false, true)
s = snapshot(-1, " ", "0.0dB center", "<Username> incoming", "<Username> silent")
s.Y = 21
if got := texts(r.Update_application(s, a.Observe(s))); len(got) != 0 {
if got := texts(r.UpdateApplication(s, a.Observe(s))); len(got) != 0 {
t.Fatal(got)
}
if result, _ := a.Command(command.ReadLiveRegion1); result.Text != "<Username> silent" {
@@ -269,7 +269,7 @@ func TestVolumeAndPanAnnounceOnlyChangedComponent(t *testing.T) {
}
update := func(value string, chat ...string) []string {
s := makeSnapshot(value, chat...)
return texts(r.Update_application(s, a.Observe(s)))
return texts(r.UpdateApplication(s, a.Observe(s)))
}
update("0.0dB center", "<Username> old")
for _, trial := range []struct{ value, want string }{
+20 -20
View File
@@ -52,13 +52,13 @@ func (a *Adapter) Command(id command.ID) (presentation.CommandResult, bool) {
if slot := slices.Index(ids, id); slot >= 0 {
regions := a.regions
if len(regions) == 0 {
regions = region_names()
regions = regionNames()
}
return presentation.CommandResult{Text: regions[slot].Read()}, true
}
if id == command.ListReadingRegions {
var entries []string
for slot, region := range region_names() {
for slot, region := range regionNames() {
entries = append(entries, i18n.Format("Live region {0}: {1}", strconv.Itoa(slot+1), region.Name))
}
return presentation.CommandResult{Text: strings.Join(entries, ". ")}, true
@@ -66,7 +66,7 @@ func (a *Adapter) Command(id command.ID) (presentation.CommandResult, bool) {
return presentation.CommandResult{}, false
}
func region_names() []applicationoverrides.Region {
func regionNames() []applicationoverrides.Region {
return []applicationoverrides.Region{
{Name: i18n.T("Health")}, {Name: i18n.T("Status")},
{Name: i18n.T("Latest message")}, {Name: i18n.T("Surroundings")},
@@ -89,12 +89,12 @@ func (a *Adapter) Observe(next screen.Snapshot) applicationoverrides.Frame {
options := strings.Contains(next.Text(0), `Terse output ("terse"):`) && strings.Contains(string(next.Cells), `Inventory style ("inven"):`)
page := strings.Contains(string(next.Cells), "--Press space to continue--")
if options || page && (stable || stats != nil) {
a.regions = region_names()
a.regions = regionNames()
a.regions[2].Text = a.latest
a.previous, a.dialog = next, true
return applicationoverrides.Frame{Recognized: true, Regions: slices.Clone(a.regions)}
}
x, y, found := player_position(next)
x, y, found := playerPosition(next)
if stats == nil || !found {
a.Reset()
return applicationoverrides.Frame{}
@@ -111,22 +111,22 @@ func (a *Adapter) Observe(next screen.Snapshot) applicationoverrides.Frame {
// A visible clear permits the same message to be announced on a later turn.
// Messages replaced between captures cannot be recovered from screenshots.
a.message = message
regions := region_names()
regions := regionNames()
regions[0].Text = i18n.Format("{0} of {1}", stats[3], stats[4])
regions[1].Text = strings.TrimSpace(next.Text(23))
regions[2].Text = a.latest
regions[3].Text = surroundings(next, x, y)
entities := visible_entities(next)
entities := visibleEntities(next)
var monsters, objects []string
for _, item := range entities {
text := describe(item, x, y)
if is_monster(item.glyph) {
if isMonster(item.glyph) {
monsters = append(monsters, text)
} else {
objects = append(objects, text)
}
}
regions[4].Text, regions[5].Text = join_entities(monsters), join_entities(objects)
regions[4].Text, regions[5].Text = joinEntities(monsters), joinEntities(objects)
if !stable || len(a.stats) == 0 {
frame.Updates = append(frame.Updates, presentation.Message{Text: regions[0].Read()})
if stats[10] != "" {
@@ -160,16 +160,16 @@ func (a *Adapter) Observe(next screen.Snapshot) applicationoverrides.Frame {
if stable && !a.dialog && len(a.stats) != 0 && stats[1] == a.stats[1] {
counts := map[rune]int{}
for _, item := range a.entities {
if is_monster(item.glyph) {
if isMonster(item.glyph) {
counts[item.glyph]++
}
}
for _, item := range entities {
if is_monster(item.glyph) && counts[item.glyph] > 0 {
if isMonster(item.glyph) && counts[item.glyph] > 0 {
counts[item.glyph]--
continue
}
if !is_monster(item.glyph) && slices.Contains(a.entities, item) {
if !isMonster(item.glyph) && slices.Contains(a.entities, item) {
continue
}
frame.Updates = append(frame.Updates, presentation.Message{Text: describe(item, x, y)})
@@ -181,7 +181,7 @@ func (a *Adapter) Observe(next screen.Snapshot) applicationoverrides.Frame {
return frame
}
func player_position(s screen.Snapshot) (int, int, bool) {
func playerPosition(s screen.Snapshot) (int, int, bool) {
x, y := -1, -1
for row := 1; row <= mapBottom; row++ {
for col, glyph := range s.Line(row)[:80] {
@@ -196,13 +196,13 @@ func player_position(s screen.Snapshot) (int, int, bool) {
return x, y, x >= 0
}
func is_monster(glyph rune) bool { return glyph >= 'A' && glyph <= 'Z' }
func isMonster(glyph rune) bool { return glyph >= 'A' && glyph <= 'Z' }
func visible_entities(s screen.Snapshot) []entity {
func visibleEntities(s screen.Snapshot) []entity {
var result []entity
for y := 1; y <= mapBottom; y++ {
for x, glyph := range s.Line(y)[:80] {
if is_monster(glyph) || strings.ContainsRune("+^%*!?$:)],=/", glyph) {
if isMonster(glyph) || strings.ContainsRune("+^%*!?$:)],=/", glyph) {
result = append(result, entity{x, y, glyph})
}
}
@@ -210,7 +210,7 @@ func visible_entities(s screen.Snapshot) []entity {
return result
}
func join_entities(items []string) string {
func joinEntities(items []string) string {
if len(items) == 0 {
return i18n.T("None visible")
}
@@ -243,12 +243,12 @@ func describe(item entity, x, y int) string {
if item.x > x {
offsets = append(offsets, i18n.Format("east {0}", strconv.Itoa(item.x-x)))
}
return i18n.Format("{0}, {1}", glyph_name(item.glyph), strings.Join(offsets, ", "))
return i18n.Format("{0}, {1}", glyphName(item.glyph), strings.Join(offsets, ", "))
}
func glyph_name(glyph rune) string {
func glyphName(glyph rune) string {
// These are Rogue's own English monster names, rather than Fenrir labels.
if is_monster(glyph) {
if isMonster(glyph) {
return []string{"aquator", "bat", "centaur", "dragon", "emu", "venus flytrap", "griffin", "hobgoblin", "ice monster", "jabberwock", "kestrel", "leprechaun", "medusa", "nymph", "orc", "phantom", "quagga", "rattlesnake", "snake", "troll", "black unicorn", "vampire", "wraith", "xeroc", "yeti", "zombie"}[glyph-'A']
}
switch glyph {
@@ -80,7 +80,7 @@ func TestNamedRegionsAndVisibleMap(t *testing.T) {
func TestMessagesHealthAndHungerWithoutMapChatter(t *testing.T) {
a := &rogue.Adapter{}
r := reader.New()
update := func(s screen.Snapshot) []string { return texts(r.Update_application(s, a.Observe(s))) }
update := func(s screen.Snapshot) []string { return texts(r.UpdateApplication(s, a.Observe(s))) }
update(game(24, 80, "", initialStatus))
if got := update(game(24, 80, "", initialStatus)); len(got) != 0 {
t.Fatal("idle chatter", got)
@@ -200,14 +200,14 @@ func TestDialogsAndContextBoundaries(t *testing.T) {
func TestRawReviewStillReadsActualMap(t *testing.T) {
a, r := &rogue.Adapter{}, reader.New()
s := game(24, 80, "", initialStatus)
r.Update_application(s, a.Observe(s))
r.UpdateApplication(s, a.Observe(s))
if got := r.Command(command.CurrentLine); !strings.Contains(got.Text, "@") {
t.Fatal(got)
}
r.Note_input(true, false, false)
r.NoteInput(true, false, false)
s = game(24, 80, "", initialStatus)
s.Line(5)[10], s.Line(5)[11], s.X = '.', '@', 11
if got := texts(r.Update_application(s, a.Observe(s))); len(got) != 0 {
if got := texts(r.UpdateApplication(s, a.Observe(s))); len(got) != 0 {
t.Fatal("movement spoke map", got)
}
}