|
|
|
@ -29,7 +29,7 @@ type Application struct {
|
|
|
|
|
// An optional capture function which receives a key event and returns the
|
|
|
|
|
// event to be forwarded to the default input handler (nil if nothing should
|
|
|
|
|
// be forwarded).
|
|
|
|
|
inputCapture func(event *tcell.EventKey) *tcell.EventKey
|
|
|
|
|
inputCapture func(event tcell.Event) tcell.Event
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewApplication creates and returns a new application.
|
|
|
|
@ -46,11 +46,15 @@ func NewApplication() *Application {
|
|
|
|
|
// 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
|
|
|
|
|
// applicatoon.
|
|
|
|
|
func (a *Application) SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *Application {
|
|
|
|
|
func (a *Application) SetInputCapture(capture func(event tcell.Event) tcell.Event) *Application {
|
|
|
|
|
a.inputCapture = capture
|
|
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *Application) Screen() tcell.Screen {
|
|
|
|
|
return a.screen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run starts the application and thus the event loop. This function returns
|
|
|
|
|
// when Stop() was called.
|
|
|
|
|
func (a *Application) Run() error {
|
|
|
|
@ -97,13 +101,7 @@ func (a *Application) Run() error {
|
|
|
|
|
break // The screen was finalized.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch event := event.(type) {
|
|
|
|
|
case *tcell.EventKey:
|
|
|
|
|
a.RLock()
|
|
|
|
|
p := a.focus
|
|
|
|
|
a.RUnlock()
|
|
|
|
|
|
|
|
|
|
// Intercept keys.
|
|
|
|
|
// Intercept all events.
|
|
|
|
|
if a.inputCapture != nil {
|
|
|
|
|
event = a.inputCapture(event)
|
|
|
|
|
if event == nil {
|
|
|
|
@ -111,6 +109,12 @@ func (a *Application) Run() error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch event := event.(type) {
|
|
|
|
|
case *tcell.EventKey:
|
|
|
|
|
a.RLock()
|
|
|
|
|
p := a.focus
|
|
|
|
|
a.RUnlock()
|
|
|
|
|
|
|
|
|
|
// Ctrl-C closes the application.
|
|
|
|
|
if event.Key() == tcell.KeyCtrlC {
|
|
|
|
|
a.Stop()
|
|
|
|
|