Skip to content

Init stage produces unwanted terminal output when run via expect spawn #1572

@lonnywong

Description

@lonnywong

Describe the bug
The init() function calls _ = lipgloss.HasDarkBackground(), which accesses the terminal and produces OSC/DSR sequences (e.g., ^[]11;rgb:0000/0000/0000^[\^[[78;1R) before main().
This output appears when the program is run via spawn in an expect script.

Setup

  • OS: macOS
  • Shell: bash
  • Terminal Emulator: iTerm2
  • Terminal Multiplexer: no

To Reproduce

  1. Write an expect script that uses spawn to run a Bubble Tea program.
  2. Observe that terminal sequences are printed before main() executes.

Source Code

#!/usr/bin/env expect
spawn ./program
expect "Hello"
interact
package main

import (
        "flag"
        "fmt"

        tea "github.com/charmbracelet/bubbletea"
)

func main() {
        useTea := flag.Bool("tea", false, "use Bubble Tea")
        flag.Parse()

        if *useTea {
                tea.Println("Hello, Tea.")
                return
        }

        fmt.Println("Hello, World.")
}

Expected behavior
The init() function should not produce unwanted terminal output when the program is run via spawn in an expect script.

Screenshots

$ ./expect.sh
spawn ./program
^[]11;rgb:0000/0000/0000^[\^[[78;1RHello, World.
^[]11;rgb:0000/0000/0000^[\^[[78;1R

Additional context
Consider performing terminal detection lazily, e.g., with sync.Once when it is actually needed in the program.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions