| 39 | } |
| 40 | |
| 41 | func (ep *msgPopup) layout(g *gocui.Gui) error { |
| 42 | if !ep.active { |
| 43 | return nil |
| 44 | } |
| 45 | |
| 46 | maxX, maxY := g.Size() |
| 47 | |
| 48 | width := minInt(60, maxX) |
| 49 | wrapped, lines := text.Wrap(ep.message, width-2) |
| 50 | height := minInt(lines+1, maxY-3) |
| 51 | x0 := (maxX - width) / 2 |
| 52 | y0 := (maxY - height) / 2 |
| 53 | |
| 54 | v, err := g.SetView(msgPopupView, x0, y0, x0+width, y0+height, 0) |
| 55 | if err != nil { |
| 56 | if !errors.Is(err, gocui.ErrUnknownView) { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | v.Frame = true |
| 61 | v.Autoscroll = true |
| 62 | } |
| 63 | |
| 64 | v.Title = ep.title |
| 65 | |
| 66 | v.Clear() |
| 67 | _, _ = fmt.Fprint(v, wrapped) |
| 68 | |
| 69 | if _, err := g.SetCurrentView(msgPopupView); err != nil { |
| 70 | return err |
| 71 | } |
| 72 | |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | func (ep *msgPopup) close(g *gocui.Gui, v *gocui.View) error { |
| 77 | ep.active = false |