diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-04-30 10:55:37 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-04-30 10:55:37 +0300 |
commit | e48ff5bea4725d39818f24fa76b5ae74971f23a3 (patch) | |
tree | 549b8688ef59f7096a20544cd01ad75ec111c0e4 /vendor/maunium.net/go/tview/box.go | |
parent | 576bab9e2e9589942d4cac8742fa1b54e8b237f9 (diff) |
Update dependencies
Diffstat (limited to 'vendor/maunium.net/go/tview/box.go')
-rw-r--r-- | vendor/maunium.net/go/tview/box.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/maunium.net/go/tview/box.go b/vendor/maunium.net/go/tview/box.go index 1bcbff0..ff3cc1e 100644 --- a/vendor/maunium.net/go/tview/box.go +++ b/vendor/maunium.net/go/tview/box.go @@ -62,6 +62,8 @@ type Box struct { // nothing should be forwarded). mouseCapture func(event *tcell.EventMouse) *tcell.EventMouse + pasteCapture func(event *tcell.EventPaste) *tcell.EventPaste + // An optional function which is called before the box is drawn. draw func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) } @@ -218,6 +220,36 @@ func (b *Box) GetMouseCapture() func(event *tcell.EventMouse) *tcell.EventMouse return b.mouseCapture } +func (b *Box) WrapPasteHandler(pasteHandler func(*tcell.EventPaste)) func(*tcell.EventPaste) { + return func(event *tcell.EventPaste) { + if b.pasteCapture != nil { + event = b.pasteCapture(event) + } + if event != nil && pasteHandler != nil { + pasteHandler(event) + } + } +} + +func (b *Box) PasteHandler() func(event *tcell.EventPaste) { + return b.WrapPasteHandler(func(event *tcell.EventPaste) { + // Default paste handler just calls input handler with each character. + inputHandler := b.InputHandler() + for _, char := range event.Text() { + inputHandler(tcell.NewEventKey(tcell.KeyRune, char, tcell.ModNone), nil) + } + }) +} + +func (b *Box) SetPasteCapture(capture func(event *tcell.EventPaste) *tcell.EventPaste) *Box { + b.pasteCapture = capture + return b +} + +func (b *Box) GetPasteCapture() func(event *tcell.EventPaste) *tcell.EventPaste { + return b.pasteCapture +} + // SetBackgroundColor sets the box's background color. func (b *Box) SetBackgroundColor(color tcell.Color) *Box { b.backgroundColor = color |