Created
April 13, 2025 23:23
-
-
Save injust90/e2c9e420348a94857822a4222042246c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <termios.h> | |
#include <unistd.h> | |
#include <ctype.h> | |
#include <stdio.h> | |
struct termios orig_termios; | |
void disableRawMode() | |
{ | |
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios); | |
} | |
void enableRawMode() | |
{ | |
tcgetattr(STDIN_FILENO, &orig_termios); | |
atexit(disableRawMode); | |
struct termios raw = orig_termios; | |
raw.c_lflag &= ~(ECHO | ICANON); | |
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); | |
} | |
int main() | |
{ | |
enableRawMode(); | |
int c; | |
/* | |
while (read(STDIN_FILENO, &c, 1) == 1 && c!= 'q') | |
{ | |
// if (iscntrl(c)) { | |
if (c == 0x7F){ | |
printf("%d\n", c); | |
} | |
else { | |
printf("%d ('%c')\n", c, c); | |
} | |
} | |
*/ | |
while ((c = getchar()) != EOF) | |
{ | |
if (c == ' ') | |
printf("\\t"); | |
if (c == '\\') | |
printf("\\\\"); | |
if (c == 0x7F) | |
printf("backspace"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment