mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 21:55:45 +01:00
Merge 477f76c628 into 06d72ec646
This commit is contained in:
commit
fe84853569
10 changed files with 53 additions and 9 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/paginator"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/internal/tty"
|
||||
|
|
@ -153,7 +154,7 @@ func (o Options) Run() error {
|
|||
defer cancel()
|
||||
|
||||
// Disable Keybindings since we will control it ourselves.
|
||||
tm, err := tea.NewProgram(
|
||||
tm, err := gumtea.NewProgram(
|
||||
m,
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithContext(ctx),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/help"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/exit"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/style"
|
||||
|
|
@ -45,7 +46,7 @@ func (o Options) Run() error {
|
|||
promptStyle: o.PromptStyle.ToLipgloss(),
|
||||
padding: []int{top, right, bottom, left},
|
||||
}
|
||||
tm, err := tea.NewProgram(
|
||||
tm, err := gumtea.NewProgram(
|
||||
m,
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithContext(ctx),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/filepicker"
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/style"
|
||||
)
|
||||
|
|
@ -61,7 +62,7 @@ func (o Options) Run() error {
|
|||
ctx, cancel := timeout.Context(o.Timeout)
|
||||
defer cancel()
|
||||
|
||||
tm, err := tea.NewProgram(
|
||||
tm, err := gumtea.NewProgram(
|
||||
&m,
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithContext(ctx),
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/viewport"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/files"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/internal/tty"
|
||||
|
|
@ -143,7 +144,7 @@ func (o Options) Run() error {
|
|||
}
|
||||
}
|
||||
|
||||
tm, err := tea.NewProgram(m, options...).Run()
|
||||
tm, err := gumtea.NewProgram(m, options...).Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to run filter: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/cursor"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/style"
|
||||
|
|
@ -59,7 +60,7 @@ func (o Options) Run() error {
|
|||
ctx, cancel := timeout.Context(o.Timeout)
|
||||
defer cancel()
|
||||
|
||||
p := tea.NewProgram(
|
||||
p := gumtea.NewProgram(
|
||||
m,
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithReportFocus(),
|
||||
|
|
|
|||
35
internal/gumtea/gumtea.go
Normal file
35
internal/gumtea/gumtea.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Package gumtea wraps tea.NewProgram to allow custom options.
|
||||
package gumtea
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// NewProgram wraps tea.NewProgram, injecting options from the environment.
|
||||
func NewProgram(model tea.Model, baseOpts ...tea.ProgramOption) *tea.Program {
|
||||
opts := append(baseOpts, loadOptionsFromEnv()...)
|
||||
return tea.NewProgram(model, opts...)
|
||||
}
|
||||
|
||||
// loadOptionsFromEnv loads options from environment variables.
|
||||
// This feature is provisional. It may be altered or removed in a future version of this package.
|
||||
func loadOptionsFromEnv() []tea.ProgramOption {
|
||||
var opts []tea.ProgramOption
|
||||
|
||||
if fps := os.Getenv("GUM_FPS"); fps != "" {
|
||||
if v, err := strconv.Atoi(fps); err == nil && v > 0 {
|
||||
opts = append(opts, tea.WithFPS(v))
|
||||
}
|
||||
}
|
||||
|
||||
if alt := os.Getenv("GUM_ALTSCREEN"); alt != "" {
|
||||
if altEnabled, err := strconv.ParseBool(alt); err == nil && altEnabled {
|
||||
opts = append(opts, tea.WithAltScreen())
|
||||
}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/viewport"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
)
|
||||
|
|
@ -47,7 +48,7 @@ func (o Options) Run() error {
|
|||
ctx, cancel := timeout.Context(o.Timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := tea.NewProgram(
|
||||
_, err := gumtea.NewProgram(
|
||||
m,
|
||||
tea.WithAltScreen(),
|
||||
tea.WithReportFocus(),
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/spinner"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/exit"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/style"
|
||||
"github.com/charmbracelet/x/term"
|
||||
|
|
@ -37,7 +38,7 @@ func (o Options) Run() error {
|
|||
ctx, cancel := timeout.Context(o.Timeout)
|
||||
defer cancel()
|
||||
|
||||
tm, err := tea.NewProgram(
|
||||
tm, err := gumtea.NewProgram(
|
||||
m,
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithContext(ctx),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/table"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/style"
|
||||
|
|
@ -150,7 +151,7 @@ func (o Options) Run() error {
|
|||
keymap: defaultKeymap(),
|
||||
padding: []int{top, right, bottom, left},
|
||||
}
|
||||
tm, err := tea.NewProgram(
|
||||
tm, err := gumtea.NewProgram(
|
||||
m,
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithContext(ctx),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/charmbracelet/bubbles/textarea"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/cursor"
|
||||
"github.com/charmbracelet/gum/internal/gumtea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
"github.com/charmbracelet/gum/style"
|
||||
|
|
@ -68,7 +69,7 @@ func (o Options) Run() error {
|
|||
ctx, cancel := timeout.Context(o.Timeout)
|
||||
defer cancel()
|
||||
|
||||
p := tea.NewProgram(
|
||||
p := gumtea.NewProgram(
|
||||
m,
|
||||
tea.WithOutput(os.Stderr),
|
||||
tea.WithReportFocus(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue