Import std.term.terminal
std.term.terminal
A Terminal: where line widgets and full-screen apps write, and keys come from. Terminal.Console() is the program's own console, stdout's, or stderr's with Terminal.Console(StandardStream.ERROR), and a FakeTerminal keeps what's written to it, for tests, and gives the bytes it's fed as keys, at any size and colors. A Class of a program's own can be one too, over a socket, say.
std/term/terminal.fb
Types
Terminal
class
Public Abstract Class Terminal
Where text goes, as it is, escape codes and all, and where keys come from. What's written is sent on at a Flush. Reading keys is in raw mode, where they come as they're typed, without showing them; StartRawMode keeps it on for a while, as a full-screen app does.
-
A Terminal with input of its own.
-
How many columns it has.
-
How many rows it has.
-
How many colors it shows.
-
Whether what's written goes to a terminal, where a line can be drawn again in place and the cursor moved, rather than to a pipe or a file, which only gets lines as they're done.
-
Whether keys come as they're typed, rather than from a pipe or a file, which has them a line at a time.
-
Writes
textas it is, escape codes and all. -
Sends on what's been written.
-
Reads what's come into the start of
into, waiting fortimeoutnanoseconds at most, or as long as it takes when that's negative, and gives how many bytes it read: 0 when none came in time, once the time has passed, -1 at the end of the input, and -2, before any more, once its size has changed. What a program reads goes through ReadEvent and the rest. -
Sets how input comes: 0 as it was, or else 1 for each key as it's typed, without showing it, plus 2 for Ctrl+C as a key, and 4 for the mouse's reports.
-
What changes the screen, and what puts it back, which the console writes as the program ends meanwhile, however it ends; "" and "" once it's back.
-
Writes
textand a line break. -
Writes
textinstyle, as many colors as it shows, or alone where it shows none. -
textinstyle, as it shows colors. -
Whether it's in raw mode.
-
Starts raw mode, until a matching EndRawMode: keys come as they're typed, without showing them. Ctrl+C still ends the program, unless
ctrlCIsKeysays it's a key; withmouse, themouse's reports come too, once the terminal is asked for them. Each StartRawMode needs its EndRawMode; those inside another add what they ask for. -
Ends a StartRawMode, and raw mode with the last of them. Panics without one.
-
The next event, in raw mode for as long as it waits, if it isn't already, or Null at the end of the input. A RESIZE gives the size it has now.
-
The next event, in raw mode for as long as it waits, which is
timeoutat most, or Null when none came by then, or at the end of the input. -
The next key, in raw mode for as long as it waits, if it isn't already, or Null at the end of the input. What isn't a key is skipped.
-
The next key, which waits for
timeoutat most, or Null when none came by then. -
Writes the
prompt, then reads a line in raw mode without showing it, up to ENTER, as for a password. BACKSPACE takes back the last character, and Ctrl+U the whole line, and what's pasted is typed. Null at the end of the input, or for Ctrl+D on an empty line. -
The program's console: stdout, and stdin for keys. Its state is the main thread's.
-
The console for writing to
stream, stdout or stderr, as a progress bar does so what the program prints to stdout stays as it is. Both read keys from stdin, which they share.
FakeTerminal
class
Public Class FakeTerminal Extends Terminal
A Terminal for tests: it keeps everything written to it, which Output gives, and TakeOutput what's new, and gives what it's fed as keys, as a terminal would send them, then the end of the input. It's the size, colors, and kind it's made with, until a Resize.
std/term/terminal.fb, line 368
-
Public New(columns: Int = 80, rows: Int = 24, colors: ColorLevel = ColorLevel.TRUE_COLOR, interactive: Bool = True)constructor #A terminal of
columnsandrowsthat shows the colorscolorssays, and isinteractive, as a terminal is, or not, as a pipe or a file is, for both what's written and keys. -
How many columns it has.
Doc from
std.term.terminal.Terminal.Columns. -
How many rows it has.
Doc from
std.term.terminal.Terminal.Rows. -
How many colors it shows.
Doc from
std.term.terminal.Terminal.Colors. -
Whether what's written goes to a terminal, where a line can be drawn again in place and the cursor moved, rather than to a pipe or a file, which only gets lines as they're done.
Doc from
std.term.terminal.Terminal.IsInteractive. -
Whether keys come as they're typed, rather than from a pipe or a file, which has them a line at a time.
-
Everything written to it.
-
What's been written since the last TakeOutput.
-
How many times it's been flushed.
-
The input mode it was last given: 0 for none, or 1 for raw, plus 2 for Ctrl+C as a key, and 4 for the mouse.
-
What the console would write to put the screen back, were the program to end now.
-
Takes
text's bytes as if they were typed, after what's fed before. Bytes fed one after another come as one, as a terminal's do when they're sent at once. -
Changes its size, after what's fed before, as a resize event says.
-
A pause after what's fed before, as when nothing is typed for a while: what's waiting for more, like an escape alone, is what it is, and a read that waits for a time gives nothing, as at its timeout. One that waits for as long as it takes goes on to what's after.
-
A pause of time after what's fed before: a read that waits that long or less gives nothing, as at its timeout, and leaves what's left of the pause, and one that waits longer goes on to what's after, as when the rest of a sequence or a paste comes a little late.
-
Writes
textas it is, escape codes and all.Doc from
std.term.terminal.Terminal.Write. -
Sends on what's been written.
Doc from
std.term.terminal.Terminal.Flush. -
Reads what's come into the start of
into, waiting fortimeoutnanoseconds at most, or as long as it takes when that's negative, and gives how many bytes it read: 0 when none came in time, once the time has passed, -1 at the end of the input, and -2, before any more, once its size has changed. What a program reads goes through ReadEvent and the rest.Doc from
std.term.terminal.Terminal.ReadInput. -
Sets how input comes: 0 as it was, or else 1 for each key as it's typed, without showing it, plus 2 for Ctrl+C as a key, and 4 for the mouse's reports.
Doc from
std.term.terminal.Terminal.SetInputMode. -
What changes the screen, and what puts it back, which the console writes as the program ends meanwhile, however it ends; "" and "" once it's back.
Doc from
std.term.terminal.Terminal.ScreenChanged.
Report an issue with this page or with FutureBlitz on GitHub.