chore: clean up linter errors in examples

This commit is contained in:
Christian Muehlhaeuser 2022-10-08 00:34:41 +02:00
parent 8b8fd12201
commit 22d15efad7
16 changed files with 26 additions and 40 deletions

View File

@ -23,7 +23,6 @@ func main() {
} }
type ( type (
tickMsg struct{}
errMsg error errMsg error
) )

View File

@ -20,7 +20,6 @@ func main() {
} }
type ( type (
tickMsg struct{}
errMsg error errMsg error
) )
@ -139,9 +138,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyEnter: case tea.KeyEnter:
if m.focused == len(m.inputs)-1 { if m.focused == len(m.inputs)-1 {
return m, tea.Quit return m, tea.Quit
} else {
m.nextInput()
} }
m.nextInput()
case tea.KeyCtrlC, tea.KeyEsc: case tea.KeyCtrlC, tea.KeyEsc:
return m, tea.Quit return m, tea.Quit
case tea.KeyShiftTab, tea.KeyCtrlP: case tea.KeyShiftTab, tea.KeyCtrlP:

View File

@ -28,7 +28,6 @@ func (m model) Init() tea.Cmd {
func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
switch msg := message.(type) { switch msg := message.(type) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.String() { switch msg.String() {
case "q", "esc", "ctrl+c": case "q", "esc", "ctrl+c":
@ -36,12 +35,11 @@ func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
} }
case tickMsg: case tickMsg:
m -= 1 m--
if m <= 0 { if m <= 0 {
return m, tea.Quit return m, tea.Quit
} }
return m, tick() return m, tick()
} }
return m, nil return m, nil

View File

@ -37,7 +37,6 @@ func (m model) Init() tea.Cmd {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.String() { switch msg.String() {
case "q", "ctrl+c", "esc": case "q", "ctrl+c", "esc":
@ -77,5 +76,7 @@ func checkServer() tea.Msg {
if err != nil { if err != nil {
return errMsg{err} return errMsg{err}
} }
defer res.Body.Close()
return statusMsg(res.StatusCode) return statusMsg(res.StatusCode)
} }

View File

@ -45,12 +45,11 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
} }
} }
fmt.Fprintf(w, fn(str)) fmt.Fprint(w, fn(str))
} }
type model struct { type model struct {
list list.Model list list.Model
items []item
choice string choice string
quitting bool quitting bool
} }

View File

@ -25,7 +25,6 @@ type model struct {
var ( var (
currentPkgNameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("211")) currentPkgNameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("211"))
subtleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("239"))
doneStyle = lipgloss.NewStyle().Margin(1, 2) doneStyle = lipgloss.NewStyle().Margin(1, 2)
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓") checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓")
) )

View File

@ -42,7 +42,7 @@ type model struct {
progress progress.Model progress progress.Model
} }
func (_ model) Init() tea.Cmd { func (m model) Init() tea.Cmd {
return tickCmd() return tickCmd()
} }
@ -79,10 +79,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
} }
func (e model) View() string { func (m model) View() string {
pad := strings.Repeat(" ", padding) pad := strings.Repeat(" ", padding)
return "\n" + return "\n" +
pad + e.progress.View() + "\n\n" + pad + m.progress.View() + "\n\n" +
pad + helpStyle("Press any key to quit") pad + helpStyle("Press any key to quit")
} }

View File

@ -27,7 +27,6 @@ func finalPause() tea.Cmd {
} }
type model struct { type model struct {
url, path string
pw *progressWriter pw *progressWriter
progress progress.Model progress progress.Model
err error err error

View File

@ -50,13 +50,12 @@ type model struct {
progress progress.Model progress progress.Model
} }
func (_ model) Init() tea.Cmd { func (m model) Init() tea.Cmd {
return tickCmd() return tickCmd()
} }
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
return m, tea.Quit return m, tea.Quit
@ -80,10 +79,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
} }
func (e model) View() string { func (m model) View() string {
pad := strings.Repeat(" ", padding) pad := strings.Repeat(" ", padding)
return "\n" + return "\n" +
pad + e.progress.ViewAs(e.percent) + "\n\n" + pad + m.progress.ViewAs(m.percent) + "\n\n" +
pad + helpStyle("Press any key to quit") pad + helpStyle("Press any key to quit")
} }

View File

@ -19,7 +19,6 @@ var (
spinnerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("63")) spinnerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Margin(1, 0) helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Margin(1, 0)
dotStyle = helpStyle.Copy().UnsetMargins() dotStyle = helpStyle.Copy().UnsetMargins()
foodStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("36"))
durationStyle = dotStyle.Copy() durationStyle = dotStyle.Copy()
appStyle = lipgloss.NewStyle().Margin(1, 2, 0, 2) appStyle = lipgloss.NewStyle().Margin(1, 2, 0, 2)
) )

View File

@ -47,7 +47,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg: case tea.KeyMsg:
return m, tea.Quit return m, tea.Quit
case tickMsg: case tickMsg:
m -= 1 m--
if m <= 0 { if m <= 0 {
return m, tea.Quit return m, tea.Quit
} }

View File

@ -33,7 +33,6 @@ func (m model) Init() tea.Cmd {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.String() { switch msg.String() {
case "q", "esc", "ctrl+c": case "q", "esc", "ctrl+c":

View File

@ -46,8 +46,6 @@ func tabBorderWithBottom(left, middle, right string) lipgloss.Border {
} }
var ( var (
defaultWidth = 20
inactiveTabBorder = tabBorderWithBottom("┴", "─", "┴") inactiveTabBorder = tabBorderWithBottom("┴", "─", "┴")
activeTabBorder = tabBorderWithBottom("┘", " ", "└") activeTabBorder = tabBorderWithBottom("┘", " ", "└")
docStyle = lipgloss.NewStyle().Padding(1, 2, 1, 2) docStyle = lipgloss.NewStyle().Padding(1, 2, 1, 2)

View File

@ -20,7 +20,6 @@ func main() {
} }
type ( type (
tickMsg struct{}
errMsg error errMsg error
) )

View File

@ -115,16 +115,15 @@ func (m model) View() string {
// Update loop for the first view where you're choosing a task. // Update loop for the first view where you're choosing a task.
func updateChoices(msg tea.Msg, m model) (tea.Model, tea.Cmd) { func updateChoices(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.String() { switch msg.String() {
case "j", "down": case "j", "down":
m.Choice += 1 m.Choice++
if m.Choice > 3 { if m.Choice > 3 {
m.Choice = 3 m.Choice = 3
} }
case "k", "up": case "k", "up":
m.Choice -= 1 m.Choice--
if m.Choice < 0 { if m.Choice < 0 {
m.Choice = 0 m.Choice = 0
} }
@ -138,7 +137,7 @@ func updateChoices(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
m.Quitting = true m.Quitting = true
return m, tea.Quit return m, tea.Quit
} }
m.Ticks -= 1 m.Ticks--
return m, tick() return m, tick()
} }
@ -148,10 +147,9 @@ func updateChoices(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
// Update loop for the second view after a choice has been made // Update loop for the second view after a choice has been made
func updateChosen(msg tea.Msg, m model) (tea.Model, tea.Cmd) { func updateChosen(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
switch msg.(type) { switch msg.(type) {
case frameMsg: case frameMsg:
if !m.Loaded { if !m.Loaded {
m.Frames += 1 m.Frames++
m.Progress = ease.OutBounce(float64(m.Frames) / float64(100)) m.Progress = ease.OutBounce(float64(m.Frames) / float64(100))
if m.Progress >= 1 { if m.Progress >= 1 {
m.Progress = 1 m.Progress = 1
@ -168,7 +166,7 @@ func updateChosen(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
m.Quitting = true m.Quitting = true
return m, tea.Quit return m, tea.Quit
} }
m.Ticks -= 1 m.Ticks--
return m, tick() return m, tick()
} }
} }

View File

@ -22,6 +22,8 @@ func checkServer() tea.Msg {
if err != nil { if err != nil {
return errMsg{err} return errMsg{err}
} }
defer res.Body.Close()
return statusMsg(res.StatusCode) return statusMsg(res.StatusCode)
} }
@ -39,7 +41,6 @@ func (m model) Init() tea.Cmd {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case statusMsg: case statusMsg:
m.status = int(msg) m.status = int(msg)
return m, tea.Quit return m, tea.Quit