npcole / npyscreen

Automatically exported from code.google.com/p/npyscreen
Other
481 stars 109 forks source link

How to get Function keys using putty? #80

Open pdumais opened 5 years ago

pdumais commented 5 years ago

Hi, I'm trying to add a handler for the F1 key on text control. when running from putty, that key generates "]11~" in the text control.

I understand that this can be solved by configuring putty to send ^[OP instead, or to properly set the TERM variable. But I don't want to impose those settings to my users. When using putty, pressing F1 in Vim works fine (and in other TUI apps also) even if the termcap for xterm is defined as ^[OP. So it seems that Vim is smart enough to detect the sequence.

How would I go about detecting that from a npyscreen app? I've tried using add_complex_handlers but It gets messy and doesn't seem to return all chars when using it on a text control.

dmgolembiowski commented 5 years ago

Hi there, I'm exploring a similar issue at the moment. I don't believe there is either a clean or an easy fix to that one. Your solution potentially involves overwriting one of the core base classes deep in the repository, at: https://github.com/npcole/npyscreen/blob/b032562a7dbedbe3a273b443a8303d3f57e7ac89/build/lib/npyscreen/wgwidget.py There's no telling what might happen when you might try changing the methods to the InputHandler class, but I suspect you could apply a wrapper around instance.set_up_handlers() to force a nonlocal variable to update instance.handlers with dictionary that uses curses.KEY_F1 as a key to point to a hard-coded curses.ascii combination that meets your needs.