command.go
This file
Path
input/command.go
79 lines · 1.8 KiB · Go
Last changed by
feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525
History of this fileTake it
The walk stopped after 200 commits: lines older than 19a93b0 point at it.
refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
lines 1–3why, one step back1package input23import (feat(choose,confirm,file,filter,input,table,write): esc exit 1, ctrl+c exit 130, help arrow order (#771)Carlos Alexandro Beckerbefore adoption774667a
line 4why, one step back4 "errors"refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
lines 5–7why, one step back5 "fmt"6 "os"7refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 8–9why, one step back8 "github.com/charmbracelet/bubbles/help"9 "github.com/charmbracelet/bubbles/textinput"refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
line 10why, one step back10 tea "github.com/charmbracelet/bubbletea"refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
line 11why, one step back11 "github.com/charmbracelet/gum/cursor"refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
line 12why, one step back12 "github.com/charmbracelet/gum/internal/stdin"feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
line 13why, one step back13 "github.com/charmbracelet/gum/internal/timeout"feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525
line 14why, one step back14 "github.com/charmbracelet/gum/style"refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
lines 15–19why, one step back15)1617// Run provides a shell script interface for the text input bubble.18// https://github.com/charmbracelet/bubbles/textinput19func (o Options) Run() error {refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
line 20why, one step back20 if o.Value == "" {feat: --no-strip-ansi (#784)Carlos Alexandro Beckerbefore adoption4cedf9f
line 21why, one step back21 if in, _ := stdin.Read(stdin.StripANSI(o.StripANSI)); in != "" {refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 22–26why, one step back22 o.Value = in23 }24 }2526 i := textinput.New()refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
line 27why, one step back27 if o.Value != "" {refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
line 28why, one step back28 i.SetValue(o.Value)feat: --no-strip-ansi (#784)Carlos Alexandro Beckerbefore adoption4cedf9f
line 29why, one step back29 } else if in, _ := stdin.Read(stdin.StripANSI(o.StripANSI)); in != "" {refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
line 30why, one step back30 i.SetValue(in)refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
line 31why, one step back31 }refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 32–40why, one step back32 i.Focus()33 i.Prompt = o.Prompt34 i.Placeholder = o.Placeholder35 i.Width = o.Width36 i.PromptStyle = o.PromptStyle.ToLipgloss()37 i.PlaceholderStyle = o.PlaceholderStyle.ToLipgloss()38 i.Cursor.Style = o.CursorStyle.ToLipgloss()39 i.Cursor.SetMode(cursor.Modes[o.CursorMode])40 i.CharLimit = o.CharLimitrefactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
lines 41–42why, one step back4142 if o.Password {refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 43–44why, one step back43 i.EchoMode = textinput.EchoPassword44 i.EchoCharacter = '•'refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
lines 45–46why, one step back45 }46feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525
line 47why, one step back47 top, right, bottom, left := style.ParsePadding(o.Padding)feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
line 48why, one step back48 m := model{refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 49–51why, one step back49 textinput: i,50 header: o.Header,51 headerStyle: o.HeaderStyle.ToLipgloss(),feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525
line 52why, one step back52 padding: []int{top, right, bottom, left},refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 53–56why, one step back53 autoWidth: o.Width < 1,54 showHelp: o.ShowHelp,55 help: help.New(),56 keymap: defaultKeymap(),feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
lines 57–64why, one step back57 }5859 ctx, cancel := timeout.Context(o.Timeout)60 defer cancel()6162 p := tea.NewProgram(63 m,64 tea.WithOutput(os.Stderr),feat: handle focus/blur events (#749)Carlos Alexandro Beckerbefore adoption71d7e65
line 65why, one step back65 tea.WithReportFocus(),feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
lines 66–67why, one step back66 tea.WithContext(ctx),67 )refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
line 68why, one step back68 tm, err := p.Run()refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
line 69why, one step back69 if err != nil {refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
line 70why, one step back70 return fmt.Errorf("failed to run input: %w", err)refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
lines 71–72why, one step back71 }72feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
line 73why, one step back73 m = tm.(model)feat(choose,confirm,file,filter,input,table,write): esc exit 1, ctrl+c exit 130, help arrow order (#771)Carlos Alexandro Beckerbefore adoption774667a
lines 74–76why, one step back74 if !m.submitted {75 return errors.New("not submitted")76 }refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
line 77why, one step back77 fmt.Println(m.textinput.Value())refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0
lines 78–79why, one step back78 return nil79}