75 lines
1.2 KiB
Go
75 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type model struct {
|
|
cursor int
|
|
actions []string
|
|
}
|
|
|
|
func initialModel() model {
|
|
return model{
|
|
actions: []string{"Write", "Read", "Edit", "Delete"},
|
|
}
|
|
}
|
|
|
|
func (m model) Init() tea.Cmd {
|
|
return tea.SetWindowTitle("Gemlog CLI")
|
|
}
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
switch msg.String() {
|
|
case "ctrl+c", "q":
|
|
return m, tea.Quit
|
|
case "up", "k":
|
|
if m.cursor > 0 {
|
|
m.cursor--
|
|
}
|
|
case "down", "j":
|
|
if m.cursor < len(m.actions)-1 {
|
|
m.cursor++
|
|
}
|
|
// case "enter", " ":
|
|
// _, ok := m.selected[m.cursor]
|
|
// if ok {
|
|
// delete(m.selected, m.cursor)
|
|
// } else {
|
|
// m.selected[m.cursor] = struct{}{}
|
|
// }
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
func (m model) View() string {
|
|
s := "Welcome to gemlog cli!\n\nWhat would you like to do?\n\n"
|
|
|
|
for i, action := range m.actions {
|
|
cursor := " "
|
|
if m.cursor == i {
|
|
cursor = ">"
|
|
}
|
|
|
|
s += fmt.Sprintf("%s %s\n", cursor, action)
|
|
}
|
|
|
|
s += "\nPress q to quit.\n"
|
|
|
|
return s
|
|
}
|
|
|
|
func main() {
|
|
p := tea.NewProgram(initialModel())
|
|
if _, err := p.Run(); err != nil {
|
|
fmt.Printf("Alas, there's been an error: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|