Files
8bitMyGoUI/code/commandhistory.go
T
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
Elements are now pass-scoped value handles: tests that read bounds
after a frame bind a ui.Handle. pixel tells frames apart by the build
pass's root, since the Tester clock no longer moves on its own.

Fix the regressions the upgrade brought:
- Clipboard reads in input handlers go through c.Services().
- MyGo notes an overlay's opener after building it, so AutoFocus
  inside lost it; pixel.AutoFocus focuses through a Handle, and
  archtest bans the raw call. Dialogs hand the focus back again.
- Elements around a press stay hovered: Tooltip tells a press-given
  focus by focus arriving under the pointer.
- The web host moves the Tester clock with real time, at most 500 ms
  a call, and gives components the real clock.

The gallery's source index also accepts CRLF checkouts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:31:08 -04:00

42 lines
1.3 KiB
Go

package code
import (
"log/slog"
"strconv"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type CommandHistoryOptions struct {
// Width and Height are dots; zeros mean 200 by 120.
Width, Height int
Disabled bool
}
type CommandHistoryResult struct {
Element ui.Element
// Rerun is Enter or a double click on a command.
Changed, Rerun bool
}
// CommandHistory numbers past commands; Enter reruns one.
func CommandHistory(c *ui.Context, text string, commands []string, selected *int, o CommandHistoryOptions) CommandHistoryResult {
k := pixel.K(c)
var r data.ListResult
e := ui.Box(c).Width(k.D(pixel.Or("CommandHistory Width", o.Width, 200))).Children(func() {
r = data.List(c, text, len(commands), selected, data.ListOptions{Height: o.Height, Disabled: o.Disabled}, func(i int) string { return commands[i] }, func(i int) {
ui.Row(c).Gap(k.D(4)).Children(func() {
pixel.Text(c, strconv.Itoa(i+1), pixel.TextOptions{Slot: pixel.Faint})
pixel.Text(c, commands[i], pixel.TextOptions{MaxLines: 1})
})
})
})
if r.Submitted {
slog.Debug("8bit: command history rerun", "label", text, "index", *selected)
}
return CommandHistoryResult{Element: e, Changed: r.Changed, Rerun: r.Submitted}
}