init
This commit is contained in:
27
c-src/terminal_linux.c
Normal file
27
c-src/terminal_linux.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "../include/terminal.h"
|
||||
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static struct termios orig_termios;
|
||||
|
||||
void exit_raw_mode() {
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
|
||||
}
|
||||
|
||||
void enter_raw_mode() {
|
||||
tcgetattr(STDIN_FILENO, &orig_termios);
|
||||
// atexit(exit_raw_mode); // zig is handling this step
|
||||
struct termios raw = orig_termios;
|
||||
raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
||||
raw.c_oflag &= ~(OPOST);
|
||||
raw.c_cflag |= (CS8);
|
||||
raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
|
||||
|
||||
raw.c_cc[VMIN] = 0;
|
||||
// raw.c_cc[VTIME] = 1;
|
||||
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
|
||||
}
|
||||
|
||||
51
c-src/terminal_windows.c
Normal file
51
c-src/terminal_windows.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "../include/terminal.h"
|
||||
#include <Windows.h>
|
||||
#include <consoleapi.h>
|
||||
#include <minwindef.h>
|
||||
#include <processenv.h>
|
||||
#include <winbase.h>
|
||||
|
||||
#define DEFAULT_CONSOLE_MODE (\
|
||||
ENABLE_ECHO_INPUT |\
|
||||
ENABLE_LINE_INPUT |\
|
||||
ENABLE_MOUSE_INPUT |\
|
||||
ENABLE_PROCESSED_INPUT |\
|
||||
ENABLE_QUICK_EDIT_MODE |\
|
||||
ENABLE_WINDOW_INPUT |\
|
||||
ENABLE_PROCESSED_OUTPUT |\
|
||||
ENABLE_WRAP_AT_EOL_OUTPUT |\
|
||||
ENABLE_VIRTUAL_TERMINAL_PROCESSING |\
|
||||
DISABLE_NEWLINE_AUTO_RETURN |\
|
||||
ENABLE_LVB_GRID_WORLDWIDE)
|
||||
|
||||
#define RAW_CONSOLE_MODE \
|
||||
ENABLE_WINDOW_INPUT |\
|
||||
ENABLE_VIRTUAL_TERMINAL_INPUT
|
||||
// ENABLE_PROCESSED_INPUT |\
|
||||
|
||||
static DWORD mode = 0;
|
||||
|
||||
void enter_raw_mode() {
|
||||
|
||||
GetConsoleMode(
|
||||
GetStdHandle(STD_INPUT_HANDLE),
|
||||
&mode
|
||||
);
|
||||
|
||||
SetConsoleMode(
|
||||
GetStdHandle(STD_INPUT_HANDLE),
|
||||
RAW_CONSOLE_MODE
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void exit_raw_mode() {
|
||||
|
||||
SetConsoleMode(
|
||||
GetStdHandle(STD_INPUT_HANDLE),
|
||||
mode
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user