peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.64k stars 238 forks source link

more keyboard interactions #334

Closed eyaler closed 3 years ago

eyaler commented 3 years ago

i am missing two types of keyboard interactions:

  1. key pressed event for special key combinations e.g. alt-a, ctrl-f1
  2. key released event
peterbrittain commented 3 years ago

Sadly, these are largely limitations of the terminal interface.

On the first point, the maintainer of curses explains how support of modified keys in terminals is limited and so fragmented as to be impossible to handle them all: https://invisible-island.net/ncurses/ncurses.faq.html#modified_keys. Then there's a pretty good blog post about key release events here: https://blog.robertelder.org/detect-keyup-event-linux-terminal/.

Asciimatics is designed to run in a true terminal environment (i.e. the SSH connection case in that blog post), so cannot support these types of events. The best you can do there is use the keyboard package if you really need that level of control. That should give you access to everything, but at the cost of running as root and no longer being able to run over a terminal connection.

peterbrittain commented 3 years ago

Longer term, there may be a new standard for handling modifiers (as debated in https://github.com/microsoft/terminal/issues/8719). However, that is still far from universal and would currently require moving away from curses (e.g. to termkey), so not something that would be worth implementing yet.

peterbrittain commented 3 years ago

Net is that I think I'll just have to document the current limitations.

peterbrittain commented 3 years ago

Now covered by https://github.com/peterbrittain/asciimatics/commit/613a4ddc67cb808b45dc4b90f1b93f0b78bfc9df