package ui import ( "fmt" tea "github.com/charmbracelet/bubbletea" ) type Action string const ( Write Action = "write" Read Action = "read" Edit Action = "edit" Delete Action = "delete" ) var actions = []Action{Write, Read, Edit, Delete} type ActionListPageModel struct { cursor int } func initialActionListPageModel() ActionListPageModel { return ActionListPageModel{ cursor: 0, } } func (m ActionListPageModel) InitActionListPage() tea.Cmd { return nil } func (m ActionListPageModel) Update(msg tea.Msg, active bool, ctx *context) (ActionListPageModel, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: if !active { return m, nil } switch msg.String() { case "up", "k": if m.cursor > 0 { m.cursor-- } case "down", "j": if m.cursor < len(actions)-1 { m.cursor++ } case "enter", " ", "l": action := actions[m.cursor] switch action { case Write: return m, WritePostCMD(ctx.config) case Read, Delete, Edit: switchPageCmd := func() tea.Msg { return SwitchPages{Page: EntryList} } actionToTakeCmd := func() tea.Msg { return SelectActionToTake{ActionToTake: action} } loadGemLogsCmd := LoadGemlogsCMD(ctx.config) return m, tea.Batch(switchPageCmd, loadGemLogsCmd, actionToTakeCmd) } } } return m, nil } func (m ActionListPageModel) View() string { s := "Welcome to gemlog cli!\n\nWhat post action would you like to take?\n\n" for i, action := range actions { cursor := " " if m.cursor == i { cursor = ">" } s += fmt.Sprintf("%s %s\n", cursor, action) } return s }