Skip to content

Commit

Permalink
Merge branch 'main' into timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 authored Nov 18, 2024
2 parents fbb0a65 + 3cec9b7 commit a7b0f2c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 2 additions & 0 deletions file/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (o Options) Run() error {
FileAllowed(o.File).
Height(o.Height).
ShowHidden(o.All).
ShowSize(o.Size).
ShowPermissions(o.Permissions).
Value(&path),
),
).
Expand Down
12 changes: 7 additions & 5 deletions file/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ type Options struct {
// Path is the path to the folder / directory to begin traversing.
Path string `arg:"" optional:"" name:"path" help:"The path to the folder to begin traversing" env:"GUM_FILE_PATH"`
// Cursor is the character to display in front of the current selected items.
Cursor string `short:"c" help:"The cursor character" default:">" env:"GUM_FILE_CURSOR"`
All bool `short:"a" help:"Show hidden and 'dot' files" default:"false" env:"GUM_FILE_ALL"`
File bool `help:"Allow files selection" default:"true" env:"GUM_FILE_FILE"`
Directory bool `help:"Allow directories selection" default:"false" env:"GUM_FILE_DIRECTORY"`
ShowHelp bool `help:"Show help key binds" negatable:"" default:"true" env:"GUM_FILE_SHOW_HELP"`
Cursor string `short:"c" help:"The cursor character" default:">" env:"GUM_FILE_CURSOR"`
All bool `short:"a" help:"Show hidden and 'dot' files" default:"false" env:"GUM_FILE_ALL"`
Permissions bool `short:"p" help:"Show file permissions" default:"true" negatable:"" env:"GUM_FILE_PERMISSION"`
Size bool `short:"s" help:"Show file size" default:"true" negatable:"" env:"GUM_FILE_SIZE"`
File bool `help:"Allow files selection" default:"true" env:"GUM_FILE_FILE"`
Directory bool `help:"Allow directories selection" default:"false" env:"GUM_FILE_DIRECTORY"`
ShowHelp bool `help:"Show help key binds" negatable:"" default:"true" env:"GUM_FILE_SHOW_HELP"`

Height int `help:"Maximum number of files to display" default:"0" env:"GUM_FILE_HEIGHT"`
CursorStyle style.Styles `embed:"" prefix:"cursor." help:"The cursor style" set:"defaultForeground=212" envprefix:"GUM_FILE_CURSOR_"`
Expand Down
6 changes: 6 additions & 0 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m *model) CursorUp() {
if len(m.matches) == 0 {
return
}
if m.reverse { //nolint:nestif
m.cursor = (m.cursor + 1) % len(m.matches)
if len(m.matches)-m.cursor <= m.viewport.YOffset {
Expand All @@ -275,6 +278,9 @@ func (m *model) CursorUp() {
}

func (m *model) CursorDown() {
if len(m.matches) == 0 {
return
}
if m.reverse { //nolint:nestif
m.cursor = (m.cursor - 1 + len(m.matches)) % len(m.matches)
if len(m.matches)-m.cursor > m.viewport.Height+m.viewport.YOffset {
Expand Down
18 changes: 3 additions & 15 deletions spin/spin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ package spin

import (
"io"
"os"
"os/exec"
"strings"
"time"

"github.com/charmbracelet/gum/internal/exit"
"github.com/charmbracelet/gum/timeout"
"github.com/charmbracelet/x/term"

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -65,22 +63,12 @@ func commandStart(command []string) tea.Cmd {
if len(command) > 1 {
args = command[1:]
}
cmd := exec.Command(command[0], args...) //nolint:gosec

if term.IsTerminal(os.Stdout.Fd()) {
stdout := io.MultiWriter(&bothbuf, &errbuf)
stderr := io.MultiWriter(&bothbuf, &outbuf)

cmd.Stdout = stdout
cmd.Stderr = stderr
} else {
cmd.Stdout = os.Stdout
}

cmd := exec.Command(command[0], args...) //nolint:gosec
cmd.Stdout = io.MultiWriter(&bothbuf, &outbuf)
cmd.Stderr = io.MultiWriter(&bothbuf, &errbuf)
_ = cmd.Run()

status := cmd.ProcessState.ExitCode()

if status == -1 {
status = 1
}
Expand Down
9 changes: 6 additions & 3 deletions table/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,16 @@ func (o Options) Run() error {
return nil
}

table := table.New(
opts := []table.Option{
table.WithColumns(columns),
table.WithFocused(true),
table.WithHeight(o.Height),
table.WithRows(rows),
table.WithStyles(styles),
)
}
if o.Height > 0 {
opts = append(opts, table.WithHeight(o.Height))
}
table := table.New(opts...)

tm, err := tea.NewProgram(model{table: table}, tea.WithOutput(os.Stderr)).Run()
if err != nil {
Expand Down

0 comments on commit a7b0f2c

Please sign in to comment.