gum/file/command.go
Maas Lalani 995bd04e38 docs: document gum table, file, pager
This commit documents `gum table`, `gum file`, and `gum pager` with
demonstration GIFs and sample scripts.
2022-10-07 15:38:48 -04:00

59 lines
1.3 KiB
Go

package file
import (
"fmt"
"os"
"path/filepath"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/gum/internal/stack"
)
// Run is the interface to picking a file.
func (o Options) Run() error {
if o.Path == "" {
o.Path = "."
}
path, err := filepath.Abs(o.Path)
if err != nil {
return fmt.Errorf("file not found: %w", err)
}
m := model{
path: path,
cursor: o.Cursor,
selected: 0,
showHidden: o.All,
autoHeight: o.Height == 0,
height: o.Height,
max: 0,
min: 0,
selectedStack: stack.NewStack(),
minStack: stack.NewStack(),
maxStack: stack.NewStack(),
cursorStyle: o.CursorStyle.ToLipgloss(),
symlinkStyle: o.SymlinkStyle.ToLipgloss(),
directoryStyle: o.DirectoryStyle.ToLipgloss(),
fileStyle: o.FileStyle.ToLipgloss(),
permissionStyle: o.PermissionsStyle.ToLipgloss(),
selectedStyle: o.SelectedStyle.ToLipgloss(),
fileSizeStyle: o.FileSizeStyle.ToLipgloss(),
}
tm, err := tea.NewProgram(&m, tea.WithOutput(os.Stderr)).StartReturningModel()
if err != nil {
return fmt.Errorf("unable to pick selection: %w", err)
}
m = tm.(model)
if m.path == "" {
os.Exit(1)
}
fmt.Println(m.path)
return nil
}