UFO: Alien Invasion
Loading...
Searching...
No Matches
unix_console.cpp File Reference

console functions for *nix ports More...

#include "../../common/common.h"
#include "../system.h"
#include <unistd.h>
#include <signal.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/time.h>
Include dependency graph for unix_console.cpp:

Go to the source code of this file.

Data Structures

struct  consoleHistory_t

Macros

#define CON_HISTORY   32

Functions

static void CON_FlushIn (void)
 Flush stdin, I suspect some terminals are sending a LOT of shit.
static void Sys_TTYDeleteCharacter (void)
 Output a backspace.
static void Sys_TTYConsoleHide (void)
 Clear the display of the line currently edited bring cursor back to beginning of line.
static void Sys_TTYConsoleShow (void)
 Show the current line.
static void Sys_TTYConsoleHistoryAdd (consoleHistory_t *field)
static consoleHistory_tSys_TTYConsoleHistoryPrevious (void)
static consoleHistory_tSys_TTYConsoleHistoryNext (void)
static void Sys_TTYConsoleSigCont (int signum)
 Reinitialize console input after receiving SIGCONT, as on Linux the terminal seems to lose all set attributes if user did CTRL+Z and then does fg again.
void Sys_ShowConsole (bool show)
void Sys_ConsoleShutdown (void)
 Shutdown the console.
static void Sys_TTYConsoleHistoryClear (consoleHistory_t *edit)
static bool Sys_IsATTY (void)
void Sys_ConsoleInit (void)
 Initialize the console input (tty mode if possible).
const char * Sys_ConsoleInput (void)
void Sys_ConsoleOutput (const char *string)

Variables

static bool stdinActive
static bool ttyConsoleActivated = false
static int TTY_erase
static int TTY_eof
static struct termios TTY_tc
static consoleHistory_t ttyConsoleHistory
static consoleHistory_t ttyEditLines [CON_HISTORY]
static int histCurrent = -1
static int histCount = 0

Detailed Description

console functions for *nix ports

Definition in file unix_console.cpp.

Macro Definition Documentation

◆ CON_HISTORY

#define CON_HISTORY   32

Definition at line 53 of file unix_console.cpp.

Referenced by Sys_TTYConsoleHistoryNext().

Function Documentation

◆ CON_FlushIn()

void CON_FlushIn ( void )
static

Flush stdin, I suspect some terminals are sending a LOT of shit.

Todo
relevant?

Definition at line 61 of file unix_console.cpp.

References key.

Referenced by Sys_ConsoleInput().

◆ Sys_ConsoleInit()

void Sys_ConsoleInit ( void )

Initialize the console input (tty mode if possible).

Definition at line 217 of file unix_console.cpp.

References Com_Printf(), stdinActive, Sys_IsATTY(), Sys_TTYConsoleHistoryClear(), Sys_TTYConsoleSigCont(), TTY_eof, TTY_erase, TTY_tc, ttyConsoleActivated, and ttyConsoleHistory.

Referenced by Sys_TTYConsoleSigCont().

◆ Sys_ConsoleInput()

◆ Sys_ConsoleOutput()

void Sys_ConsoleOutput ( const char * string)

Definition at line 382 of file unix_console.cpp.

◆ Sys_ConsoleShutdown()

void Sys_ConsoleShutdown ( void )

Shutdown the console.

Note
Never exit without calling this, or your terminal will be left in a pretty bad state

Definition at line 192 of file unix_console.cpp.

References Sys_TTYDeleteCharacter(), TTY_tc, and ttyConsoleActivated.

◆ Sys_IsATTY()

bool Sys_IsATTY ( void )
static

Definition at line 208 of file unix_console.cpp.

References Q_streq.

Referenced by Sys_ConsoleInit().

◆ Sys_ShowConsole()

void Sys_ShowConsole ( bool show)

Definition at line 169 of file unix_console.cpp.

References Sys_TTYConsoleHide(), Sys_TTYConsoleShow(), and ttyConsoleActivated.

Referenced by Sys_ConsoleInput().

◆ Sys_TTYConsoleHide()

void Sys_TTYConsoleHide ( void )
static

Clear the display of the line currently edited bring cursor back to beginning of line.

Definition at line 88 of file unix_console.cpp.

References i, Sys_TTYDeleteCharacter(), and ttyConsoleHistory.

Referenced by Sys_ShowConsole().

◆ Sys_TTYConsoleHistoryAdd()

void Sys_TTYConsoleHistoryAdd ( consoleHistory_t * field)
static

Definition at line 111 of file unix_console.cpp.

References field, histCount, histCurrent, i, lengthof, and ttyEditLines.

Referenced by Sys_ConsoleInput().

◆ Sys_TTYConsoleHistoryClear()

void Sys_TTYConsoleHistoryClear ( consoleHistory_t * edit)
static

Definition at line 203 of file unix_console.cpp.

References OBJZERO.

Referenced by Sys_ConsoleInit(), and Sys_ConsoleInput().

◆ Sys_TTYConsoleHistoryNext()

consoleHistory_t * Sys_TTYConsoleHistoryNext ( void )
static

Definition at line 145 of file unix_console.cpp.

References CON_HISTORY, histCount, histCurrent, and ttyEditLines.

Referenced by Sys_ConsoleInput().

◆ Sys_TTYConsoleHistoryPrevious()

consoleHistory_t * Sys_TTYConsoleHistoryPrevious ( void )
static

Definition at line 130 of file unix_console.cpp.

References histCount, histCurrent, lengthof, and ttyEditLines.

Referenced by Sys_ConsoleInput().

◆ Sys_TTYConsoleShow()

void Sys_TTYConsoleShow ( void )
static

Show the current line.

Todo
need to position the cursor if needed?

Definition at line 101 of file unix_console.cpp.

References i, and ttyConsoleHistory.

Referenced by Sys_ShowConsole().

◆ Sys_TTYConsoleSigCont()

void Sys_TTYConsoleSigCont ( int signum)
static

Reinitialize console input after receiving SIGCONT, as on Linux the terminal seems to lose all set attributes if user did CTRL+Z and then does fg again.

Definition at line 164 of file unix_console.cpp.

References Sys_ConsoleInit().

Referenced by Sys_ConsoleInit().

◆ Sys_TTYDeleteCharacter()

void Sys_TTYDeleteCharacter ( void )
static

Output a backspace.

Note
it seems on some terminals just sending '\b' is not enough so instead we send "\\b \\b"
Todo
there may be a way to find out if '\b' alone would work though

Definition at line 74 of file unix_console.cpp.

References key.

Referenced by Sys_ConsoleInput(), Sys_ConsoleShutdown(), and Sys_TTYConsoleHide().

Variable Documentation

◆ histCount

int histCount = 0
static

◆ histCurrent

int histCurrent = -1
static

◆ stdinActive

bool stdinActive
static

Definition at line 39 of file unix_console.cpp.

Referenced by Sys_ConsoleInit(), and Sys_ConsoleInput().

◆ TTY_eof

int TTY_eof
static

Definition at line 45 of file unix_console.cpp.

Referenced by Sys_ConsoleInit().

◆ TTY_erase

int TTY_erase
static

Definition at line 44 of file unix_console.cpp.

Referenced by Sys_ConsoleInit(), and Sys_ConsoleInput().

◆ TTY_tc

struct termios TTY_tc
static

Definition at line 47 of file unix_console.cpp.

Referenced by Sys_ConsoleInit(), and Sys_ConsoleShutdown().

◆ ttyConsoleActivated

bool ttyConsoleActivated = false
static

◆ ttyConsoleHistory

consoleHistory_t ttyConsoleHistory
static

◆ ttyEditLines