Skip to content
Myr

command.go

This file

Path

write/command.go

87 lines · 2.2 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 write
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

line 5why, one step back
5 "fmt"

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

line 6why, one step back
6 "os"

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 7–8why, one step back
7 "strings"
8

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

lines 9–12why, one step back
9 "github.com/charmbracelet/bubbles/help"
10 "github.com/charmbracelet/bubbles/textarea"11 tea "github.com/charmbracelet/bubbletea"12 "github.com/charmbracelet/gum/cursor"

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

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

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

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

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

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

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 16–20why, one step back
16)
1718// Run provides a shell script interface for the text area bubble.19// https://github.com/charmbracelet/bubbles/textarea20func (o Options) Run() error {

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

line 21why, one step back
21 in, _ := stdin.Read(stdin.StripANSI(o.StripANSI))

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 22–25why, one step back
22 if in != "" && o.Value == "" {
23 o.Value = strings.ReplaceAll(in, "\r", "")24 }25

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

lines 26–27why, one step back
26 a := textarea.New()
27 a.Focus()

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 28why, one step back
28

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

lines 29–32why, one step back
29 a.Prompt = o.Prompt
30 a.Placeholder = o.Placeholder31 a.ShowLineNumbers = o.ShowLineNumbers32 a.CharLimit = o.CharLimit

fix(write): max height, max chars (#753)Carlos Alexandro Beckerbefore adoption01892a0

line 33why, one step back
33 a.MaxHeight = o.MaxLines

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

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

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 35why, one step back
35

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

lines 36–44why, one step back
36 style := textarea.Style{
37 Base: o.BaseStyle.ToLipgloss(),38 Placeholder: o.PlaceholderStyle.ToLipgloss(),39 CursorLine: o.CursorLineStyle.ToLipgloss(),40 CursorLineNumber: o.CursorLineNumberStyle.ToLipgloss(),41 EndOfBuffer: o.EndOfBufferStyle.ToLipgloss(),42 LineNumber: o.LineNumberStyle.ToLipgloss(),43 Prompt: o.PromptStyle.ToLipgloss(),44 }

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 45why, one step back
45

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

lines 46–49why, one step back
46 a.BlurredStyle = style
47 a.FocusedStyle = style48 a.Cursor.Style = o.CursorStyle.ToLipgloss()49 a.Cursor.SetMode(cursor.Modes[o.CursorMode])

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 50why, one step back
50

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

lines 51–52why, one step back
51 a.SetWidth(max(0, o.Width-left-right))
52 a.SetHeight(max(0, o.Height-top-bottom))

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

lines 53–54why, one step back
53 a.SetValue(o.Value)
54

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

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

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

lines 56–62why, one step back
56 textarea: a,
57 header: o.Header,58 headerStyle: o.HeaderStyle.ToLipgloss(),59 autoWidth: o.Width < 1,60 help: help.New(),61 showHelp: o.ShowHelp,62 keymap: defaultKeymap(),

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

line 63why, one step back
63 padding: []int{top, right, bottom, left},

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

lines 64–65why, one step back
64 }
65

fix(write): ctrl+j not making new line (#819)Carlos Alexandro Beckerbefore adoptionc11af42

lines 66–67why, one step back
66 m.textarea.KeyMap.InsertNewline = m.keymap.InsertNewline
67

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

lines 68–76why, one step back
68 ctx, cancel := timeout.Context(o.Timeout)
69 defer cancel()7071 p := tea.NewProgram(72 m,73 tea.WithOutput(os.Stderr),74 tea.WithReportFocus(),75 tea.WithContext(ctx),76 )

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

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

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

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

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

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

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

line 80why, one step back
80 }

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

line 81why, one step back
81 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 82–84why, one step back
82 if !m.submitted {
83 return errors.New("not submitted")84 }

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

line 85why, one step back
85 fmt.Println(m.textarea.Value())

refactor(input): simplify echoModeCarlos Alexandro Beckerbefore adoption19a93b0

lines 86–87why, one step back
86 return nil
87}