Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Default handler for all keybindings. #159

Open
lesovsky opened this issue May 11, 2018 · 1 comment
Open

Question: Default handler for all keybindings. #159

lesovsky opened this issue May 11, 2018 · 1 comment

Comments

@lesovsky
Copy link

lesovsky commented May 11, 2018

Hi,

Is there a way to define default handler function for all keybindings which are not defined separately?
For example, a program has a set of keybindings with associated handlers, and also there are other keybindings that are not associated with any functions. When user presses all another keys, program should run default handler which should display something like: 'unknown command -- try "h" for help'

is it possible?

@michalkowalik
Copy link

michalkowalik commented Jun 27, 2018

I hope it's OK if I comment on it.
One possible option, which I'm using is to write your own editor function. It may be as simple as sending the keystroke to the channel:

func ed(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
  keystrokes <- ch
}

and processing the keys / runes any way you want, for example:

// read from keyboard:
  go func() {
  	for {
  		k := <-keystrokes
  		g.Update(func(g *gocui.Gui) error {
			v, _ := g.View(termName)
			fmt.Fprintf(v, "KEY -> %s\n", string(k))
			v.MoveCursor(0, 1, true)
			return nil
		})
	}
}()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants