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.

Constructors

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

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.

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

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

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;

Meta