aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-01-31 14:29:54 +1000
committerDavid Walter Seikel2014-01-31 14:29:54 +1000
commitbbd8ecd2f69b9e00848d18eb68b400ac118bc83b (patch)
tree8913169ccf61bbf47c58cb314f0a8a55c71cfb61
parentActually scroll the terminal when we get to the end of it. (diff)
downloadboxes-bbd8ecd2f69b9e00848d18eb68b400ac118bc83b.zip
boxes-bbd8ecd2f69b9e00848d18eb68b400ac118bc83b.tar.gz
boxes-bbd8ecd2f69b9e00848d18eb68b400ac118bc83b.tar.bz2
boxes-bbd8ecd2f69b9e00848d18eb68b400ac118bc83b.tar.xz
Document handle_keys() and friends.
-rw-r--r--handlekeys.h49
1 files changed, 48 insertions, 1 deletions
diff --git a/handlekeys.h b/handlekeys.h
index c12c290..00e6e93 100644
--- a/handlekeys.h
+++ b/handlekeys.h
@@ -3,5 +3,52 @@
3 * Copyright 2012 David Seikel <won_fang@yahoo.com.au> 3 * Copyright 2012 David Seikel <won_fang@yahoo.com.au>
4 */ 4 */
5 5
6void handle_keys(long extra, int (*handle_sequence)(long extra, char *sequence), void (*handle_CSI)(long extra, char *command, int *params, int count)); 6/* An input loop that handles keystrokes and terminal CSI commands.
7 *
8 * Reads stdin, trying to convert raw keystrokes into something more readable.
9 * See the keys[] array at the top of handlekeys.c for what byte sequences get
10 * translated into what key names. See dumbsh.c for an example of usage.
11 * A 0.1 second delay is used to detect the Esc key being pressed, and not Esc
12 * being part of a raw keystroke. As a bonus, Midnight Commander style
13 * "Esc digit" sequences are translated to function keys.
14 *
15 * handle_keys also tries to decode CSI commands that terminals can send.
16 * Some keystrokes are CSI commands, but those are translated as key sequences
17 * instead of CSI commands.
18 *
19 * handle_keys also sets up a SIGWINCH handler to catch terminal resizes,
20 * and sends a request to the terminal to report it's current size when it gets
21 * a SIGWINCH. This is the main reason for handle_CSI, as those reports are
22 * sent as CSI. It's still up to the user code to recognise and deal with the
23 * terminal resize response, but at least it's nicely decoded for you.
24 *
25 * Arguments -
26 * extra - arbitrary data that gets passed back to the callbacks.
27 * handle_sequence - a callback to handle keystroke sequences.
28 * handle_CSI - a callback to handle terminal CSI commands.
29 *
30 * handle_sequence is called when a complete keystroke sequence has been
31 * accumulated. It should return 1 if the sequence has been dealt with,
32 * otherwise it should return 0, then handle_keys will keep adding more
33 * complete keystroke sequences on the end, and try again later.
34 *
35 * handle_CSI is called when a complete terminal CSI command has been
36 * detected. The command argument is the full CSI command code, including
37 * private and intermediate characters. The params argument is the decoded
38 * parameters from the command. The count argument is the number of decoded
39 * parameters. Empty parameters are set to -1, coz -1 parameters are not legal,
40 * and empty ones should default to something that is command dependant.
41 *
42 * NOTE - handle_CSI differs from handle_sequence in not having to
43 * return anything. CSI sequences include a definite terminating byte,
44 * so no need for this callback to tell handle_keys to keep accumulating.
45 * Some applications use a series of keystrokes for things, so they
46 * get accumulated until fully recognised by the user code.
47 */
48void handle_keys(long extra,
49 int (*handle_sequence)(long extra, char *sequence),
50 void (*handle_CSI)(long extra, char *command, int *params, int count));
51
52
53/* Call this when you want handle_keys to return. */
7void handle_keys_quit(); 54void handle_keys_quit();