From 7d9fcad9a447a64513b30cb2566141c9d70941b3 Mon Sep 17 00:00:00 2001 From: VB Date: Tue, 29 Sep 2026 17:20:28 +0400 Subject: [PATCH 1/4] Reproduce graphics detection through installer terminal handoff --- .github/workflows/probe-investigation.yml | 28 +++++ client/terminal_probe_test.go | 121 ++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 .github/workflows/probe-investigation.yml create mode 100644 client/terminal_probe_test.go diff --git a/.github/workflows/probe-investigation.yml b/.github/workflows/probe-investigation.yml new file mode 100644 index 0000000..c22455b --- /dev/null +++ b/.github/workflows/probe-investigation.yml @@ -0,0 +1,28 @@ +name: Terminal probe investigation +on: + push: + branches: [fix/installer-terminal-probe] +permissions: + contents: read +jobs: + probe: + runs-on: ${{ matrix.os }} + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + os: [ubuntu-24.04, macos-15, macos-15-intel] + env: + PUPPETEER_SKIP_DOWNLOAD: 'true' + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '24' + cache: npm + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - run: npm ci + - run: npm run build:proto:go + - run: go test -count=1 -v -timeout=60s ./client -run '^TestGraphicsProbePTY' diff --git a/client/terminal_probe_test.go b/client/terminal_probe_test.go new file mode 100644 index 0000000..b432c67 --- /dev/null +++ b/client/terminal_probe_test.go @@ -0,0 +1,121 @@ +package main + +import ( + "bytes" + "context" + "fmt" + "io" + "os" + "os/exec" + "reflect" + "strings" + "testing" + "time" + + "github.com/creack/pty" + "golang.org/x/sys/unix" + "golang.org/x/term" +) + +// A direct PTY slave and an explicitly reopened /dev/tty are different devices +// on macOS. Exercise the installer-style pipe and redirection, not just a PTY. +func TestGraphicsProbePTY(t *testing.T) { + executable, err := os.Executable() + if err != nil { + t.Fatal(err) + } + for _, tc := range []struct { + name, launch, renderer string + delay time.Duration + }{ + {"direct-kitty", "direct", "kitty", 500 * time.Millisecond}, + {"redirect-kitty", "redirect", "kitty", 0}, + {"installer-kitty", "pipe", "kitty", 500 * time.Millisecond}, + {"installer-sixel", "pipe", "sixel", 500 * time.Millisecond}, + {"installer-no-response", "pipe", "tcell", 0}, + } { + t.Run(tc.name, func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second) + defer cancel() + cmd := exec.CommandContext(ctx, executable, "-test.run=^TestGraphicsProbePTYHelper$") + switch tc.launch { + case "redirect": + cmd = exec.CommandContext(ctx, "bash", "-c", `exec "$TERMIUM_PROBE_EXECUTABLE" -test.run=^TestGraphicsProbePTYHelper$ Date: Tue, 29 Sep 2026 17:22:49 +0400 Subject: [PATCH 2/4] Keep terminal probe regression focused on renderer selection --- client/terminal_probe_test.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/client/terminal_probe_test.go b/client/terminal_probe_test.go index b432c67..00215ac 100644 --- a/client/terminal_probe_test.go +++ b/client/terminal_probe_test.go @@ -7,14 +7,12 @@ import ( "io" "os" "os/exec" - "reflect" "strings" "testing" "time" "github.com/creack/pty" "golang.org/x/sys/unix" - "golang.org/x/term" ) // A direct PTY slave and an explicitly reopened /dev/tty are different devices @@ -100,21 +98,10 @@ func TestGraphicsProbePTYHelper(t *testing.T) { if want == "" { return } - before, err := term.GetState(0) - if err != nil { - t.Fatal(err) - } fds := []unix.PollFd{{Fd: 0, Events: unix.POLLIN}} n, pollErr := unix.Poll(fds, 0) fmt.Fprintf(os.Stderr, "initial poll: n=%d revents=%#x err=%v\n", n, fds[0].Revents, pollErr) got := detectRenderer() - after, err := term.GetState(0) - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(before, after) { - t.Fatal("graphics detection did not restore terminal settings") - } if got != want { t.Fatalf("renderer=%s, want %s", got, want) } From 0db126d688c781a97ea1f529f5ebecf9cdd7f9b9 Mon Sep 17 00:00:00 2001 From: VB Date: Tue, 29 Sep 2026 17:24:09 +0400 Subject: [PATCH 3/4] Use select for terminal probes reopened through dev tty on macOS --- client/main.go | 34 ++++++++++++++++++++++++++++------ docs/releases/v0.2.4.md | 23 +++++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 docs/releases/v0.2.4.md diff --git a/client/main.go b/client/main.go index 9a14abf..8fb7c04 100644 --- a/client/main.go +++ b/client/main.go @@ -848,6 +848,7 @@ func detectTerminalAndCalibrate() { setDefaultCharSize() if cfg.Renderer == "auto" { cfg.Renderer = detectRenderer() + Debug(fmt.Sprintf("Graphics auto-detection selected %s", cfg.Renderer), INFO) } if cfg.Renderer == "tcell" { return @@ -867,6 +868,11 @@ func detectRenderer() string { if err == nil && strings.Contains(response, "i=31;OK") { return "kitty" } + if err != nil { + Debug(fmt.Sprintf("Kitty graphics probe failed: %v", err), DEBUG) + } else { + Debug("Kitty graphics probe did not report support", DEBUG) + } response, err = queryTerminalWithTimeout("\033[c", graphicsProbeTimeoutMs) if err == nil { for _, parameter := range strings.Split(strings.TrimSuffix(strings.TrimPrefix(response, "\033[?"), "c"), ";") { @@ -874,12 +880,17 @@ func detectRenderer() string { return "sixel" } } + } else { + Debug(fmt.Sprintf("Sixel graphics probe failed: %v", err), DEBUG) } return "tcell" } func queryTerminalWithTimeout(query string, timeoutMs int) (string, error) { fd := int(os.Stdin.Fd()) + if fd < 0 || fd >= unix.FD_SETSIZE { + return "", fmt.Errorf("terminal descriptor %d is outside select range", fd) + } old, err := term.MakeRaw(fd) if err != nil { return "", err @@ -891,25 +902,36 @@ func queryTerminalWithTimeout(query string, timeoutMs int) (string, error) { deadline := time.Now().Add(time.Duration(timeoutMs) * time.Millisecond) response := make([]byte, 0, 128) for time.Now().Before(deadline) { - poll := []unix.PollFd{{Fd: int32(fd), Events: unix.POLLIN}} - n, err := unix.Poll(poll, max(1, int(time.Until(deadline).Milliseconds()))) + remaining := time.Until(deadline) + if remaining <= 0 { + break + } + // The installer reopens stdin through /dev/tty. Darwin's poll returns + // POLLNVAL for that device even though reads work; select supports it. + var readable unix.FdSet + readable.Set(fd) + timeout := unix.NsecToTimeval(remaining.Nanoseconds()) + n, err := unix.Select(fd+1, &readable, nil, nil, &timeout) if err == unix.EINTR { continue } if err != nil { - return "", err + return "", fmt.Errorf("waiting for terminal response: %w", err) } if n == 0 { break } - if poll[0].Revents&unix.POLLIN == 0 { - return "", fmt.Errorf("terminal closed") - } buf := make([]byte, 128) n, err = unix.Read(fd, buf) + if err == unix.EINTR { + continue + } if err != nil { return "", err } + if n == 0 { + return "", io.EOF + } response = append(response, buf[:n]...) text := string(response) if strings.HasSuffix(text, "t") || strings.HasSuffix(text, "c") || strings.HasSuffix(text, "\033\\") { diff --git a/docs/releases/v0.2.4.md b/docs/releases/v0.2.4.md new file mode 100644 index 0000000..df7d708 --- /dev/null +++ b/docs/releases/v0.2.4.md @@ -0,0 +1,23 @@ +# Termium v0.2.4 + +Fix graphics detection when the macOS installer automatically launches Termium, +or when launching with input redirected from `/dev/tty`. + +The installer reopens terminal input because its script arrives through a pipe. +On macOS, `poll()` reports that reopened device as invalid, causing an immediate +fallback to ASCII graphics. Increasing the timeout in v0.2.3 did not address this +failure. Terminal queries now use `select()`, which supports the device; the +one-second graphics probe deadlines remain. + +Debug logs now record graphics probe errors and the automatically selected +renderer. Regression tests exercise direct launch, `/dev/tty` redirection, and +the installer's pipe-and-launch handoff, including delayed responses and ASCII +fallback when no graphics protocol responds. + +Close Termium, then update: + +```sh +curl -fsSL https://termium.dev/install | bash +``` + +After quitting, `termium --version` should report `v0.2.4`. From 557897513dc2d4fd2410dfe70812fc6e35d8481d Mon Sep 17 00:00:00 2001 From: VB Date: Tue, 29 Sep 2026 17:24:59 +0400 Subject: [PATCH 4/4] Keep probe regression in normal platform CI after investigation --- .github/workflows/probe-investigation.yml | 28 ----------------------- 1 file changed, 28 deletions(-) delete mode 100644 .github/workflows/probe-investigation.yml diff --git a/.github/workflows/probe-investigation.yml b/.github/workflows/probe-investigation.yml deleted file mode 100644 index c22455b..0000000 --- a/.github/workflows/probe-investigation.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Terminal probe investigation -on: - push: - branches: [fix/installer-terminal-probe] -permissions: - contents: read -jobs: - probe: - runs-on: ${{ matrix.os }} - timeout-minutes: 10 - strategy: - fail-fast: false - matrix: - os: [ubuntu-24.04, macos-15, macos-15-intel] - env: - PUPPETEER_SKIP_DOWNLOAD: 'true' - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: '24' - cache: npm - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - run: npm ci - - run: npm run build:proto:go - - run: go test -count=1 -v -timeout=60s ./client -run '^TestGraphicsProbePTY'