caller just got an input character of ESC or M-^O; note: curses converts a lot of escape sequences to single values greater than 255 and those won't look like ESC to caller so won't get here */
| 997 | note: curses converts a lot of escape sequences to single values greater |
| 998 | than 255 and those won't look like ESC to caller so won't get here */ |
| 999 | static int |
| 1000 | parse_escape_sequence(int key, boolean *keypadnum) |
| 1001 | { |
| 1002 | #ifndef PDCURSES |
| 1003 | int ret, keypadother = 0; |
| 1004 | |
| 1005 | *keypadnum = FALSE; |
| 1006 | |
| 1007 | timeout(10); |
| 1008 | ret = getch(); |
| 1009 | |
| 1010 | if (ret == 'O' || key == SS3) { /* handle numeric keypad */ |
| 1011 | /* |
| 1012 | * ESC O <pending> or M-^O <something|nothing>. |
| 1013 | * |
| 1014 | * For the former, we don't have the next char yet so get it now. |
| 1015 | * If there isn't one, treat ESC O as if user typed M-O (which |
| 1016 | * is probably the case, via alt+shift+O combo sending two char |
| 1017 | * "ESC O"). |
| 1018 | * |
| 1019 | * For the latter, it there wasn't another char then 'ret' will |
| 1020 | * be ERR and we'll treat the result as M-^O. However, if there |
| 1021 | * is another char and it is O meant as two characters "M-^O O" |
| 1022 | * we'll be fooled, but that's not a valid escape sequence so |
| 1023 | * don't worry about those two characters arriving together. |
| 1024 | */ |
| 1025 | if (key == '\033') |
| 1026 | ret = getch(); |
| 1027 | |
| 1028 | if (ret == ERR) { |
| 1029 | iflags.term_gone = 1; |
| 1030 | /* there was no additional char; treat as M-O or M-^O below */ |
| 1031 | ret = (key == '\033') ? 'O' : C('O'); |
| 1032 | } else if (ret >= 112 && ret <= 121) { /* 'p'..'y' */ |
| 1033 | *keypadnum = TRUE; /* convert 'p'..'y' to '0'..'9' below */ |
| 1034 | } else if (ret >= 108 && ret <= 110) { /* 'l'..'n' */ |
| 1035 | keypadother = 1; /* convert 'l','m','n' to ',','.','-' below */ |
| 1036 | } else if (ret == 'M') { |
| 1037 | keypadother = 2; /* convert "ESC O M" or "SS3 M" to ^M */ |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | timeout(-1); /* reset to 'wait unlimited time for next input' */ |
| 1042 | |
| 1043 | if (*keypadnum) { |
| 1044 | /* 'p' -> '0', ..., 'y' -> '9' */ |
| 1045 | ret -= ('p' - '0'); /* Convert c from 'ESC O c' to digit */ |
| 1046 | } else if (keypadother > 0) { |
| 1047 | /* conversion for VT keypad keys (no plus; ignore PF1 through PF4) |
| 1048 | [typical PC keyboard has period and plus, no comma or minus] */ |
| 1049 | if (keypadother == 1) |
| 1050 | ret -= ('l' - ','); /* keypad comma, period, or minus */ |
| 1051 | else |
| 1052 | ret = C('M'); /* keypad <enter> */ |
| 1053 | } else if (ret != ERR && ret <= 255) { |
| 1054 | /* ESC <something>; effectively 'altmeta' behind player's back */ |
| 1055 | ret = M(ret); /* Meta key support for most terminals */ |
| 1056 | } else { |
no outgoing calls
no test coverage detected