feat(tui): add bubbletea terminal UI with entity list, detail, and capture
Adds `nib tui` command and `make tui` target. Scrollable entity list with j/k navigation, enter for detail view, `a` to capture new entries using the existing parse grammar, and `d` to delete.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"github.com/lerko/nib/internal/db"
|
||||
)
|
||||
|
||||
type entitiesLoadedMsg struct {
|
||||
entities []*db.Entity
|
||||
}
|
||||
|
||||
type entityCreatedMsg struct {
|
||||
entity *db.Entity
|
||||
}
|
||||
|
||||
type entityDeletedMsg struct {
|
||||
id string
|
||||
}
|
||||
|
||||
type errMsg struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func loadEntities(store *db.Store, params db.ListParams) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
entities, err := store.List(params)
|
||||
if err != nil {
|
||||
return errMsg{err}
|
||||
}
|
||||
return entitiesLoadedMsg{entities}
|
||||
}
|
||||
}
|
||||
|
||||
func createEntity(store *db.Store, e *db.Entity) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if err := store.Create(e); err != nil {
|
||||
return errMsg{err}
|
||||
}
|
||||
return entityCreatedMsg{e}
|
||||
}
|
||||
}
|
||||
|
||||
func deleteEntity(store *db.Store, id string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if _, err := store.SoftDelete(id); err != nil {
|
||||
return errMsg{err}
|
||||
}
|
||||
return entityDeletedMsg{id}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user