mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-12-04 14:46:37 -05:00
49 lines
1.1 KiB
Go
49 lines
1.1 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
|
|
|
|
m.err = c.GetArg("error").(error)
|
|
if m.err != nil {
|
|
m.viewport.SetContent(m.err.Error())
|
|
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.err = nil
|
|
return true, cmds
|
|
}
|
|
|
|
return false, cmds
|
|
}
|