Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/test-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ $required = @(
'TestAnalyzeRefusalsDoNotWriteState',
'TestAnalyzeDoesNotRedirectAnUnreadableExactGame',
'TestPlayNowCutsAMaxSearchShort',
'TestPlayNowIsOfferedOnTheSmallestTerminal',
'TestReplayAnalysisFromTheMenu',
'TestStudyNoteSurvivesLeavingAndResizing'
)
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- In a terminal too small for the panel, `esc play now` and the search's time
and completed depth were hidden for the whole search behind the announcement
of the move just played, until another key was pressed. They now lead the
status line, and the announcement follows them.
- In a terminal too small for the panel, pressing `m` again after a bookmark
change refused because another window had saved first toggled a stored state
that had never been shown. The refusal now says whether the entry is
bookmarked now, at every size.
- The manual described notes attached to a changed record, or kept in a newer
or damaged file, as read-only; they are not shown at all.

## [0.8.0] - 2026-09-28

### Added
Expand Down
25 changes: 16 additions & 9 deletions docs/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 +990,13 @@ another program keeps them unless you edit them away.
Notes are attached to the record's digest as well as to the game ID, and the
file is limited to 1 MiB. If the record has changed since the notes were
written, or the file was written by a newer twixtui or is damaged, the viewer
says so and the notes are read-only; the file is left exactly as it was, never
moved onto the new record or rewritten. Notes can be saved on finished games
only, so an unfinished imported game can be watched but `m` and `e` explain why
they do nothing. In a terminal with no room for the panel, the status line
gives the reason for a refused `m`, `e` or save in a few words.
does not show those notes — they belong to another record or cannot be read —
and says why instead. They cannot be edited either, so `m` and `e` change
nothing, and the file is left exactly as it was, never moved onto the new
record or rewritten. Notes can be saved on finished games only, so an
unfinished imported game can be watched but `m` and `e` explain why they do
nothing. In a terminal with no room for the panel, the status line gives the
reason for a refused `m`, `e` or save in a few words.

Every save is checked against the revision the viewer last read, and a
successful save advances it. If another window saved first, the save is refused
Expand All @@ -1004,10 +1006,15 @@ stored one. Saving again is taken only while the whole stored note is on
screen. In a terminal too small to show it — with no panel, or a panel too
short or narrow for all of it — the save is refused again and nothing is
written until the terminal is enlarged; `esc` still keeps the stored note. A
bookmark refused the same way shows what is stored, and pressing `m` again
decides. A file another program has left at the highest revision there is
still shows its notes but can take no further save: saving is refused as for a
damaged file, and the file is left as it was.
bookmark refused the same way changes nothing either: the viewer shows what is
stored, and the refusal says whether the entry is bookmarked now, on the status
line (`marked elsewhere` or `unmarked elsewhere`) as well as in the panel, so
pressing `m` again is a decision about the state you have read. In a terminal
too small to draw the board, where the refusal cannot be shown, `m` on that
entry does nothing until the terminal is enlarged. A file another program has
left at the highest revision there is still shows its notes but can take no
further save: saving is refused as for a damaged file, and the file is left as
it was.

## Position analysis

Expand Down
95 changes: 64 additions & 31 deletions internal/app/gamescreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1464,11 +1464,13 @@ func (s *gameScreen) lastSearchForms() []string {
}
}

// fitMessage is the message as a status line width cells wide can show it.
// The finished search's figures are the one message with shorter forms of its
// own, and the forms stand only while the message is still the sentence they
// were made with: whatever writes the message next replaces the sentence, and
// so retires the forms without having to know they exist.
// fitMessage is the message as width cells of the status line can show it: the
// whole line, or what is left of it once the play-now key and the search have
// led a line with no panel. The finished search's figures are the one message
// with shorter forms of its own, and the forms stand only while the message is
// still the sentence they were made with: whatever writes the message next
// replaces the sentence, and so retires the forms without having to know they
// exist.
func (s *gameScreen) fitMessage(width int) string {
if len(s.figures) == 0 || s.message != s.figures[0] {
return s.message
Expand Down Expand Up @@ -2584,25 +2586,43 @@ func (s *gameScreen) openingPeg() string {
// because there is nowhere else for that to go, and advice once it has been
// asked for, which leads the line ahead of the turn. While the engine searches,
// the key that cuts the search short and how far the search has got lead even
// that.
// that, and on a line with no panel they lead the answer to a keypress too.
func (s *gameScreen) statusLine(arr ui.Arrangement) string {
phase := s.keyPhase()
playNow := ""
if s.actionAvailable(phase, gaPlayNow, ui.ActNone) {
playNow = s.gameKeyLabel(gaPlayNow) + " play now"
}
if s.message != "" {
return s.style(s.styles.Status, gsTruncate(s.fitMessage(arr.Width), arr.Width))
if playNow == "" || arr.Panel != ui.PanelNone {
return s.style(s.styles.Status, gsTruncate(s.fitMessage(arr.Width), arr.Width))
}
// The move that starts a search is announced here, and the
// announcement stands until the next key, which a player waiting for
// the engine has no reason to press. Given the whole line, it hid the
// key that cuts the search short, and the search, for as long as the
// search ran, in the one layout where this line is the only place
// either can be seen. So they lead a message as they lead the line
// without one, and the message has the width they leave: it is what
// is cut, or dropped whole, when there is not room for everything.
// Nothing is cleared, so once play now is no longer offered the
// message has the line to itself again. With a panel the thinking
// line shows the search and the help lists the key, and a message
// keeps the line as it always has.
parts := s.searchLead(playNow, arr.Width)
room := arr.Width - ansi.StringWidth(strings.Join(parts, " · ")+" · ")
parts = append(parts, s.fitMessage(room))
return s.style(s.styles.Status, fitLead(parts, len(parts)-1, arr.Width))
}
phase := s.keyPhase()
if phase == phasePlay && s.hint.shown && s.notice == "" {
// A short panel, or the one-turn swap notice above it, can hide the
// advice. Keep its complete coordinate and policy on the status line
// in every layout, without appending items that could truncate them.
return s.style(s.styles.Status, s.hint.statusText(arr.Width))
}
var parts []string
playNow := ""
if s.actionAvailable(phase, gaPlayNow, ui.ActNone) {
playNow = s.gameKeyLabel(gaPlayNow) + " play now"
}
// lead counts the parts at the front of the line that have to reach the
// screen whole; see the end of this function.
// screen whole; see fitLead.
lead := 0
if arr.Panel == ui.PanelNone {
if s.notice != "" {
Expand All @@ -2612,14 +2632,9 @@ func (s *gameScreen) statusLine(arr ui.Arrangement) string {
// With no panel this line is the only place the search and the
// key that cuts it short can be seen. The headline used to come
// first, and at the minimum width it filled the line and cut both
// off. The key leads now, then the search, cut down to the room
// the key leaves, and the headline has whatever width is left.
room := arr.Width
if playNow != "" {
parts = append(parts, playNow)
room -= ansi.StringWidth(playNow + " · ")
}
parts = append(parts, s.searchProgressShort(room))
// off. The key leads now, then the search, and the headline has
// whatever width is left.
parts = s.searchLead(playNow, arr.Width)
lead = len(parts)
}
parts = append(parts, gsPlain(s.headlineText()))
Expand Down Expand Up @@ -2677,20 +2692,38 @@ func (s *gameScreen) statusLine(arr ui.Arrangement) string {
}
parts = append(parts, s.gameKeyLabel(gaDraw)+" draw", s.gameKeyLabel(gaResign)+" resign")
}
return s.style(s.styles.Status, fitLead(parts, lead, arr.Width))
}

// searchLead is the front of the status line of a layout with no panel while
// the engine searches: the play-now key while it is offered, then how far the
// search has got, cut down to the room the key leaves.
func (s *gameScreen) searchLead(playNow string, width int) []string {
room := width
var lead []string
if playNow != "" {
lead = append(lead, playNow)
room -= ansi.StringWidth(playNow + " · ")
}
return append(lead, s.searchProgressShort(room))
}

// fitLead joins a status line's parts and cuts the line to width, with the
// first lead of them, which have to reach the screen whole, kept whole. A cut
// line ends in a mark, and ui.Compose shortens such a line to the last item it
// can be sure is whole: an item with the mark straight after it may have been
// cut through, so it goes. Where the width leaves no cell past the lead for the
// separator after it, the mark lands straight after the search's figures, and
// they would go. The lead is shown alone then, unmarked: the figures are worth
// more than a mark saying that the rest of the line did not fit.
func fitLead(parts []string, lead, width int) string {
line := strings.Join(parts, " · ")
if lead > 0 && ansi.StringWidth(line) > arr.Width {
// A cut line ends in a mark, and ui.Compose shortens such a line to
// the last item it can be sure is whole: an item with the mark
// straight after it may have been cut through, so it goes. Where the
// width leaves no cell past the lead for the separator after it, the
// mark lands straight after the search's figures, and they would go.
// The lead is shown alone then, unmarked: the figures are worth more
// than a mark saying that the headline and the other keys did not fit.
if head := strings.Join(parts[:lead], " · "); ansi.StringWidth(head)+2 > arr.Width {
if lead > 0 && ansi.StringWidth(line) > width {
if head := strings.Join(parts[:lead], " · "); ansi.StringWidth(head)+2 > width {
line = head
}
}
return s.style(s.styles.Status, gsTruncate(line, arr.Width))
return gsTruncate(line, width)
}

// quitHint is the terse form of the quit key for the status line. A game opened
Expand Down
100 changes: 98 additions & 2 deletions internal/app/gamescreen_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"slices"
"strings"
"sync"
"testing"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/BAKocska/twixtui/internal/bot"
"github.com/BAKocska/twixtui/internal/game"
"github.com/BAKocska/twixtui/internal/gamestore"
"github.com/BAKocska/twixtui/internal/ui"
)

// --- a search the test runs by hand -----------------------------------------
Expand Down Expand Up @@ -241,6 +243,17 @@ func gpClaimsDepth(frame string, depth int) bool {
// included.
var gpDepthClaim = regexp.MustCompile(`\bdepth \d`)

// gpCompactDepth2 is the completed depth 2 in the short form a status line
// with no panel gives it.
var gpCompactDepth2 = regexp.MustCompile(`\bd2\b`)

// gpBottom is the bottom row of a composed frame, where ui.Compose pins the
// status line, as the player reads it.
func gpBottom(frame string) string {
lines := strings.Split(frame, "\n")
return ansi.Strip(lines[len(lines)-1])
}

// --- the thinking line --------------------------------------------------------

// TestTheThinkingLineShowsOnlyThisSearchsFinishedWork reads the engine while
Expand Down Expand Up @@ -385,8 +398,10 @@ func TestPlayNowAndTheSearchShowAtEverySize(t *testing.T) {
h := newGSHarness(t, gsTestDeps(t), gsVersusBot(6, engine), size[0], size[1])
h.playTurn(game.Point{Col: 1, Row: 0})
gpEntered(t, engine)
// The commit's own line answers the key that made it, and holds
// the status line until the next key.
// The commit's own line answers the key that made it, and where
// there is a panel it holds the status line until the next key.
// TestPlayNowLeadsTheMovesAnnouncementWithoutAPanel looks before
// any such key.
h.press("j")
key := h.s.gameKeyLabel(gaPlayNow) + " play now"

Expand All @@ -410,6 +425,87 @@ func TestPlayNowAndTheSearchShowAtEverySize(t *testing.T) {
}
}

// TestPlayNowLeadsTheMovesAnnouncementWithoutAPanel commits a move from the
// keyboard and then only lets the search run. Nothing else is pressed, so the
// commit's announcement stays the status line's message for the whole search,
// as it does for a player who sits back and waits for the engine. Without a
// panel that line is the only place for the play-now key and the search, and
// the announcement used to take all of it: neither was on screen until some
// other key cleared the message. TestPlayNowAndTheSearchShowAtEverySize
// presses such a key before it looks, which is why it never saw this. With a
// panel the announcement keeps the line to itself, as it always has, and once
// the move arrives its own announcement takes the line at every size.
//
// Both boards are played because the layouts differ: at 40x12 the six-hole
// board leaves room for a panel below it and the full-size board does not.
// 70x12 is added to the supported sizes as a line with no panel beside the
// full-size board that is wide enough for the announcement to follow the key
// and the search whole, which is where it can be seen not to have been lost.
func TestPlayNowLeadsTheMovesAnnouncementWithoutAPanel(t *testing.T) {
sizes := append(slices.Clone(shellSizes), [2]int{70, 12})
var panelless, paneled, followed int
for _, n := range []int{6, 24} {
for _, size := range sizes {
w, ht := size[0], size[1]
panel := ui.Arrange(w, ht, n).Panel
if panel == ui.PanelNone {
panelless++
} else {
paneled++
}
t.Run(fmt.Sprintf("board %d at %dx%d", n, w, ht), func(t *testing.T) {
engine := newGPBot(t)
h := newGSHarness(t, gsTestDeps(t), gsVersusBot(n, engine), w, ht)
h.playTurn(game.Point{Col: 1, Row: 0})
gpEntered(t, engine)
key := h.s.gameKeyLabel(gaPlayNow) + " play now"
announced := h.s.toMoveText()

gpTick(t, h, engine.started.Add(1500*time.Millisecond))
bottom := gpBottom(h.frame())
if panel == ui.PanelNone {
if !strings.HasPrefix(bottom, key+" · 1.5s") {
t.Errorf("with the move's announcement standing, the bottom row %q does not lead with %q and the search's time", bottom, key)
}
} else if bottom != announced {
t.Errorf("with a panel, the bottom row %q is not the move's announcement %q alone", bottom, announced)
}

engine.complete(2, 4321, game.Point{Col: 4, Row: 2})
gpTick(t, h, engine.started.Add(2500*time.Millisecond))
frame := h.frame()
bottom = gpBottom(frame)
if panel == ui.PanelNone {
if !strings.HasPrefix(bottom, key) || !gpCompactDepth2.MatchString(bottom) {
t.Errorf("with the move's announcement standing, the bottom row %q does not lead with %q and the completed depth d2", bottom, key)
}
if whole := key + " · 2.5s d2 · " + announced; ansi.StringWidth(whole) <= w {
if bottom != whole {
t.Errorf("the bottom row %q has room for the announcement after the key and the search, want %q", bottom, whole)
}
followed++
}
} else if bottom != announced {
t.Errorf("with a panel, the bottom row %q is not the move's announcement %q alone", bottom, announced)
}
gsCheckFrame(t, "thinking with the announcement standing", frame, w, ht)

move := game.Point{Col: 4, Row: 2}
engine.release <- move
h.waitFor("the engine's move", func() bool { return h.s.g.At(move) == game.Horizontal })
bottom = gpBottom(h.frame())
if strings.Contains(bottom, key) || !strings.Contains(bottom, "played "+move.String()) {
t.Errorf("once the move has arrived, the bottom row %q is not its announcement", bottom)
}
})
}
}
if panelless == 0 || paneled == 0 || followed == 0 {
t.Fatalf("the sizes covered %d layouts with no panel, %d with one, and %d with room for the announcement after the search; each needs one",
panelless, paneled, followed)
}
}

// --- play now -----------------------------------------------------------------

// TestPlayNowPlaysTheSearchsOwnMoveOnce presses escape during a search that has
Expand Down
Loading
Loading