Adding new task menu, better tab bar ui using lipgloss
This commit is contained in:
parent
4d2028cd01
commit
ac37f53069
28
bubbletea.go
28
bubbletea.go
@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
@ -12,6 +12,8 @@ func (m model) Init() tea.Cmd {
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
|
||||
switch msg := msg.(type) {
|
||||
|
||||
// Is it a key press?
|
||||
@ -26,23 +28,23 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
// The "up" and "k" keys move the cursor up
|
||||
case "up", "k":
|
||||
if m.cursor > 0 {
|
||||
if m.cursor > 0 && !m.addTask {
|
||||
m.cursor--
|
||||
}
|
||||
|
||||
// The "down" and "j" keys move the cursor down
|
||||
case "down", "j":
|
||||
if m.cursor < len(m.todos)-1 {
|
||||
if m.cursor < len(m.todos)-1 && !m.addTask {
|
||||
m.cursor++
|
||||
}
|
||||
|
||||
case "left", "h":
|
||||
if m.tab > 0 {
|
||||
if m.tab > 0 && !m.addTask {
|
||||
m.tab--
|
||||
}
|
||||
|
||||
case "right", "l":
|
||||
if m.tab < 4 {
|
||||
if m.tab < 4 && !m.addTask {
|
||||
m.tab++
|
||||
}
|
||||
|
||||
@ -65,9 +67,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
m.textinput, cmd = m.textinput.Update(msg)
|
||||
|
||||
// Return the updated model to the Bubble Tea runtime for processing.
|
||||
// Note that we're not returning a command.
|
||||
return m, nil
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
@ -111,22 +115,26 @@ func (m model) View() string {
|
||||
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice)
|
||||
}
|
||||
|
||||
// render tab bar
|
||||
for i, v := range []string{"Inbox", "Today", "Tomorrow", "Scheduled", "Anytime"} {
|
||||
if i == m.tab {
|
||||
s += fmt.Sprintf("**%s** ", v)
|
||||
s += lipgloss.NewStyle().Bold(true).Render(fmt.Sprintf("%s ", v))
|
||||
} else {
|
||||
s += fmt.Sprintf("%s ", v)
|
||||
}
|
||||
}
|
||||
|
||||
// The footer
|
||||
s += "\nn: new\n"
|
||||
s += "q: quit.\n"
|
||||
s += "\nn: new"
|
||||
|
||||
if m.addTask {
|
||||
|
||||
s += ": >"
|
||||
m.textinput.Prompt = "New Task..."
|
||||
s += m.textinput.View()
|
||||
}
|
||||
|
||||
s += "\nq: quit.\n"
|
||||
|
||||
// Send the UI for rendering
|
||||
return s
|
||||
}
|
||||
|
6
go.mod
6
go.mod
@ -2,9 +2,13 @@ module breadone/gotd
|
||||
|
||||
go 1.24.1
|
||||
|
||||
require github.com/charmbracelet/bubbletea v1.3.4
|
||||
require (
|
||||
github.com/charmbracelet/bubbles v0.20.0
|
||||
github.com/charmbracelet/bubbletea v1.3.4
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/charmbracelet/lipgloss v1.0.0 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.8.0 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -1,5 +1,9 @@
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
|
||||
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
||||
github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI=
|
||||
github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo=
|
||||
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
|
||||
|
5
model.go
5
model.go
@ -1,5 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
)
|
||||
|
||||
type todo struct {
|
||||
name string
|
||||
done bool
|
||||
@ -16,6 +20,7 @@ type model struct {
|
||||
selected map[int]struct{} // which to-do items are selected
|
||||
tab int // which tab is selected
|
||||
addTask bool // defines if the new task window is shown
|
||||
textinput textinput.Model
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
|
Loading…
x
Reference in New Issue
Block a user