Skip to content
Myr

docs: fix lint issues in examples and tutorials (#759)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Carlos Alexandro Becker · committed by GitHub · parent b2d2ac6 · Browse files · 18 files+47 added−66 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

Diff stats

18 files+47 added−66 removed

  • other:+47 added−66 removed

18 files+47 added−66 removed

modified:examples/cellbuffer/main.go+13 added-17 removed
16 unmodified lines
17const (18 fps = 6019 frequency = 7.520 damping = 0.1521 asterisk = "*"22)2324func drawEllipse(cb *cellbuffer, xc, yc, rx, ry float64) {24 const c = "*"25 var (26 dx, dy, d1, d2 float6427 x float64 = 028 y = ry27 x float6428 y = ry29 )3031 d1 = ry*ry - rx*rx*ry + 0.25*rx*rx32 dx = 2 * ry * ry * x33 dy = 2 * rx * rx * y3435 for dx < dy {36 cb.set(c, int(x+xc), int(y+yc))37 cb.set(c, int(-x+xc), int(y+yc))38 cb.set(c, int(x+xc), int(-y+yc))39 cb.set(c, int(-x+xc), int(-y+yc))36 cb.set(int(x+xc), int(y+yc))37 cb.set(int(-x+xc), int(y+yc))38 cb.set(int(x+xc), int(-y+yc))39 cb.set(int(-x+xc), int(-y+yc))40 if d1 < 0 {41 x++42 dx = dx + (2 * ry * ry)43 d1 = d1 + dx + (ry * ry)
8 unmodified lines
5253 d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) + ((rx * rx) * ((y - 1) * (y - 1))) - (rx * rx * ry * ry)5455 for y >= 0 {56 cb.set(c, int(x+xc), int(y+yc))57 cb.set(c, int(-x+xc), int(y+yc))58 cb.set(c, int(x+xc), int(-y+yc))59 cb.set(c, int(-x+xc), int(-y+yc))56 cb.set(int(x+xc), int(y+yc))57 cb.set(int(-x+xc), int(y+yc))58 cb.set(int(x+xc), int(-y+yc))59 cb.set(int(-x+xc), int(-y+yc))60 if d2 > 0 {61 y--62 dy = dy - (2 * rx * rx)63 d2 = d2 + (rx * rx) - dy
20 unmodified lines
84 c.cells = make([]string, w*h)85 c.wipe()86}8788func (c cellbuffer) set(v string, x, y int) {88func (c cellbuffer) set(x, y int) {89 i := y*c.stride + x90 if i > len(c.cells)-1 || x < 0 || y < 0 || x >= c.width() || y >= c.height() {91 return92 }93 c.cells[i] = v93 c.cells[i] = asterisk94}9596func (c *cellbuffer) clear(x, y int) {97 c.set(" ", x, y)98}9996func (c *cellbuffer) wipe() {97 for i := range c.cells {98 c.cells[i] = " "99 }
96 unmodified lines
modified:examples/composable-views/main.go+1 added-1 removed
96 unmodified lines
97 cmds = append(cmds, m.timer.Init())98 } else {99 m.Next()100 m.resetSpinner()101 cmds = append(cmds, spinner.Tick)101 cmds = append(cmds, m.spinner.Tick)102 }103 }104 switch m.state {105 // update whichever model is focused
57 unmodified lines
modified:examples/help/main.go+3 added-3 removed
130 unmodified lines
131}132133func main() {134 if os.Getenv("HELP_DEBUG") != "" {135 if f, err := tea.LogToFile("debug.log", "help"); err != nil {135 f, err := tea.LogToFile("debug.log", "help")136 if err != nil {137 fmt.Println("Couldn't open a file for logging:", err)138 os.Exit(1)138 } else {139 defer f.Close()139 }140 defer f.Close() // nolint:errcheck141 }142143 if _, err := tea.NewProgram(newModel()).Run(); err != nil {144 fmt.Printf("Could not start program :(\n%v\n", err)
3 unmodified lines
modified:examples/http/main.go+1 added-1 removed
74 unmodified lines
75 res, err := c.Get(url)76 if err != nil {77 return errMsg{err}78 }79 defer res.Body.Close()79 defer res.Body.Close() // nolint:errcheck8081 return statusMsg(res.StatusCode)82}
modified:examples/list-simple/main.go+3 added-3 removed
26 unmodified lines
27func (i item) FilterValue() string { return "" }2829type itemDelegate struct{}3031func (d itemDelegate) Height() int { return 1 }32func (d itemDelegate) Spacing() int { return 0 }33func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }31func (d itemDelegate) Height() int { return 1 }32func (d itemDelegate) Spacing() int { return 0 }33func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil }34func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {35 i, ok := listItem.(item)36 if !ok {37 return
91 unmodified lines
modified:examples/package-manager/main.go+1 added-3 removed
113 unmodified lines
114115func downloadAndInstall(pkg string) tea.Cmd {116 // This is where you'd do i/o stuff to download and install packages. In117 // our case we're just pausing for a moment to simulate the process.118 d := time.Millisecond * time.Duration(rand.Intn(500))118 d := time.Millisecond * time.Duration(rand.Intn(500)) //nolint:gosec119 return tea.Tick(d, func(t time.Time) tea.Msg {120 return installedPkgMsg(pkg)121 })122}
5 unmodified lines
128 return b129}130131func main() {132 rand.Seed(time.Now().Unix())133132 if _, err := tea.NewProgram(newModel()).Run(); err != nil {133 fmt.Println("Error running program:", err)134 os.Exit(1)135 }
1 unmodified line
modified:examples/package-manager/packages.go+1 added-1 removed
44 unmodified lines
45 pkgs[i], pkgs[j] = pkgs[j], pkgs[i]46 })4748 for k := range pkgs {49 pkgs[k] += fmt.Sprintf("-%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10))49 pkgs[k] += fmt.Sprintf("-%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10)) //nolint:gosec50 }51 return pkgs52}
modified:examples/pipe/main.go+1 added-1 removed
56 unmodified lines
5758func newModel(initialValue string) (m model) {59 i := textinput.New()60 i.Prompt = ""61 i.CursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))61 i.Cursor.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))62 i.Width = 4863 i.SetValue(initialValue)64 i.CursorEnd()65 i.Focus()
28 unmodified lines
modified:examples/prevent-quit/main.go+1 added-1 removed
59 unmodified lines
60 ti.Focus()6162 return model{63 textarea: ti,64 help: help.NewModel(),64 help: help.New(),65 keymap: keymap{66 save: key.NewBinding(67 key.WithKeys("ctrl+s"),68 key.WithHelp("ctrl+s", "save"),
86 unmodified lines
modified:examples/progress-download/main.go+3 added-3 removed
38 unmodified lines
39 return len(p), nil40}4142func getResponse(url string) (*http.Response, error) {43 resp, err := http.Get(url)43 resp, err := http.Get(url) // nolint:gosec44 if err != nil {45 log.Fatal(err)46 }47 if resp.StatusCode != http.StatusOK {
15 unmodified lines
63 if err != nil {64 fmt.Println("could not get response", err)65 os.Exit(1)66 }67 defer resp.Body.Close()67 defer resp.Body.Close() // nolint:errcheck6869 // Don't add TUI if the header doesn't include content size70 // it's impossible see progress without total71 if resp.ContentLength <= 0 {
6 unmodified lines
78 if err != nil {79 fmt.Println("could not create file:", err)80 os.Exit(1)81 }82 defer file.Close()82 defer file.Close() // nolint:errcheck8384 pw := &progressWriter{85 total: int(resp.ContentLength),86 file: file,
21 unmodified lines
modified:examples/realtime/main.go+2 added-4 removed
22 unmodified lines
23// asynchronously.24func listenForActivity(sub chan struct{}) tea.Cmd {25 return func() tea.Msg {26 for {27 time.Sleep(time.Millisecond * time.Duration(rand.Int63n(900)+100))27 time.Sleep(time.Millisecond * time.Duration(rand.Int63n(900)+100)) // nolint:gosec28 sub <- struct{}{}29 }30 }31}
13 unmodified lines
45}4647func (m model) Init() tea.Cmd {48 return tea.Batch(49 spinner.Tick,49 m.spinner.Tick,50 listenForActivity(m.sub), // generate activity51 waitForActivity(m.sub), // wait for activity52 )53}
23 unmodified lines
77 return s78}7980func main() {81 rand.Seed(time.Now().UTC().UnixNano())8281 p := tea.NewProgram(model{82 sub: make(chan struct{}),83 spinner: spinner.New(),84 })
6 unmodified lines
modified:examples/send-msg/main.go+3 added-5 removed
51 unmodified lines
52 }53}5455func (m model) Init() tea.Cmd {56 return spinner.Tick56 return m.spinner.Tick57}5859func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {60 switch msg := msg.(type) {
38 unmodified lines
99 return appStyle.Render(s)100}101102func main() {103 rand.Seed(time.Now().UTC().UnixNano())104103 p := tea.NewProgram(newModel())104105 // Simulate activity106 go func() {107 for {110 pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond108 pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond // nolint:gosec109 time.Sleep(pause)110111 // Send the Bubble Tea program a message from outside the112 // tea.Program. This will block until it is ready to receive
13 unmodified lines
126 "an apple", "a pear", "a gherkin", "a party gherkin",127 "a kohlrabi", "some spaghetti", "tacos", "a currywurst", "some curry",128 "a sandwich", "some peanut butter", "some cashews", "some ramen",129 }132 return string(food[rand.Intn(len(food))])130 return food[rand.Intn(len(food))] // nolint:gosec131}
modified:examples/stopwatch/main.go+1 added-1 removed
89 unmodified lines
90 key.WithKeys("ctrl+c", "q"),91 key.WithHelp("q", "quit"),92 ),93 },94 help: help.NewModel(),94 help: help.New(),95 }9697 m.keymap.start.SetEnabled(false)98
5 unmodified lines
modified:examples/textinputs/main.go+6 added-5 removed
6 unmodified lines
7 "fmt"8 "os"9 "strings"1011 "github.com/charmbracelet/bubbles/cursor"12 "github.com/charmbracelet/bubbles/textinput"13 tea "github.com/charmbracelet/bubbletea"14 "github.com/charmbracelet/lipgloss"15)
12 unmodified lines
2829type model struct {30 focusIndex int31 inputs []textinput.Model31 cursorMode textinput.CursorMode32 cursorMode cursor.Mode33}3435func initialModel() model {36 m := model{
2 unmodified lines
3940 var t textinput.Model41 for i := range m.inputs {42 t = textinput.New()42 t.CursorStyle = cursorStyle43 t.Cursor.Style = cursorStyle44 t.CharLimit = 324546 switch i {47 case 0:
29 unmodified lines
7778 // Change cursor mode79 case "ctrl+r":80 m.cursorMode++80 if m.cursorMode > textinput.CursorHide {81 m.cursorMode = textinput.CursorBlink81 if m.cursorMode > cursor.CursorHide {82 m.cursorMode = cursor.CursorBlink83 }84 cmds := make([]tea.Cmd, len(m.inputs))85 for i := range m.inputs {85 cmds[i] = m.inputs[i].SetCursorMode(m.cursorMode)86 cmds[i] = m.inputs[i].Cursor.SetMode(m.cursorMode)87 }88 return m, tea.Batch(cmds...)8990 // Set focus to next input
88 unmodified lines
modified:examples/timer/main.go+1 added-1 removed
109 unmodified lines
110 key.WithKeys("q", "ctrl+c"),111 key.WithHelp("q", "quit"),112 ),113 },114 help: help.NewModel(),114 help: help.New(),115 }116 m.keymap.start.SetEnabled(false)117118 if _, err := tea.NewProgram(m).Run(); err != nil {
4 unmodified lines
modified:examples/tui-daemon-combo/main.go+3 added-5 removed
17 unmodified lines
1819var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render2021func main() {22 rand.Seed(time.Now().UTC().UnixNano())2322 var (23 daemonMode bool24 showHelp bool25 opts []tea.ProgramOption
48 unmodified lines
7475func (m model) Init() tea.Cmd {76 log.Println("Starting work...")77 return tea.Batch(80 spinner.Tick,78 m.spinner.Tick,79 runPretendProcess,80 )81}82
42 unmodified lines
125type processFinishedMsg time.Duration126127// pretendProcess simulates a long-running process.128func runPretendProcess() tea.Msg {131 pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond129 pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond // nolint:gosec130 time.Sleep(pause)131 return processFinishedMsg(pause)132}133134func randomEmoji() string {135 emojis := []rune("🍦🧋🍡🤠👾😭🦊🐯🦆🥨🎏🍔🍒🍥🎮📦🦁🐶🐸🍕🥐🧲🚒🥇🏆🌽")138 return string(emojis[rand.Intn(len(emojis))])136 return string(emojis[rand.Intn(len(emojis))]) // nolint:gosec137}
modified:examples/views/main.go+2 added-10 removed
214 unmodified lines
215 if m.Loaded {216 label = fmt.Sprintf("Downloaded. Exiting in %s seconds...", colorFg(strconv.Itoa(m.Ticks), "79"))217 }218219 return msg + "\n\n" + label + "\n" + progressbar(80, m.Progress) + "%"219 return msg + "\n\n" + label + "\n" + progressbar(m.Progress) + "%"220}221222func checkbox(label string, checked bool) string {223 if checked {
1 unmodified line
225 }226 return fmt.Sprintf("[ ] %s", label)227}228229func progressbar(width int, percent float64) string {229func progressbar(percent float64) string {230 w := float64(progressBarWidth)231232 fullSize := int(math.Round(w * percent))233 var fullCells string
18 unmodified lines
252func makeFgStyle(color string) func(string) string {253 return termenv.Style{}.Foreground(term.Color(color)).Styled254}255256// Color a string's foreground and background with the given value.257func makeFgBgStyle(fg, bg string) func(string) string {258 return termenv.Style{}.259 Foreground(term.Color(fg)).260 Background(term.Color(bg)).261 Styled262}263256// Generate a blend of colors.257func makeRamp(colorA, colorB string, steps float64) (s []string) {258 cA, _ := colorful.Hex(colorA)259 cB, _ := colorful.Hex(colorB)
22 unmodified lines
modified:tutorials/commands/main.go+1 added-1 removed
20 unmodified lines
21 res, err := c.Get(url)22 if err != nil {23 return errMsg{err}24 }25 defer res.Body.Close()25 defer res.Body.Close() // nolint:errcheck2627 return statusMsg(res.StatusCode)28}29
49 unmodified lines