Files
openchamber-android-native/third_party/mygo/plugins/terminal/appearance_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

88 lines
2.5 KiB
Go

package terminal
import (
"fmt"
"strings"
"testing"
)
// A server's terminal has no View, but applications must still be able
// to query the colors configured for it.
func TestHeadlessThemeQueries(t *testing.T) {
loadLib(t)
for _, tc := range []struct {
name string
theme *Theme
mode int
}{
{"light", LightTheme(), 2},
{"dark", DarkTheme(), 1},
} {
t.Run(tc.name, func(t *testing.T) {
p := newPipe()
term, err := New(Options{Conn: p, Theme: tc.theme})
if err != nil {
t.Fatal(err)
}
defer term.Close()
term.Feed([]byte("\x1b]10;?\x1b\\\x1b]11;?\x1b\\\x1b[?996n"))
got := p.take(term)
for _, color := range []struct {
index int
r, g, b uint8
}{
{10, tc.theme.Foreground.R, tc.theme.Foreground.G, tc.theme.Foreground.B},
{11, tc.theme.Background.R, tc.theme.Background.G, tc.theme.Background.B},
} {
want := fmt.Sprintf("\x1b]%d;rgb:%04x/%04x/%04x\x1b\\", color.index,
uint16(color.r)*257, uint16(color.g)*257, uint16(color.b)*257)
if !strings.Contains(got, want) {
t.Errorf("query OSC %d: got %q, want %q", color.index, got, want)
}
}
if want := fmt.Sprintf("\x1b[?997;%dn", tc.mode); !strings.Contains(got, want) {
t.Errorf("scheme query: got %q, want %q", got, want)
}
})
}
}
func TestHeadlessAppearanceChanges(t *testing.T) {
loadLib(t)
p := newPipe()
term, err := New(Options{Conn: p, Theme: LightTheme()})
if err != nil {
t.Fatal(err)
}
defer term.Close()
// Applications that did not subscribe must receive no unsolicited
// input. Once subscribed, each preference change produces one report.
term.UseTheme(DarkTheme())
if got := p.take(term); got != "" {
t.Fatalf("unsubscribed application received %q", got)
}
term.Feed([]byte("\x1b[?2031h"))
p.take(term)
term.UseTheme(LightTheme())
if got, want := p.take(term), "\x1b[?997;2n"; got != want {
t.Fatalf("light change = %q, want %q", got, want)
}
term.UseTheme(LightTheme())
if got := p.take(term); got != "" {
t.Fatalf("unchanged preference sent %q", got)
}
term.UseTheme(DarkTheme())
if got, want := p.take(term), "\x1b[?997;1n"; got != want {
t.Fatalf("dark change = %q, want %q", got, want)
}
term.Feed([]byte("\x1b[?996n"))
if got, want := p.take(term), "\x1b[?997;1n"; got != want {
t.Fatalf("query after change = %q, want %q", got, want)
}
term.Feed([]byte("\x1b[?2031l"))
term.UseTheme(LightTheme())
if got := p.take(term); got != "" {
t.Fatalf("unsubscribed application received %q", got)
}
}