mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 11:09:17 -07:00
Simplify code a bit
This commit is contained in:
10
commands.go
10
commands.go
@@ -22,10 +22,7 @@ func Every(duration time.Duration, fn func(time.Time) Msg) Cmd {
|
||||
n := time.Now()
|
||||
d := n.Truncate(duration).Add(duration).Sub(n)
|
||||
t := time.NewTimer(d)
|
||||
select {
|
||||
case now := <-t.C:
|
||||
return fn(now)
|
||||
}
|
||||
return fn(<-t.C)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +32,7 @@ func Every(duration time.Duration, fn func(time.Time) Msg) Cmd {
|
||||
func Tick(d time.Duration, fn func(time.Time) Msg) Cmd {
|
||||
return func() Msg {
|
||||
t := time.NewTimer(d)
|
||||
select {
|
||||
case now := <-t.C:
|
||||
return fn(now)
|
||||
}
|
||||
return fn(<-t.C)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ func (m *Model) SetTotalPages(items int) int {
|
||||
}
|
||||
n := items / m.PerPage
|
||||
if items%m.PerPage > 0 {
|
||||
n += 1
|
||||
n++
|
||||
}
|
||||
m.TotalPages = n
|
||||
return n
|
||||
@@ -89,10 +89,7 @@ func (m *Model) NextPage() {
|
||||
|
||||
// LastPage returns whether or not we're on the last page.
|
||||
func (m Model) OnLastPage() bool {
|
||||
if m.Page == m.TotalPages-1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return m.Page == m.TotalPages-1
|
||||
}
|
||||
|
||||
// NewModel creates a new model with defaults.
|
||||
|
||||
@@ -182,7 +182,6 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
switch msg.Type {
|
||||
case boba.KeyBackspace:
|
||||
|
||||
@@ -82,7 +82,6 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
switch msg.String() {
|
||||
|
||||
// Down one page
|
||||
case "pgdown":
|
||||
fallthrough
|
||||
@@ -122,7 +121,6 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
case "k":
|
||||
m.LineUp(1)
|
||||
return m, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user