From e48ff5bea4725d39818f24fa76b5ae74971f23a3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 30 Apr 2018 10:55:37 +0300 Subject: Update dependencies --- vendor/maunium.net/go/tview/box.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'vendor/maunium.net/go/tview/box.go') 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 -- cgit v1.2.3