MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / linenoisePrintKeyCodes

Function linenoisePrintKeyCodes

tools/shell/linenoise.cpp:3783–3808  ·  view source on GitHub ↗

This special mode is used by linenoise in order to print scan codes * on screen for debugging / development purposes. It is implemented * by the linenoise_example program using the --keycodes option. */

Source from the content-addressed store, hash-verified

3781 * on screen for debugging / development purposes. It is implemented
3782 * by the linenoise_example program using the --keycodes option. */
3783void linenoisePrintKeyCodes(void) {
3784 char quit[4];
3785
3786 printf("Linenoise key codes debugging mode.\n"
3787 "Press keys to see scan codes. Type 'quit' at any time to exit.\n");
3788 if (enableRawMode(STDIN_FILENO) == -1)
3789 return;
3790 memset(quit, ' ', 4);
3791 while (1) {
3792 char c;
3793 int nread;
3794
3795 nread = read(STDIN_FILENO, &c, 1);
3796 if (nread <= 0)
3797 continue;
3798 memmove(quit, quit + 1, sizeof(quit) - 1); /* shift string to left. */
3799 quit[sizeof(quit) - 1] = c; /* Insert current char on the right. */
3800 if (memcmp(quit, "quit", sizeof(quit)) == 0)
3801 break;
3802
3803 printf("'%c' %02x (%d) (type quit to exit)\n", isprint(c) ? c : '?', (int)c, (int)c);
3804 printf("\r"); /* Go left edge manually, we are in raw mode. */
3805 fflush(stdout);
3806 }
3807 disableRawMode(STDIN_FILENO);
3808}
3809
3810/* This function calls the line editing function linenoiseEdit() using
3811 * the STDIN file descriptor set in raw mode. */

Callers

nothing calls this directly

Calls 3

enableRawModeFunction · 0.85
readFunction · 0.85
disableRawModeFunction · 0.85

Tested by

no test coverage detected