mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* WTF-484 DigitalOcean module stubbed out * WTF-484 Delete droplets via Ctrl-d * WTF-484 Rebasing off master after a long time away * WTF-484 Improve DigitalOcean display * WTF-484 Can shutdown and restart the selected droplet * WTF-484 Display info about the selected droplet using the ? key * WTF-484 Display info about the selected droplet using the Return key * WTF-484 Greatly improve the utils.Truncate function * WTF-484 Display a droplet's features in the info modal * WTF-484 Change reboot key from r to b to not conflict with refresh * WTF-484 Panic if a keyboard control is mapped to the same character more than once * WTF-484 Colorize droplet status indicator * WTF-484 Extract view.InfoTable out into a reusable component
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package view
|
|
|
|
import (
|
|
"github.com/gdamore/tcell"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
const offscreen = -1000
|
|
const modalWidth = 80
|
|
const modalHeight = 22
|
|
|
|
// NewBillboardModal creates and returns a modal dialog suitable for displaying
|
|
// a wall of text
|
|
// An example of this is the keyboard help modal that shows up for all widgets
|
|
// that support keyboard control when '/' is pressed
|
|
func NewBillboardModal(text string, closeFunc func()) *tview.Frame {
|
|
keyboardIntercept := func(event *tcell.EventKey) *tcell.EventKey {
|
|
if string(event.Rune()) == "/" {
|
|
closeFunc()
|
|
return nil
|
|
}
|
|
|
|
switch event.Key() {
|
|
case tcell.KeyEsc:
|
|
closeFunc()
|
|
return nil
|
|
case tcell.KeyTab:
|
|
return nil
|
|
default:
|
|
return event
|
|
}
|
|
}
|
|
|
|
textView := tview.NewTextView()
|
|
textView.SetDynamicColors(true)
|
|
textView.SetInputCapture(keyboardIntercept)
|
|
textView.SetText(text)
|
|
textView.SetWrap(true)
|
|
|
|
frame := tview.NewFrame(textView)
|
|
frame.SetRect(offscreen, offscreen, modalWidth, modalHeight)
|
|
|
|
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
|
w, h := screen.Size()
|
|
frame.SetRect((w/2)-(width/2), (h/2)-(height/2), width, height)
|
|
return x, y, width, height
|
|
}
|
|
|
|
frame.SetBorder(true)
|
|
frame.SetBorders(1, 1, 0, 0, 1, 1)
|
|
frame.SetDrawFunc(drawFunc)
|
|
|
|
return frame
|
|
}
|