1
0
Fork 0

Refactored MsgError

This commit is contained in:
マリウス 2023-01-05 12:21:26 -05:00
parent a61772e3b0
commit e234ab044e
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 22 additions and 11 deletions

View File

@ -27,11 +27,15 @@ 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)
if err := c.GetArg("error"); err != nil {
m.errs = append(m.errs, err.(error))
}
if errs := c.GetArg("errors"); errs != nil {
m.errs = append(m.errs, errs.([]error)...)
}
m.setErrorContent()
m.tk.CacheView(m)
return true, cmds
}
@ -40,7 +44,7 @@ func handleWinCloseCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var cmds []tea.Cmd
if c.Target == WIN_ID {
m.err = nil
m.errs = []error{}
return true, cmds
}

View File

@ -30,7 +30,7 @@ type Model struct {
a *aggregator.Aggregator
err error
errs []error
viewcache string
viewcacheTextareaXY []int
@ -50,7 +50,7 @@ func NewModel(c *ctx.Ctx) Model {
),
xywh: [4]int{0, 0, 0, 0},
err: nil,
errs: []error{},
viewcache: "",
viewcacheTextareaXY: []int{0, 0, 0, 0},
@ -77,12 +77,19 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var vcmd tea.Cmd
m.ctx.Logger.Debugf("ERROR IS: %v\n", m.err)
if m.err != nil {
m.viewport.SetContent(m.err.Error())
}
m.setErrorContent()
m.viewport, vcmd = m.viewport.Update(msg)
cmds = append(cmds, vcmd)
return m, tea.Batch(cmds...)
}
func (m *Model) setErrorContent() {
if len(m.errs) > 0 {
var tmp string = ""
for _, err := range m.errs {
tmp += err.Error() + "\n"
}
m.viewport.SetContent(tmp)
}
}