From efa32413a4b53bfba78f353856fcba23a667567f Mon Sep 17 00:00:00 2001 From: Leandro Dorileo Date: Tue, 3 Apr 2018 13:07:49 -0700 Subject: [PATCH] edit: pass event.Ch to OnKeyPress callback It seems beneficial the callback to also know the event.Ch so we can implement more "sophisticated" field filling validation strategies. --- demos/maindemo/clui_demo.go | 2 +- edit.go | 2 +- edit_osx.go | 4 ++-- edit_other.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/demos/maindemo/clui_demo.go b/demos/maindemo/clui_demo.go index c1311f1..8885262 100644 --- a/demos/maindemo/clui_demo.go +++ b/demos/maindemo/clui_demo.go @@ -91,7 +91,7 @@ func createView() { ui.ActivateControl(view, edit) - edit.OnKeyPress(func(key term.Key) bool { + edit.OnKeyPress(func(key term.Key, ch rune) bool { if key == term.KeyCtrlM { v := edit.Title() logBox.AddItem(fmt.Sprintf("New PB value(KeyPress): %v", v)) diff --git a/edit.go b/edit.go index 581dfe2..3631ea4 100644 --- a/edit.go +++ b/edit.go @@ -15,7 +15,7 @@ func (e *EditField) OnChange(fn func(Event)) { // the controls is active. If a handler processes the key it should return // true. If handler returns false it means that the default handler will // process the key -func (e *EditField) OnKeyPress(fn func(term.Key) bool) { +func (e *EditField) OnKeyPress(fn func(term.Key, rune) bool) { e.onKeyPress = fn } diff --git a/edit_osx.go b/edit_osx.go index 4ae0e32..40f22b4 100644 --- a/edit_osx.go +++ b/edit_osx.go @@ -30,7 +30,7 @@ type EditField struct { showStars bool onChange func(Event) - onKeyPress func(term.Key) bool + onKeyPress func(term.Key, rune) bool lastEvent time.Time } @@ -93,7 +93,7 @@ func (e *EditField) ProcessEvent(event Event) bool { if event.Type == EventKey && event.Key != term.KeyTab { if e.onKeyPress != nil { - res := e.onKeyPress(event.Key) + res := e.onKeyPress(event.Key, event.Ch) if res { return true } diff --git a/edit_other.go b/edit_other.go index 6c2276c..3acc120 100644 --- a/edit_other.go +++ b/edit_other.go @@ -28,7 +28,7 @@ type EditField struct { showStars bool onChange func(Event) - onKeyPress func(term.Key) bool + onKeyPress func(term.Key, rune) bool } // NewEditField creates a new EditField control @@ -84,7 +84,7 @@ func (e *EditField) ProcessEvent(event Event) bool { if event.Type == EventKey && event.Key != term.KeyTab { if e.onKeyPress != nil { - res := e.onKeyPress(event.Key) + res := e.onKeyPress(event.Key, event.Ch) if res { return true }