2023-01-03 16:58:49 -05:00
|
|
|
package msgerror
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/charmbracelet/bubbles/viewport"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
2023-01-06 19:46:41 -05:00
|
|
|
"github.com/mrusme/neonmodem/ui/cmd"
|
2023-01-03 16:58:49 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func handleViewResize(mi interface{}) (bool, []tea.Cmd) {
|
|
|
|
var m *Model = mi.(*Model)
|
|
|
|
var cmds []tea.Cmd
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-01-05 12:21:26 -05:00
|
|
|
if err := c.GetArg("error"); err != nil {
|
|
|
|
m.errs = append(m.errs, err.(error))
|
2023-01-03 16:58:49 -05:00
|
|
|
}
|
2023-01-05 12:21:26 -05:00
|
|
|
if errs := c.GetArg("errors"); errs != nil {
|
|
|
|
m.errs = append(m.errs, errs.([]error)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.setErrorContent()
|
|
|
|
m.tk.CacheView(m)
|
2023-01-03 16:58:49 -05:00
|
|
|
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 {
|
2023-01-05 12:21:26 -05:00
|
|
|
m.errs = []error{}
|
2023-01-03 16:58:49 -05:00
|
|
|
return true, cmds
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, cmds
|
|
|
|
}
|