diff --git a/bubbletea/query.go b/bubbletea/query.go deleted file mode 100644 index cc456171..00000000 --- a/bubbletea/query.go +++ /dev/null @@ -1,95 +0,0 @@ -package bubbletea - -import ( - "image/color" - "io" - "time" - - "github.com/charmbracelet/x/ansi" - "github.com/charmbracelet/x/input" -) - -// queryBackgroundColor queries the terminal for the background color. -// If the terminal does not support querying the background color, nil is -// returned. -// -// Note: you will need to set the input to raw mode before calling this -// function. -// -// state, _ := term.MakeRaw(in.Fd()) -// defer term.Restore(in.Fd(), state) -// -// copied from x/term@v0.1.3. -func queryBackgroundColor(in io.Reader, out io.Writer) (c color.Color, err error) { - // nolint: errcheck - err = queryTerminal(in, out, defaultQueryTimeout, - func(events []input.Event) bool { - for _, e := range events { - switch e := e.(type) { - case input.BackgroundColorEvent: - c = e.Color - continue // we need to consume the next DA1 event - case input.PrimaryDeviceAttributesEvent: - return false - } - } - return true - }, ansi.RequestBackgroundColor+ansi.RequestPrimaryDeviceAttributes) - return -} - -const defaultQueryTimeout = time.Second * 2 - -// QueryTerminalFilter is a function that filters input events using a type -// switch. If false is returned, the QueryTerminal function will stop reading -// input. -type QueryTerminalFilter func(events []input.Event) bool - -// queryTerminal queries the terminal for support of various features and -// returns a list of response events. -// Most of the time, you will need to set stdin to raw mode before calling this -// function. -// Note: This function will block until the terminal responds or the timeout -// is reached. -// copied from x/term@v0.1.3. -func queryTerminal( - in io.Reader, - out io.Writer, - timeout time.Duration, - filter QueryTerminalFilter, - query string, -) error { - rd, err := input.NewReader(in, "", 0) - if err != nil { - return err - } - - defer rd.Close() // nolint: errcheck - - done := make(chan struct{}, 1) - defer close(done) - go func() { - select { - case <-done: - case <-time.After(timeout): - rd.Cancel() - } - }() - - if _, err := io.WriteString(out, query); err != nil { - return err - } - - for { - events, err := rd.ReadEvents() - if err != nil { - return err - } - - if !filter(events) { - break - } - } - - return nil -} diff --git a/go.mod b/go.mod index 5e9f5496..49b15bb0 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,10 @@ go 1.21 require ( github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.2.0.20250114183556-4f0e1e15a2b2 + github.com/charmbracelet/colorprofile v0.1.8 github.com/charmbracelet/keygen v0.5.1 github.com/charmbracelet/log/v2 v2.0.0-20250114165231-978e92235d71 github.com/charmbracelet/ssh v0.0.0-20241211182756-4fe22b0f1b7c - github.com/charmbracelet/x/ansi v0.7.0 - github.com/charmbracelet/x/input v0.3.1-0.20250113133550-1814328524c0 github.com/go-git/go-git/v5 v5.13.1 github.com/google/go-cmp v0.6.0 github.com/hashicorp/golang-lru/v2 v2.0.7 @@ -23,11 +22,12 @@ require ( github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v1.1.3 // indirect github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect - github.com/charmbracelet/colorprofile v0.1.8 // indirect github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20250114171829-b67eb015d607 // indirect + github.com/charmbracelet/x/ansi v0.7.0 // indirect github.com/charmbracelet/x/cellbuf v0.0.6 // indirect github.com/charmbracelet/x/conpty v0.1.0 // indirect github.com/charmbracelet/x/errors v0.0.0-20240508181413-e8d8b6e2de86 // indirect + github.com/charmbracelet/x/input v0.3.1-0.20250113133550-1814328524c0 // indirect github.com/charmbracelet/x/term v0.2.1 // indirect github.com/charmbracelet/x/termios v0.1.0 // indirect github.com/charmbracelet/x/vt v0.0.0-20241121165045-a3720547cbb4 // indirect