UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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>

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. More...
 
static void Sys_TTYDeleteCharacter (void)
 Output a backspace. More...
 
static void Sys_TTYConsoleHide (void)
 Clear the display of the line currently edited bring cursor back to beginning of line. More...
 
static void Sys_TTYConsoleShow (void)
 Show the current line. More...
 
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. More...
 
void Sys_ShowConsole (bool show)
 
void Sys_ConsoleShutdown (void)
 Shutdown the console. More...
 
static void Sys_TTYConsoleHistoryClear (consoleHistory_t *edit)
 
static bool Sys_IsATTY (void)
 
void Sys_ConsoleInit (void)
 Initialize the console input (tty mode if possible) More...
 
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

#define CON_HISTORY   32

Definition at line 53 of file unix_console.cpp.

Referenced by Sys_TTYConsoleHistoryNext().

Function Documentation

static 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().

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, and ttyConsoleActivated.

Referenced by Sys_TTYConsoleSigCont().

void Sys_ConsoleOutput ( const char *  string)

Definition at line 382 of file unix_console.cpp.

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.

static bool Sys_IsATTY ( void  )
static

Definition at line 208 of file unix_console.cpp.

References Q_streq.

Referenced by Sys_ConsoleInit().

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().

static 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 consoleHistory_t::cursor, i, and Sys_TTYDeleteCharacter().

Referenced by Sys_ShowConsole().

static void Sys_TTYConsoleHistoryAdd ( consoleHistory_t field)
static

Definition at line 111 of file unix_console.cpp.

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

Referenced by Sys_ConsoleInput().

static 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().

static consoleHistory_t* Sys_TTYConsoleHistoryNext ( void  )
static

Definition at line 145 of file unix_console.cpp.

References CON_HISTORY, histCount, and histCurrent.

Referenced by Sys_ConsoleInput().

static consoleHistory_t* Sys_TTYConsoleHistoryPrevious ( void  )
static

Definition at line 130 of file unix_console.cpp.

References histCount, histCurrent, and lengthof.

Referenced by Sys_ConsoleInput().

static 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 consoleHistory_t::buffer, consoleHistory_t::cursor, and i.

Referenced by Sys_ShowConsole().

static 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().

static 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

int histCount = 0
static
int histCurrent = -1
static
bool stdinActive
static

Definition at line 39 of file unix_console.cpp.

Referenced by Sys_ConsoleInit(), and Sys_ConsoleInput().

int TTY_eof
static

Definition at line 45 of file unix_console.cpp.

Referenced by Sys_ConsoleInit().

int TTY_erase
static

Definition at line 44 of file unix_console.cpp.

Referenced by Sys_ConsoleInit(), and Sys_ConsoleInput().

struct termios TTY_tc
static

Definition at line 47 of file unix_console.cpp.

Referenced by Sys_ConsoleInit(), and Sys_ConsoleShutdown().

bool ttyConsoleActivated = false
static
consoleHistory_t ttyConsoleHistory
static

Definition at line 49 of file unix_console.cpp.

consoleHistory_t ttyEditLines[CON_HISTORY]
static

Definition at line 54 of file unix_console.cpp.