MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:
- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
elements expire and Context methods are inert: read IsDisabled into a
local during the build, keep a ui.Handle for Focus, use c.Services()
for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
content builds, so same-frame autofocus lost focus restore on close.
It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
split button tooltip no longer reorders its open menu; disabled
menubar rows pass presses to the panel; Form defers blur-started
async checks so the growing message no longer moves Submit away
from the release; Combobox drops its disabled copy now that MyGo
blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
time.Sleep/time.Now and read element state inside the view. The web
mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.
Snapshot goldens are darwin-only and were not re-verified here.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package git
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/internal"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// AnsiTextOptions configure an AnsiText.
|
|
type AnsiTextOptions struct {
|
|
// Wrap breaks long lines at the width.
|
|
Wrap bool
|
|
}
|
|
|
|
// AnsiText renders terminal output with its SGR styles.
|
|
func AnsiText(c *ui.Context, text string, opts AnsiTextOptions) ui.Element {
|
|
k := core.Tokens(c)
|
|
col := ui.Column(c).Font(theme.MonoFont).TextColor(k.Text).Shrink(0)
|
|
col.Children(func() {
|
|
var st internal.AnsiStyle
|
|
for _, line := range strings.Split(text, "\n") {
|
|
var spans []internal.AnsiSpan
|
|
spans, st = internal.ParseAnsi(line, st)
|
|
out := make([]ui.Span, 0, len(spans))
|
|
for _, s := range spans {
|
|
out = append(out, ansiTextSpan(k, s))
|
|
}
|
|
if len(out) == 0 {
|
|
out = append(out, ui.Span{Text: " "})
|
|
}
|
|
t := ui.RichText(c, out...)
|
|
if !opts.Wrap {
|
|
t.NoWrap()
|
|
}
|
|
}
|
|
})
|
|
return col
|
|
}
|
|
|
|
// ansiTextSpan maps one parsed span onto theme-readable colors.
|
|
func ansiTextSpan(k theme.Tokens, s internal.AnsiSpan) ui.Span {
|
|
fg, hasFG := internal.AnsiResolve(k.Dark, s.Style.FG)
|
|
if !hasFG {
|
|
fg = k.Text
|
|
}
|
|
bg, hasBG := internal.AnsiResolve(k.Dark, s.Style.BG)
|
|
if s.Style.Inverse {
|
|
if !hasBG {
|
|
bg = k.Surface
|
|
}
|
|
fg, bg, hasBG = bg, fg, true
|
|
}
|
|
if s.Style.Dim {
|
|
fg = fg.Mix(k.Surface, 0.4)
|
|
}
|
|
out := ui.Span{Text: s.Text, Color: fg, Italic: s.Style.Italic, Underline: s.Style.Underline, Strikethrough: s.Style.Strike}
|
|
if s.Style.Bold {
|
|
out.Weight = 700
|
|
}
|
|
if hasBG {
|
|
out.Background = bg
|
|
}
|
|
return out
|
|
}
|