From 47e7db7885b49e9a3f301dd50175ba3d72795546 Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sun, 26 Feb 2023 20:52:29 +0100 Subject: [PATCH] Provided a way to forward Ctrl-C to primites. Resolves #816 --- application.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/application.go b/application.go index 1db47c2..c8a56cf 100644 --- a/application.go +++ b/application.go @@ -135,9 +135,16 @@ func NewApplication() *Application { // different one) by returning it or stop the key event processing by returning // nil. // -// Note that this also affects the default event handling of the application -// itself: Such a handler can intercept the Ctrl-C event which closes the -// application. +// The only default global key event is Ctrl-C which stops the application. It +// requires special handling: +// +// - If you do not wish to change the default behavior, return the original +// event object passed to your input capture function. +// - If you wish to block Ctrl-C from any functionality, return nil. +// - If you do not wish Ctrl-C to stop the application but still want to +// forward the Ctrl-C event to primitives down the hierarchy, return a new +// key event with the same key and modifiers, e.g. +// tcell.NewEventKey(tcell.KeyCtrlC, 0, tcell.ModNone). func (a *Application) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Application { a.inputCapture = capture return a @@ -315,6 +322,7 @@ EventLoop: // Intercept keys. var draw bool + originalEvent := event if inputCapture != nil { event = inputCapture(event) if event == nil { @@ -325,7 +333,7 @@ EventLoop: } // Ctrl-C closes the application. - if event.Key() == tcell.KeyCtrlC { + if event == originalEvent && event.Key() == tcell.KeyCtrlC { a.Stop() break }