The OpenD Programming Language

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(Posix)
void delegate(in void[]) _writeDelegate;
static
string[string] termcapDatabase;
string[string] termcap;
version(Win32Console)
COORD[] cursorPositionStack;
version(TerminalDirectToEmulator)
TerminalEmulatorWidget tew;
version(TerminalDirectToEmulator && Posix)
ThreadID threadId;
version(TerminalDirectToEmulator && !Posix && Windows)
HANDLE threadId;
bool usingDirectEmulator;
version(Windows)
HANDLE hConsole;
version(Windows)
CONSOLE_SCREEN_BUFFER_INFO originalSbi;
bool _suppressDestruction;
bool _initialized;
int _currentForeground;
int _currentBackground;
RGB _currentForegroundRGB;
RGB _currentBackgroundRGB;
bool reverseVideo;
int[Grapheme] graphemeWidth;
bool willInsertFollowingLine;
bool uncertainIfAtEndOfLine;
bool _wrapAround;
}

Constructors

this
this()
this
this(ConsoleOutputType type)
this
this(ConsoleOutputType type, int fdIn, int fdOut, int[] delegate() getSizeOverride)

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

Enums

StderrBehavior
enum StderrBehavior

Options for stderrBehavior. Only applied if pipeThroughStdOut is set to true and its redirection actually is performed.

Functions

bold
void bold(bool set, ForceOption force)

Sets or resets the terminal's text rendering options.

clear
void clear()

Clears the screen.

clearToEndOfLine
void clearToEndOfLine()

Clears the current line from the cursor onwards.

color
void color(int foreground, int background, ForceOption force, bool reverseVideo)

Changes the current color. See enum Color for the values and note colors can be bitwise-or combined with Bright.

cursor
void cursor(TerminalCursor what, ForceOption force)

Changes the current cursor.

enableAlternateScreen
void enableAlternateScreen(bool active)

It is not valid to call this if you constructed with minimalProcessing.

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, dchar echoChar, string prefilledData)
string getline(string prompt, string prefilledData, dchar echoChar)

Gets a line, including user editing. Convenience method around the LineGetter class and RealTimeConsoleInput facilities - use them if you need more control.

hideCursor
void hideCursor()

hides the cursor

hyperlink
void hyperlink(string text, ushort identifier, bool autoStyle)

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

hyperlinkSupported
bool hyperlinkSupported()

Returns true if the terminal advertised compatibility with the hyperlink function's implementation.

italic
void italic(bool set, ForceOption force)

Sets or resets the terminal's text rendering options.

moveTo
void moveTo(int x, int y, ForceOption force)

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

restoreCursorPosition
bool restoreCursorPosition()

Saves/restores cursor position to a stack.

saveCursorPosition
bool saveCursorPosition()

Saves/restores cursor position to a stack.

setTitle
void setTitle(string t)

Changes the terminal's title

setTrueColor
bool setTrueColor(RGB foreground, RGB background, ForceOption force)

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)

Sets or resets the terminal's text rendering options.

updateCursorPosition
void updateCursorPosition()

Forces cursorX and cursorY to resync from the terminal.

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.

Properties

cursorX
int cursorX [@property getter]
cursorY
int cursorY [@property getter]

The current cached x and y positions of the output cursor. 0 == leftmost column for x and topmost row for y.

height
int height [@property getter]

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

width
int width [@property getter]

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

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.

Static variables

pipeThroughStdOut
shared(bool) pipeThroughStdOut;

Set this before you create any Terminals if you want it to merge the C stdout and stderr streams into the GUI terminal window. It will always redirect stdout if this is set (you may want to check for existing redirections first before setting this, see Terminal.stdoutIsTerminal), and will redirect stderr as well if it is invalid or points to the parent terminal.

stderrBehavior
shared(StderrBehavior) stderrBehavior;

If pipeThroughStdOut is set, this decides what happens to stderr. See: StderrBehavior.

terminateTimeoutMsecs
int terminateTimeoutMsecs;

When using the embedded terminal emulator build, closing the terminal signals that the main thread should exit by sending it a hang up event. If the main thread responds, no problem. But if it doesn't, it can keep a thing running in the background with no visible window. This timeout gives it a chance to exit cleanly, but if it doesn't by the end of the time, the program will be forcibly closed automatically.

Variables

lineGetter
LineGetter lineGetter;

The cached object used by getline. You can set it yourself if you like.

Meta