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

Function enableRawMode

tools/shell/linenoise.cpp:813–884  ·  view source on GitHub ↗

Raw mode: 1960 magic shit. */

Source from the content-addressed store, hash-verified

811
812/* Raw mode: 1960 magic shit. */
813static int enableRawMode(int fd) {
814#ifndef _WIN32
815 struct termios raw;
816
817 if (!isatty(STDIN_FILENO))
818 goto fatal;
819 if (!atexit_registered) {
820 atexit(linenoiseAtExit);
821 atexit_registered = 1;
822 }
823 if (tcgetattr(fd, &orig_termios) == -1)
824 goto fatal;
825
826 raw = orig_termios; /* modify the original mode */
827 /* input modes: no break, no CR to NL, no parity check, no strip char,
828 * no start/stop output control. */
829 raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
830 /* output modes - disable post processing */
831 raw.c_oflag &= ~(OPOST);
832 /* control modes - set 8 bit chars */
833 raw.c_cflag |= (CS8);
834 /* local modes - choing off, canonical off, no extended functions,
835 * no signal chars (^Z,^C) */
836 raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
837 /* control chars - set return condition: min number of bytes and timer.
838 * We want read to return every single byte, without timeout. */
839 raw.c_cc[VMIN] = 1;
840 raw.c_cc[VTIME] = 0; /* 1 byte, no timer */
841
842 /* put terminal in raw mode after flushing */
843 if (tcsetattr(fd, TCSADRAIN, &raw) < 0)
844 goto fatal;
845 rawmode = 1;
846#else
847 REDIS_NOTUSED(fd);
848
849 if (!atexit_registered) {
850 /* Cleanup them at exit */
851 atexit(linenoiseAtExit);
852 atexit_registered = 1;
853
854 /* Init windows console handles only once */
855 hOut = GetStdHandle(STD_OUTPUT_HANDLE);
856 if (hOut == INVALID_HANDLE_VALUE)
857 goto fatal;
858 }
859
860 DWORD consolemodeOut;
861 if (!GetConsoleMode(hOut, &consolemodeOut)) {
862 CloseHandle(hOut);
863 errno = ENOTTY;
864 return -1;
865 };
866
867 hIn = GetStdHandle(STD_INPUT_HANDLE);
868 if (hIn == INVALID_HANDLE_VALUE) {
869 CloseHandle(hOut);
870 errno = ENOTTY;

Callers 2

linenoisePrintKeyCodesFunction · 0.85
linenoiseRawFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected