get notifications working
This commit is contained in:
parent
0c617c8185
commit
1160665595
3 changed files with 46 additions and 25 deletions
38
main.go
38
main.go
|
|
@ -17,19 +17,22 @@ const (
|
|||
Delete Action = "delete"
|
||||
)
|
||||
|
||||
type ActionCallback func() error
|
||||
func TODOCmd() tea.Msg {
|
||||
return gemlog.Notification("This action has not been implemented yet.")
|
||||
}
|
||||
|
||||
var callbacks = map[Action]ActionCallback{
|
||||
Write: gemlog.WriteAction,
|
||||
Read: func() error { return fmt.Errorf("not implmented") },
|
||||
Edit: func() error { return nil },
|
||||
Delete: func() error { return nil },
|
||||
var mainCommands = map[Action]tea.Cmd{
|
||||
Write: gemlog.WritePostCMD,
|
||||
Read: TODOCmd,
|
||||
Edit: TODOCmd,
|
||||
Delete: TODOCmd,
|
||||
}
|
||||
|
||||
type model struct {
|
||||
cursor int
|
||||
actions []Action
|
||||
errorTxt string
|
||||
notification string
|
||||
cursor int
|
||||
actions []Action
|
||||
errorTxt string
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
|
|
@ -44,6 +47,8 @@ func (m model) Init() tea.Cmd {
|
|||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case gemlog.Notification:
|
||||
m.notification = fmt.Sprintf("%s\n\n", string(msg))
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c", "q":
|
||||
|
|
@ -57,13 +62,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
m.cursor++
|
||||
}
|
||||
case "enter", " ":
|
||||
err := callbacks[m.actions[m.cursor]]()
|
||||
if err == nil {
|
||||
return m, tea.Quit
|
||||
}
|
||||
m.errorTxt = "problem running action\n\nerror:\n"
|
||||
m.errorTxt += fmt.Sprintf("Error: %v\n", err)
|
||||
return m, nil
|
||||
return m, mainCommands[m.actions[m.cursor]]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +73,12 @@ func (m model) View() string {
|
|||
if len(m.errorTxt) > 0 {
|
||||
return m.errorTxt
|
||||
}
|
||||
s := "Welcome to gemlog cli!\n\nWhat post action would you like to take?\n\n"
|
||||
s := ""
|
||||
if m.notification != "" {
|
||||
s += m.notification
|
||||
} else {
|
||||
s += "Welcome to gemlog cli!\n\nWhat post action would you like to take?\n\n"
|
||||
}
|
||||
|
||||
for i, action := range m.actions {
|
||||
cursor := " "
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue