mirror of
https://github.com/charmbracelet/gum
synced 2024-05-21 23:56:43 +02:00
fix: strip ansi from gum filter when output is not a tty
This commit is contained in:
parent
6dbadf30b4
commit
5887a10fa0
|
@ -10,8 +10,10 @@ import (
|
|||
"github.com/charmbracelet/bubbles/textinput"
|
||||
"github.com/charmbracelet/bubbles/viewport"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/sahilm/fuzzy"
|
||||
|
||||
"github.com/charmbracelet/gum/ansi"
|
||||
"github.com/charmbracelet/gum/internal/exit"
|
||||
"github.com/charmbracelet/gum/internal/files"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
|
@ -98,15 +100,25 @@ func (o Options) Run() error {
|
|||
return exit.ErrAborted
|
||||
}
|
||||
|
||||
isTTY := isatty.IsTerminal(os.Stdout.Fd())
|
||||
|
||||
// allSelections contains values only if limit is greater
|
||||
// than 1 or if flag --no-limit is passed, hence there is
|
||||
// no need to further checks
|
||||
if len(m.selected) > 0 {
|
||||
for k := range m.selected {
|
||||
fmt.Println(k)
|
||||
if isTTY {
|
||||
fmt.Println(k)
|
||||
} else {
|
||||
fmt.Println(ansi.Strip(k))
|
||||
}
|
||||
}
|
||||
} else if len(m.matches) > m.cursor && m.cursor >= 0 {
|
||||
fmt.Println(m.matches[m.cursor].Str)
|
||||
if isTTY {
|
||||
fmt.Println(m.matches[m.cursor].Str)
|
||||
} else {
|
||||
fmt.Println(ansi.Strip(m.matches[m.cursor].Str))
|
||||
}
|
||||
}
|
||||
|
||||
if !o.Strict && len(m.textinput.Value()) != 0 && len(m.matches) == 0 {
|
||||
|
|
Loading…
Reference in a new issue