Terminal

Encapsulates the I/O capabilities of a terminal. Warning: do not write out escape sequences to the terminal. This won't work on Windows and will confuse Terminal's internal state on Posix.

struct Terminal {
version(Windows)
CONSOLE_CURSOR_INFO originalCursorInfo;
version(Posix)
void delegate(in void[]) _writeDelegate;
static
string[string] termcapDatabase;
string[string] termcap;
uint tcaps;
version(TerminalDirectToEmulator)
TerminalEmulatorWidget tew;
version(TerminalDirectToEmulator && Posix)
ThreadID threadId;
version(TerminalDirectToEmulator && !Posix && Windows)
HANDLE threadId;
version(Win32Console)
HANDLE hConsole;
version(Win32Console)
CONSOLE_SCREEN_BUFFER_INFO originalSbi;
version(Win32Console)
UINT oldCp;
version(Win32Console)
UINT oldCpIn;
bool _suppressDestruction;
LineGetter lineGetter;
int _currentForeground;
int _currentBackground;
RGB _currentForegroundRGB;
RGB _currentBackgroundRGB;
bool reverseVideo;
bool _wrapAround;
}

Constructors

this
this()
this
this(ConsoleOutputType type)
this
this(ConsoleOutputType type, int fdIn = 0, int fdOut = 1, int[] delegate() getSizeOverride = null)

Constructs an instance of Terminal representing the capabilities of the current terminal.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Postblit

A postblit is present on this object, but not explicitly documented in the source.

Members

Functions

clear
void clear()

Clears the screen.

color
void color(int foreground, int background, ForceOption force = ForceOption.automatic, bool reverseVideo = false)

Changes the current color. See enum Color for the values.

cursor
void cursor(TerminalCursor what, ForceOption force = ForceOption.automatic)

Changes the current cursor.

cursorX
int cursorX()

The current x position of the output cursor. 0 == leftmost column

cursorY
int cursorY()

The current y position of the output cursor. 0 == topmost row

flush
void flush()

Flushes your updates to the terminal. It is important to call this when you are finished writing for now if you are using the version=with_eventloop

getline
string getline(string prompt = null)

gets a line, including user editing. Convenience method around the LineGetter class and RealTimeConsoleInput facilities - use them if you need more control. You really shouldn't call this if stdin isn't actually a user-interactive terminal! So if you expect people to pipe data to your app, check for that or use something else.

height
int height()

The current height of the terminal (the number of rows)

hideCursor
void hideCursor()

hides the cursor

hyperlink
void hyperlink(string text, ushort identifier = 0, bool autoStyle = true)

Outputs a hyperlink to my custom terminal (v0.0.7 or later) or to version TerminalDirectToEmulator. The way it works is a bit strange...

moveTo
void moveTo(int x, int y, ForceOption force = ForceOption.automatic)

Moves the output cursor to the given position. (0, 0) is the upper left corner of the screen. The force parameter can be used to force an update, even if Terminal doesn't think it is necessary

reset
void reset()

Returns the terminal to normal output colors

setTitle
void setTitle(string t)

Changes the terminal's title

setTrueColor
bool setTrueColor(RGB foreground, RGB background, ForceOption force = ForceOption.automatic)

Attempts to set color according to a 24 bit value (r, g, b, each >= 0 and < 256).

showCursor
void showCursor()

shows the cursor

underline
void underline(bool set, ForceOption force = ForceOption.automatic)

Note: the Windows console does not support underlining

width
int width()

The current width of the terminal (the number of columns)

write
void write(T t)

Writes to the terminal at the current cursor position.

writef
void writef(string f, T t)
writefln
void writefln(string f, T t)
writeln
void writeln(T t)

Writes to the terminal at the current cursor position.

Static functions

stdinIsTerminal
bool stdinIsTerminal()
stdoutIsTerminal
bool stdoutIsTerminal()

Terminal is only valid to use on an actual console device or terminal handle. You should not attempt to construct a Terminal instance if this returns false. Real time input is similarly impossible if !stdinIsTerminal.

Meta