From 386c7be1a7a1d510f5bab384c98adc31c22ff290 Mon Sep 17 00:00:00 2001 From: Miheev Egor Date: Tue, 10 Sep 2024 23:43:12 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D1=8B=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Для повторения bioskey было написано несколько новых функций, переводящих теорминал в неканонический режим и читающие нажатия на клавиши. Также все наработки были вынесены в отдельный файл, чтобы не засорять основной файл --- 01-asm-basics/substitutions.c | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 01-asm-basics/substitutions.c diff --git a/01-asm-basics/substitutions.c b/01-asm-basics/substitutions.c new file mode 100644 index 0000000..c59edcd --- /dev/null +++ b/01-asm-basics/substitutions.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +/* Use this variable to remember original terminal attributes. */ + +struct termios saved_attributes; + +void reset_input_mode() +{ + tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes); +} + +void set_input_mode() +{ + struct termios tattr; + char *name; + + /* Make sure stdin is a terminal. */ + if (!isatty (STDIN_FILENO)) + { + fprintf (stderr, "Not a terminal.\n"); + exit (EXIT_FAILURE); + } + + /* Save the terminal attributes so we can restore them later. */ + tcgetattr (STDIN_FILENO, &saved_attributes); + atexit (reset_input_mode); + + /* Set the funny terminal modes. */ + tcgetattr (STDIN_FILENO, &tattr); + tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ + tattr.c_cc[VMIN] = 1; + tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr); +} + +void delay(unsigned int ms) +{ + usleep(ms * 1000); +} + +char isKeyPressed() +{ + char key_handler = 0; + read(STDIN_FILENO, &key_handler, 1); + if (key_handler > 0) + { + return 1; + } + return 0; +} + +//int main() +//{ +// set_input_mode(); +// while (isKeyPressed() == 0) {} +// printf("ok"); +// reset_input_mode(); +//}