Skip to content
Myr

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 file

Take 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 back
1package input
23import (

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 back
4 "errors"

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 5–7why, one step back
5 "fmt"
6 "os"7

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

lines 8–9why, one step back
8 "github.com/charmbracelet/bubbles/help"
9 "github.com/charmbracelet/bubbles/textinput"

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 10why, one step back
10 tea "github.com/charmbracelet/bubbletea"

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

line 11why, one step back
11 "github.com/charmbracelet/gum/cursor"

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 12why, one step back
12 "github.com/charmbracelet/gum/internal/stdin"

feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952

line 13why, one step back
13 "github.com/charmbracelet/gum/internal/timeout"

feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525

line 14why, one step back
14 "github.com/charmbracelet/gum/style"

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 15–19why, one step back
15)
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 back
20 if o.Value == "" {

feat: --no-strip-ansi (#784)Carlos Alexandro Beckerbefore adoption4cedf9f

line 21why, one step back
21 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 back
22 o.Value = in
23 }24 }2526 i := textinput.New()

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 27why, one step back
27 if o.Value != "" {

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

line 28why, one step back
28 i.SetValue(o.Value)

feat: --no-strip-ansi (#784)Carlos Alexandro Beckerbefore adoption4cedf9f

line 29why, one step back
29 } 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 back
30 i.SetValue(in)

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 31why, one step back
31 }

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

lines 32–40why, one step back
32 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.CharLimit

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 41–42why, one step back
41
42 if o.Password {

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

lines 43–44why, one step back
43 i.EchoMode = textinput.EchoPassword
44 i.EchoCharacter = '•'

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 45–46why, one step back
45 }
46

feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525

line 47why, one step back
47 top, right, bottom, left := style.ParsePadding(o.Padding)

feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952

line 48why, one step back
48 m := model{

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

lines 49–51why, one step back
49 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 back
52 padding: []int{top, right, bottom, left},

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

lines 53–56why, one step back
53 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 back
57 }
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 back
65 tea.WithReportFocus(),

feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952

lines 66–67why, one step back
66 tea.WithContext(ctx),
67 )

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

line 68why, one step back
68 tm, err := p.Run()

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 69why, one step back
69 if err != nil {

refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e

line 70why, one step back
70 return fmt.Errorf("failed to run input: %w", err)

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 71–72why, one step back
71 }
72

feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952

line 73why, one step back
73 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 back
74 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 back
77 fmt.Println(m.textinput.Value())

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 78–79why, one step back
78 return nil
79}