1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00
neonmodem/ui/windows/msgerror/handlers.go
2023-01-05 15:26:08 -05:00

55 lines
1.3 KiB
Go

package msgerror
import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/mrusme/gobbs/ui/cmd"
)
func handleViewResize(mi interface{}) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
m.ctx.Logger.Debugf("received WindowSizeMsg: %vx%v\n", m.tk.ViewWidth(), m.tk.ViewHeight())
viewportWidth := m.tk.ViewWidth() - 2
viewportHeight := m.tk.ViewHeight() - 5
viewportStyle.Width(viewportWidth)
viewportStyle.Height(viewportHeight)
m.viewport = viewport.New(viewportWidth-4, viewportHeight-4)
m.viewport.Width = viewportWidth - 4
m.viewport.Height = viewportHeight + 1
return false, cmds
}
func handleMsgErrorCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
if err := c.GetArg("error"); err != nil {
m.ctx.Logger.Debugf("Setting error: %v", err)
m.errs = append(m.errs, err.(error))
}
if errs := c.GetArg("errors"); errs != nil {
m.ctx.Logger.Debugf("Setting error: %v", errs)
m.errs = append(m.errs, errs.([]error)...)
}
m.setErrorContent()
m.tk.CacheView(m)
return true, cmds
}
func handleWinCloseCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
if c.Target == WIN_ID {
m.errs = []error{}
return true, cmds
}
return false, cmds
}