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.
This commit is contained in:
Leandro Dorileo 2018-04-03 13:07:49 -07:00
parent 8d3cd97d8e
commit efa32413a4
4 changed files with 6 additions and 6 deletions

View File

@ -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))

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}