64 while (read(STDIN_FILENO, &
key, 1) != -1)
77 write(STDOUT_FILENO, &
key, 1) || 0;
79 write(STDOUT_FILENO, &
key, 1) || 0;
81 write(STDOUT_FILENO, &
key, 1) || 0;
103 write(STDOUT_FILENO,
"]", 1) || 0;
120 for (
int i =
size - 1;
i > 0;
i--)
171 static int ttyConsoleHide = 0;
177 assert(ttyConsoleHide > 0);
179 if (ttyConsoleHide == 0)
182 if (ttyConsoleHide == 0)
196 tcsetattr(STDIN_FILENO, TCSADRAIN, &
TTY_tc);
200 fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) & ~O_NONBLOCK);
210 const char* term = getenv(
"TERM");
211 return isatty(STDIN_FILENO) && !(term && (
Q_streq(term,
"raw") ||
Q_streq(term,
"dumb")));
221 signal(SIGTTIN, SIG_IGN);
222 signal(SIGTTOU, SIG_IGN);
228 fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);
238 tcgetattr(STDIN_FILENO, &
TTY_tc);
241 struct termios tc =
TTY_tc;
250 tc.c_lflag &= ~(ECHO | ICANON);
256 tc.c_iflag &= ~(ISTRIP | INPCK);
259 tcsetattr(STDIN_FILENO, TCSADRAIN, &tc);
266 static char text[256];
270 int avail = read(STDIN_FILENO, &
key, 1);
291 write(1, &
key, 1) || 0;
292 write(1,
"]", 1) || 0;
304 avail = read(STDIN_FILENO, &
key, 1);
307 if (
key ==
'[' ||
key ==
'O') {
309 avail = read(STDIN_FILENO, &
key, 1);
351 write(STDOUT_FILENO, &
key, 1) || 0;
357 struct timeval timeout;
360 FD_SET(STDIN_FILENO, &fdset);
363 if (select(STDIN_FILENO + 1, &fdset,
nullptr,
nullptr, &timeout) == -1
364 || !FD_ISSET(STDIN_FILENO, &fdset))
367 const int len = read(STDIN_FILENO, text,
sizeof(text));
385 const int origflags = fcntl(STDOUT_FILENO, F_GETFL, 0);
387 fcntl(STDOUT_FILENO, F_SETFL, origflags & ~FNDELAY);
389 const ssize_t written = write(STDOUT_FILENO,
string, strlen(
string));
394 fcntl(STDOUT_FILENO, F_SETFL, origflags);
bool Com_ConsoleCompleteCommand(const char *s, char *target, size_t bufSize, uint32_t *pos, uint32_t offset)
Console completion for command and variables.
void Com_Printf(const char *const fmt,...)
definitions common between client and server, but not game lib
QGL_EXTERN GLuint GLchar GLuint * len
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
static consoleHistory_t ttyEditLines[CON_HISTORY]
void Sys_ConsoleInit(void)
Initialize the console input (tty mode if possible).
static void Sys_TTYConsoleHistoryClear(consoleHistory_t *edit)
static consoleHistory_t * Sys_TTYConsoleHistoryPrevious(void)
const char * Sys_ConsoleInput(void)
static bool Sys_IsATTY(void)
static void Sys_TTYConsoleHide(void)
Clear the display of the line currently edited bring cursor back to beginning of line.
void Sys_ShowConsole(bool show)
static struct termios TTY_tc
void Sys_ConsoleShutdown(void)
Shutdown the console.
static void Sys_TTYDeleteCharacter(void)
Output a backspace.
static consoleHistory_t * Sys_TTYConsoleHistoryNext(void)
void Sys_ConsoleOutput(const char *string)
static void CON_FlushIn(void)
Flush stdin, I suspect some terminals are sending a LOT of shit.
static consoleHistory_t ttyConsoleHistory
static void Sys_TTYConsoleSigCont(int signum)
Reinitialize console input after receiving SIGCONT, as on Linux the terminal seems to lose all set at...
static void Sys_TTYConsoleHistoryAdd(consoleHistory_t *field)
static bool ttyConsoleActivated
static void Sys_TTYConsoleShow(void)
Show the current line.