Skip to content
FutureBlitz

    Install

    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.

    std/term/terminal.fb, line 53

    • Protected New() constructor #

      A Terminal with input of its own.

    • Public Abstract ReadOnly Property Columns: Int property #

      How many columns it has.

    • Public Abstract ReadOnly Property Rows: Int property #

      How many rows it has.

    • Public Abstract ReadOnly Property Colors: ColorLevel property #

      How many colors it shows.

    • Public Abstract ReadOnly Property IsInteractive: Bool property #

      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.

    • Public Abstract ReadOnly Property IsInputInteractive: Bool property #

      Whether keys come as they're typed, rather than from a pipe or a file, which has them a line at a time.

    • Public Abstract Method Write(text: String) method #

      Writes text as it is, escape codes and all.

    • Public Abstract Method Flush() method #

      Sends on what's been written.

    • Protected Abstract Method ReadInput(into: UInt8[], timeout: Int64): Int64 method #

      Reads what's come into the start of into, waiting for timeout nanoseconds 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.

    • Protected Abstract Method SetInputMode(mode: Int) method #

      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.

    • Protected Method ScreenChanged(enter: String, leave: String) method #

      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.

    • Public Method WriteLine(text: String = "") method #

      Writes text and a line break.

    • Public Method Write(text: String, style: Style) method #

      Writes text in style, as many colors as it shows, or alone where it shows none.

    • Public Method Paint(text: String, style: Style): String method #

      text in style, as it shows colors.

    • Public Property IsRaw: Bool property #

      Whether it's in raw mode.

    • Public Method StartRawMode(ctrlCIsKey: Bool = False, mouse: Bool = False) method #

      Starts raw mode, until a matching EndRawMode: keys come as they're typed, without showing them. Ctrl+C still ends the program, unless ctrlCIsKey says it's a key; with mouse, the mouse's reports come too, once the terminal is asked for them. Each StartRawMode needs its EndRawMode; those inside another add what they ask for.

    • @PanicsAtCaller Public Method EndRawMode() method #

      Ends a StartRawMode, and raw mode with the last of them. Panics without one.

    • Public Method ReadEvent(): InputEvent? method #

      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.

    • Public Method PollEvent(timeout: Duration): InputEvent? method #

      The next event, in raw mode for as long as it waits, which is timeout at most, or Null when none came by then, or at the end of the input.

    • Public Method ReadKey(): KeyEvent? method #

      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.

    • Public Method ReadKey(timeout: Duration): KeyEvent? method #

      The next key, which waits for timeout at most, or Null when none came by then.

    • Public Method ReadPassword(prompt: String = ""): String? method #

      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.

    • Public Static Method Console(): Terminal static method #

      The program's console: stdout, and stdin for keys. Its state is the main thread's.

    • Public Static Method Console(stream: StandardStream): Terminal static method #

      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 columns and rows that shows the colors colors says, and is interactive, as a terminal is, or not, as a pipe or a file is, for both what's written and keys.

    • Override Property Columns: Int property #

      How many columns it has.

      Doc from std.term.terminal.Terminal.Columns.

    • Override Property Rows: Int property #

      How many rows it has.

      Doc from std.term.terminal.Terminal.Rows.

    • Override Property Colors: ColorLevel property #

      How many colors it shows.

      Doc from std.term.terminal.Terminal.Colors.

    • Override Property IsInteractive: Bool property #

      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.

    • Override Property IsInputInteractive: Bool property #

      Whether keys come as they're typed, rather than from a pipe or a file, which has them a line at a time.

      Doc from std.term.terminal.Terminal.IsInputInteractive.

    • Public Property Output: String property #

      Everything written to it.

    • Public Method TakeOutput(): String method #

      What's been written since the last TakeOutput.

    • Public Property Flushes: Int property #

      How many times it's been flushed.

    • Public Property InputMode: Int property #

      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.

    • Public Property Leave: String property #

      What the console would write to put the screen back, were the program to end now.

    • Public Method Feed(text: String) method #

      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.

    • Public Method Resize(columns: Int, rows: Int) method #

      Changes its size, after what's fed before, as a resize event says.

    • Public Method Pause() method #

      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.

    • Public Method Pause(time: Duration) method #

      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.

    • Override Method Write(text: String) method #

      Writes text as it is, escape codes and all.

      Doc from std.term.terminal.Terminal.Write.

    • Override Method Flush() method #

      Sends on what's been written.

      Doc from std.term.terminal.Terminal.Flush.

    • Override Method ReadInput(into: UInt8[], timeout: Int64): Int64 method #

      Reads what's come into the start of into, waiting for timeout nanoseconds 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.

    • Override Method SetInputMode(mode: Int) method #

      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.

    • Override Method ScreenChanged(enter: String, leave: String) method #

      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.