mirror of
https://github.com/charmbracelet/gum.git
synced 2024-09-11 06:16:03 +03:00
refactor: use x/term instead of go-isatty
This commit is contained in:
parent
f159a0b1af
commit
405f246635
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/charmbracelet/x/term"
|
||||
|
||||
"github.com/charmbracelet/gum/ansi"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
@ -88,7 +88,6 @@ func (o Options) Run() error {
|
||||
WithTheme(theme).
|
||||
WithTimeout(o.Timeout).
|
||||
Run()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -115,12 +114,11 @@ func (o Options) Run() error {
|
||||
WithShowHelp(o.ShowHelp).
|
||||
WithTimeout(o.Timeout).
|
||||
Run()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
if term.IsTerminal(os.Stdout.Fd()) {
|
||||
fmt.Println(choice)
|
||||
} else {
|
||||
fmt.Print(ansi.Strip(choice))
|
||||
@ -141,7 +139,7 @@ func widest(options []string) int {
|
||||
}
|
||||
|
||||
func ansiprint(s string) {
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
if term.IsTerminal(os.Stdout.Fd()) {
|
||||
fmt.Println(s)
|
||||
} else {
|
||||
fmt.Print(ansi.Strip(s))
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
"github.com/charmbracelet/bubbles/viewport"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/charmbracelet/x/term"
|
||||
"github.com/sahilm/fuzzy"
|
||||
|
||||
"github.com/charmbracelet/gum/ansi"
|
||||
@ -106,7 +106,7 @@ func (o Options) Run() error {
|
||||
return exit.ErrAborted
|
||||
}
|
||||
|
||||
isTTY := isatty.IsTerminal(os.Stdout.Fd())
|
||||
isTTY := term.IsTerminal(os.Stdout.Fd())
|
||||
|
||||
// allSelections contains values only if limit is greater
|
||||
// than 1 or if flag --no-limit is passed, hence there is
|
||||
|
4
go.mod
4
go.mod
@ -12,7 +12,7 @@ require (
|
||||
github.com/charmbracelet/lipgloss v0.11.0
|
||||
github.com/charmbracelet/log v0.4.0
|
||||
github.com/charmbracelet/x/ansi v0.1.4
|
||||
github.com/mattn/go-isatty v0.0.20
|
||||
github.com/charmbracelet/x/term v0.1.1
|
||||
github.com/muesli/reflow v0.3.0
|
||||
github.com/muesli/roff v0.1.0
|
||||
github.com/muesli/termenv v0.15.2
|
||||
@ -27,7 +27,6 @@ require (
|
||||
github.com/catppuccin/go v0.2.0 // indirect
|
||||
github.com/charmbracelet/x/exp/strings v0.0.0-20240617190524-788ec55faed1 // indirect
|
||||
github.com/charmbracelet/x/input v0.1.2 // indirect
|
||||
github.com/charmbracelet/x/term v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.1.2 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
@ -35,6 +34,7 @@ require (
|
||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||
github.com/gorilla/css v1.0.1 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/charmbracelet/bubbles/spinner"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/charmbracelet/x/term"
|
||||
|
||||
"github.com/charmbracelet/gum/internal/exit"
|
||||
)
|
||||
@ -14,7 +14,7 @@ import (
|
||||
// Run provides a shell script interface for the spinner bubble.
|
||||
// https://github.com/charmbracelet/bubbles/spinner
|
||||
func (o Options) Run() error {
|
||||
isTTY := isatty.IsTerminal(os.Stdout.Fd())
|
||||
isTTY := term.IsTerminal(os.Stdout.Fd())
|
||||
|
||||
s := spinner.New()
|
||||
s.Style = o.SpinnerStyle.ToLipgloss()
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
|
||||
"github.com/charmbracelet/gum/internal/exit"
|
||||
"github.com/charmbracelet/gum/timeout"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/charmbracelet/x/term"
|
||||
|
||||
"github.com/charmbracelet/bubbles/spinner"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
@ -66,7 +66,7 @@ func commandStart(command []string) tea.Cmd {
|
||||
}
|
||||
|
||||
cmd := exec.Command(command[0], args...) //nolint:gosec
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
if term.IsTerminal(os.Stdout.Fd()) {
|
||||
stdout := io.MultiWriter(&bothbuf, &errbuf)
|
||||
stderr := io.MultiWriter(&bothbuf, &outbuf)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user