forked from Mirrors/bubbletea
docs: fix lint issues in examples and tutorials (#759)
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
b2d2ac6504
commit
b80eb8303b
|
@ -18,14 +18,14 @@ const (
|
|||
fps = 60
|
||||
frequency = 7.5
|
||||
damping = 0.15
|
||||
asterisk = "*"
|
||||
)
|
||||
|
||||
func drawEllipse(cb *cellbuffer, xc, yc, rx, ry float64) {
|
||||
const c = "*"
|
||||
var (
|
||||
dx, dy, d1, d2 float64
|
||||
x float64 = 0
|
||||
y = ry
|
||||
x float64
|
||||
y = ry
|
||||
)
|
||||
|
||||
d1 = ry*ry - rx*rx*ry + 0.25*rx*rx
|
||||
|
@ -33,10 +33,10 @@ func drawEllipse(cb *cellbuffer, xc, yc, rx, ry float64) {
|
|||
dy = 2 * rx * rx * y
|
||||
|
||||
for dx < dy {
|
||||
cb.set(c, int(x+xc), int(y+yc))
|
||||
cb.set(c, int(-x+xc), int(y+yc))
|
||||
cb.set(c, int(x+xc), int(-y+yc))
|
||||
cb.set(c, int(-x+xc), int(-y+yc))
|
||||
cb.set(int(x+xc), int(y+yc))
|
||||
cb.set(int(-x+xc), int(y+yc))
|
||||
cb.set(int(x+xc), int(-y+yc))
|
||||
cb.set(int(-x+xc), int(-y+yc))
|
||||
if d1 < 0 {
|
||||
x++
|
||||
dx = dx + (2 * ry * ry)
|
||||
|
@ -53,10 +53,10 @@ func drawEllipse(cb *cellbuffer, xc, yc, rx, ry float64) {
|
|||
d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) + ((rx * rx) * ((y - 1) * (y - 1))) - (rx * rx * ry * ry)
|
||||
|
||||
for y >= 0 {
|
||||
cb.set(c, int(x+xc), int(y+yc))
|
||||
cb.set(c, int(-x+xc), int(y+yc))
|
||||
cb.set(c, int(x+xc), int(-y+yc))
|
||||
cb.set(c, int(-x+xc), int(-y+yc))
|
||||
cb.set(int(x+xc), int(y+yc))
|
||||
cb.set(int(-x+xc), int(y+yc))
|
||||
cb.set(int(x+xc), int(-y+yc))
|
||||
cb.set(int(-x+xc), int(-y+yc))
|
||||
if d2 > 0 {
|
||||
y--
|
||||
dy = dy - (2 * rx * rx)
|
||||
|
@ -85,16 +85,12 @@ func (c *cellbuffer) init(w, h int) {
|
|||
c.wipe()
|
||||
}
|
||||
|
||||
func (c cellbuffer) set(v string, x, y int) {
|
||||
func (c cellbuffer) set(x, y int) {
|
||||
i := y*c.stride + x
|
||||
if i > len(c.cells)-1 || x < 0 || y < 0 || x >= c.width() || y >= c.height() {
|
||||
return
|
||||
}
|
||||
c.cells[i] = v
|
||||
}
|
||||
|
||||
func (c *cellbuffer) clear(x, y int) {
|
||||
c.set(" ", x, y)
|
||||
c.cells[i] = asterisk
|
||||
}
|
||||
|
||||
func (c *cellbuffer) wipe() {
|
||||
|
|
|
@ -98,7 +98,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
} else {
|
||||
m.Next()
|
||||
m.resetSpinner()
|
||||
cmds = append(cmds, spinner.Tick)
|
||||
cmds = append(cmds, m.spinner.Tick)
|
||||
}
|
||||
}
|
||||
switch m.state {
|
||||
|
|
|
@ -132,12 +132,12 @@ func (m model) View() string {
|
|||
|
||||
func main() {
|
||||
if os.Getenv("HELP_DEBUG") != "" {
|
||||
if f, err := tea.LogToFile("debug.log", "help"); err != nil {
|
||||
f, err := tea.LogToFile("debug.log", "help")
|
||||
if err != nil {
|
||||
fmt.Println("Couldn't open a file for logging:", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
defer f.Close()
|
||||
}
|
||||
defer f.Close() // nolint:errcheck
|
||||
}
|
||||
|
||||
if _, err := tea.NewProgram(newModel()).Run(); err != nil {
|
||||
|
|
|
@ -76,7 +76,7 @@ func checkServer() tea.Msg {
|
|||
if err != nil {
|
||||
return errMsg{err}
|
||||
}
|
||||
defer res.Body.Close()
|
||||
defer res.Body.Close() // nolint:errcheck
|
||||
|
||||
return statusMsg(res.StatusCode)
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ func (i item) FilterValue() string { return "" }
|
|||
|
||||
type itemDelegate struct{}
|
||||
|
||||
func (d itemDelegate) Height() int { return 1 }
|
||||
func (d itemDelegate) Spacing() int { return 0 }
|
||||
func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
|
||||
func (d itemDelegate) Height() int { return 1 }
|
||||
func (d itemDelegate) Spacing() int { return 0 }
|
||||
func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil }
|
||||
func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
|
||||
i, ok := listItem.(item)
|
||||
if !ok {
|
||||
|
|
|
@ -115,7 +115,7 @@ type installedPkgMsg string
|
|||
func downloadAndInstall(pkg string) tea.Cmd {
|
||||
// This is where you'd do i/o stuff to download and install packages. In
|
||||
// our case we're just pausing for a moment to simulate the process.
|
||||
d := time.Millisecond * time.Duration(rand.Intn(500))
|
||||
d := time.Millisecond * time.Duration(rand.Intn(500)) //nolint:gosec
|
||||
return tea.Tick(d, func(t time.Time) tea.Msg {
|
||||
return installedPkgMsg(pkg)
|
||||
})
|
||||
|
@ -129,8 +129,6 @@ func max(a, b int) int {
|
|||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
if _, err := tea.NewProgram(newModel()).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -46,7 +46,7 @@ func getPackages() []string {
|
|||
})
|
||||
|
||||
for k := range pkgs {
|
||||
pkgs[k] += fmt.Sprintf("-%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10))
|
||||
pkgs[k] += fmt.Sprintf("-%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10)) //nolint:gosec
|
||||
}
|
||||
return pkgs
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ type model struct {
|
|||
func newModel(initialValue string) (m model) {
|
||||
i := textinput.New()
|
||||
i.Prompt = ""
|
||||
i.CursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
|
||||
i.Cursor.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
|
||||
i.Width = 48
|
||||
i.SetValue(initialValue)
|
||||
i.CursorEnd()
|
||||
|
|
|
@ -61,7 +61,7 @@ func initialModel() model {
|
|||
|
||||
return model{
|
||||
textarea: ti,
|
||||
help: help.NewModel(),
|
||||
help: help.New(),
|
||||
keymap: keymap{
|
||||
save: key.NewBinding(
|
||||
key.WithKeys("ctrl+s"),
|
||||
|
|
|
@ -40,7 +40,7 @@ func (pw *progressWriter) Write(p []byte) (int, error) {
|
|||
}
|
||||
|
||||
func getResponse(url string) (*http.Response, error) {
|
||||
resp, err := http.Get(url)
|
||||
resp, err := http.Get(url) // nolint:gosec
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func main() {
|
|||
fmt.Println("could not get response", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer resp.Body.Close() // nolint:errcheck
|
||||
|
||||
// Don't add TUI if the header doesn't include content size
|
||||
// it's impossible see progress without total
|
||||
|
@ -79,7 +79,7 @@ func main() {
|
|||
fmt.Println("could not create file:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer file.Close()
|
||||
defer file.Close() // nolint:errcheck
|
||||
|
||||
pw := &progressWriter{
|
||||
total: int(resp.ContentLength),
|
||||
|
|
|
@ -24,7 +24,7 @@ type responseMsg struct{}
|
|||
func listenForActivity(sub chan struct{}) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
for {
|
||||
time.Sleep(time.Millisecond * time.Duration(rand.Int63n(900)+100))
|
||||
time.Sleep(time.Millisecond * time.Duration(rand.Int63n(900)+100)) // nolint:gosec
|
||||
sub <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ type model struct {
|
|||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return tea.Batch(
|
||||
spinner.Tick,
|
||||
m.spinner.Tick,
|
||||
listenForActivity(m.sub), // generate activity
|
||||
waitForActivity(m.sub), // wait for activity
|
||||
)
|
||||
|
@ -78,8 +78,6 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
p := tea.NewProgram(model{
|
||||
sub: make(chan struct{}),
|
||||
spinner: spinner.New(),
|
||||
|
|
|
@ -53,7 +53,7 @@ func newModel() model {
|
|||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return spinner.Tick
|
||||
return m.spinner.Tick
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
@ -100,14 +100,12 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
p := tea.NewProgram(newModel())
|
||||
|
||||
// Simulate activity
|
||||
go func() {
|
||||
for {
|
||||
pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond
|
||||
pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond // nolint:gosec
|
||||
time.Sleep(pause)
|
||||
|
||||
// Send the Bubble Tea program a message from outside the
|
||||
|
@ -129,5 +127,5 @@ func randomFood() string {
|
|||
"a kohlrabi", "some spaghetti", "tacos", "a currywurst", "some curry",
|
||||
"a sandwich", "some peanut butter", "some cashews", "some ramen",
|
||||
}
|
||||
return string(food[rand.Intn(len(food))])
|
||||
return food[rand.Intn(len(food))] // nolint:gosec
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ func main() {
|
|||
key.WithHelp("q", "quit"),
|
||||
),
|
||||
},
|
||||
help: help.NewModel(),
|
||||
help: help.New(),
|
||||
}
|
||||
|
||||
m.keymap.start.SetEnabled(false)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/bubbles/cursor"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
@ -28,7 +29,7 @@ var (
|
|||
type model struct {
|
||||
focusIndex int
|
||||
inputs []textinput.Model
|
||||
cursorMode textinput.CursorMode
|
||||
cursorMode cursor.Mode
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
|
@ -39,7 +40,7 @@ func initialModel() model {
|
|||
var t textinput.Model
|
||||
for i := range m.inputs {
|
||||
t = textinput.New()
|
||||
t.CursorStyle = cursorStyle
|
||||
t.Cursor.Style = cursorStyle
|
||||
t.CharLimit = 32
|
||||
|
||||
switch i {
|
||||
|
@ -77,12 +78,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
// Change cursor mode
|
||||
case "ctrl+r":
|
||||
m.cursorMode++
|
||||
if m.cursorMode > textinput.CursorHide {
|
||||
m.cursorMode = textinput.CursorBlink
|
||||
if m.cursorMode > cursor.CursorHide {
|
||||
m.cursorMode = cursor.CursorBlink
|
||||
}
|
||||
cmds := make([]tea.Cmd, len(m.inputs))
|
||||
for i := range m.inputs {
|
||||
cmds[i] = m.inputs[i].SetCursorMode(m.cursorMode)
|
||||
cmds[i] = m.inputs[i].Cursor.SetMode(m.cursorMode)
|
||||
}
|
||||
return m, tea.Batch(cmds...)
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ func main() {
|
|||
key.WithHelp("q", "quit"),
|
||||
),
|
||||
},
|
||||
help: help.NewModel(),
|
||||
help: help.New(),
|
||||
}
|
||||
m.keymap.start.SetEnabled(false)
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@ import (
|
|||
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
var (
|
||||
daemonMode bool
|
||||
showHelp bool
|
||||
|
@ -77,7 +75,7 @@ func newModel() model {
|
|||
func (m model) Init() tea.Cmd {
|
||||
log.Println("Starting work...")
|
||||
return tea.Batch(
|
||||
spinner.Tick,
|
||||
m.spinner.Tick,
|
||||
runPretendProcess,
|
||||
)
|
||||
}
|
||||
|
@ -128,12 +126,12 @@ type processFinishedMsg time.Duration
|
|||
|
||||
// pretendProcess simulates a long-running process.
|
||||
func runPretendProcess() tea.Msg {
|
||||
pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond
|
||||
pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond // nolint:gosec
|
||||
time.Sleep(pause)
|
||||
return processFinishedMsg(pause)
|
||||
}
|
||||
|
||||
func randomEmoji() string {
|
||||
emojis := []rune("🍦🧋🍡🤠👾😭🦊🐯🦆🥨🎏🍔🍒🍥🎮📦🦁🐶🐸🍕🥐🧲🚒🥇🏆🌽")
|
||||
return string(emojis[rand.Intn(len(emojis))])
|
||||
return string(emojis[rand.Intn(len(emojis))]) // nolint:gosec
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ func chosenView(m model) string {
|
|||
label = fmt.Sprintf("Downloaded. Exiting in %s seconds...", colorFg(strconv.Itoa(m.Ticks), "79"))
|
||||
}
|
||||
|
||||
return msg + "\n\n" + label + "\n" + progressbar(80, m.Progress) + "%"
|
||||
return msg + "\n\n" + label + "\n" + progressbar(m.Progress) + "%"
|
||||
}
|
||||
|
||||
func checkbox(label string, checked bool) string {
|
||||
|
@ -226,7 +226,7 @@ func checkbox(label string, checked bool) string {
|
|||
return fmt.Sprintf("[ ] %s", label)
|
||||
}
|
||||
|
||||
func progressbar(width int, percent float64) string {
|
||||
func progressbar(percent float64) string {
|
||||
w := float64(progressBarWidth)
|
||||
|
||||
fullSize := int(math.Round(w * percent))
|
||||
|
@ -253,14 +253,6 @@ func makeFgStyle(color string) func(string) string {
|
|||
return termenv.Style{}.Foreground(term.Color(color)).Styled
|
||||
}
|
||||
|
||||
// Color a string's foreground and background with the given value.
|
||||
func makeFgBgStyle(fg, bg string) func(string) string {
|
||||
return termenv.Style{}.
|
||||
Foreground(term.Color(fg)).
|
||||
Background(term.Color(bg)).
|
||||
Styled
|
||||
}
|
||||
|
||||
// Generate a blend of colors.
|
||||
func makeRamp(colorA, colorB string, steps float64) (s []string) {
|
||||
cA, _ := colorful.Hex(colorA)
|
||||
|
|
|
@ -22,7 +22,7 @@ func checkServer() tea.Msg {
|
|||
if err != nil {
|
||||
return errMsg{err}
|
||||
}
|
||||
defer res.Body.Close()
|
||||
defer res.Body.Close() // nolint:errcheck
|
||||
|
||||
return statusMsg(res.StatusCode)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue