Skip to content

Commit

Permalink
fix: force query the terminal bg before running any programs
Browse files Browse the repository at this point in the history
Hack!

This forces a bg/fg query on the default os.Stdout and os.Stdin before
starting any bubbletea program. Otherwise, programs might hang before
the query finishes. This is because at that point, the bubbletea already
acquired the terminal os.Stdin and termenv cannot read from it. The
termenv query timeout can be adjusted using `termenv.OSCTimeout`.

Note that this will only work for the default IO i.e. os.Stdout and
os.Stdin.

docs: copyedits in Lip Gloss/Termenv workaround for clarity

Co-authored-by: Christian Rocha <christian@rocha.is>
  • Loading branch information
aymanbagabas and meowgorithm committed Aug 22, 2024
1 parent d6a19f0 commit d6458e0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tea_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package tea

import (
"github.com/charmbracelet/lipgloss"
)

func init() {
// XXX: This is a workaround to make assure that Lip Gloss and Termenv
// query the terminal before any Bubble Tea Program runs and acquires the
// terminal. Without this, Programs that use Lip Gloss/Termenv might hang
// while waiting for a a [termenv.OSCTimeout] while querying the terminal
// for its background/foreground colors.
//
// This happens because Bubble Tea acquires the terminal before termenv
// reads any responses.
//
// Note that this will only affect programs running on the default IO i.e.
// [os.Stdout] and [os.Stdin].
//
// This workaround will be removed in v2.
_ = lipgloss.HasDarkBackground()
}

0 comments on commit d6458e0

Please sign in to comment.