aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/key_reader.cpp
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-05-06 21:22:28 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-05-10 14:11:30 -0700
commitb055b8440c87c69e7f92a81f114ee77f48940f66 (patch)
tree5e686c338bb775fac7277be9f82ffa18e89b3cdb /src/key_reader.cpp
parent14d7b1a0fa4e9890a1d576cc0c5e04cca37e9ec7 (diff)
enhance the key_reader program
The original `key_reader` program was useful but didn't do much that `xxd` or `od -tx1z` didn't do. Furthermore, it wasn't built and installed by default. This change adds features that make it superior to those programs for decoding interactive key presses and makes it a first-class citizen like the `fish_indent` program that is always available. Fixes #2991
Diffstat (limited to 'src/key_reader.cpp')
-rw-r--r--src/key_reader.cpp74
1 files changed, 0 insertions, 74 deletions
diff --git a/src/key_reader.cpp b/src/key_reader.cpp
deleted file mode 100644
index 0d0b997f..00000000
--- a/src/key_reader.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-// A small utility to print the resulting key codes from pressing a key. Servers the same function
-// as hitting ^V in bash, but I prefer the way key_reader works.
-//
-// Type ^C to exit the program.
-#include <locale.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termcap.h>
-#include <termios.h>
-
-#include "common.h"
-#include "fallback.h" // IWYU pragma: keep
-#include "input_common.h"
-
-int writestr(char *str) {
- write_ignore(1, str, strlen(str));
- return 0;
-}
-
-int main(int argc, char **argv) {
- set_main_thread();
- setup_fork_guards();
- setlocale(LC_ALL, "");
-
- if (argc == 2) {
- static char term_buffer[2048];
- char *termtype = getenv("TERM");
- char *tbuff = new char[9999];
- char *res;
-
- tgetent(term_buffer, termtype);
- res = tgetstr(argv[1], &tbuff);
- if (res != 0) {
- while (*res != 0) {
- printf("%d ", *res);
-
- res++;
- }
- printf("\n");
- } else {
- printf("Undefined sequence\n");
- }
- } else {
- char scratch[1024];
- unsigned int c;
-
- struct termios modes, // so we can change the modes
- savemodes; // so we can reset the modes when we're done
-
- input_common_init(0);
-
- tcgetattr(0, &modes); // get the current terminal modes
- savemodes = modes; // save a copy so we can reset them
-
- modes.c_lflag &= ~ICANON; // turn off canonical mode
- modes.c_lflag &= ~ECHO; // turn off echo mode
- modes.c_cc[VMIN] = 1;
- modes.c_cc[VTIME] = 0;
- tcsetattr(0, TCSANOW, &modes); // set the new modes
- while (1) {
- if ((c = input_common_readch(0)) == EOF) break;
- if ((c > 31) && (c != 127))
- sprintf(scratch, "dec: %u hex: %x char: %c\n", c, c, c);
- else
- sprintf(scratch, "dec: %u hex: %x\n", c, c);
- writestr(scratch);
- }
- tcsetattr(0, TCSANOW, &savemodes); // reset the terminal to the saved mode
- input_common_destroy();
- }
-
- return 0;
-}