1package wtf 2 3import ( 4 "github.com/gdamore/tcell" 5 "github.com/rivo/tview" 6) 7 8const offscreen = -1000 9const modalWidth = 80 10const modalHeight = 22 11 12func NewBillboardModal(text string, closeFunc func()) *tview.Frame { 13 keyboardIntercept := func(event *tcell.EventKey) *tcell.EventKey { 14 if string(event.Rune()) == "/" { 15 closeFunc() 16 return nil 17 } 18 19 switch event.Key() { 20 case tcell.KeyEsc: 21 closeFunc() 22 return nil 23 case tcell.KeyTab: 24 return nil 25 default: 26 return event 27 } 28 } 29 30 textView := tview.NewTextView() 31 textView.SetDynamicColors(true) 32 textView.SetInputCapture(keyboardIntercept) 33 textView.SetText(text) 34 textView.SetWrap(true) 35 36 frame := tview.NewFrame(textView) 37 frame.SetRect(offscreen, offscreen, modalWidth, modalHeight) 38 39 drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) { 40 w, h := screen.Size() 41 frame.SetRect((w/2)-(width/2), (h/2)-(height/2), width, height) 42 return x, y, width, height 43 } 44 45 frame.SetBorder(true) 46 frame.SetBorders(1, 1, 0, 0, 1, 1) 47 frame.SetDrawFunc(drawFunc) 48 49 return frame 50} 51