开发者

ncurses escape sequence detection

what is the best way to detect escape sequences in ncurses raw mode.

The thing that come to my mind is do getch and then add it to some kind of buffer and then when the text matches known escape sequence execute appropriate command otherwise ignore the sequence.

However in this algorithm if i hit an escape sequence that system doesn't know about even if a continue typing other characters they will be considered as a part of escape sequence. Are there any rules of how long the escape sequence can be or some standart characters that end escape sequence

Or is there a way of detecting in ncurses when user stopped typing the characters? like escape sequence usually come as sequence of characters but i have no way to detect the last character because i have a blocking getch that just blocks when there are no characters from input system

like for example if i press page down and c button i have continuous stream of escape sequence characters ^[[6~ and then character c. how can i detect between those t开发者_如何学Gowo that the user pressed first escape sequence and then c character if i don't have a predefined set of known escape sequences


You may wish to use libtermkey to parse the key events.

http://www.leonerd.org.uk/code/libtermkey/

Either you can connect it directly to stdin, or feed it bytes as given to you by getch().

As to the general idea of detecting the end; there are certain rules that sequences follow. Sequences starting ESC [ are CSI sequences, and end on the first octet in the range [\x40-\x7e]. There are a few other kinds but they're rare to come from a terminal.


Without a predefined set of escape sequences you will not be able to determine the end of a sequence.

Ncurses uses termcap/terminfo to enumerate the sequences and their meanings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜