Skip to content
FutureBlitz

    Install

    Import std.term.terminal

    Terminal

    std.term.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.

    Examples

    Function Greet(terminal: Terminal)
        terminal.WriteLine("hello, {terminal.Columns} columns")
    End Function
    
    Local fake = FakeTerminal(40, 10)
    Greet(fake)
    Expect(fake.Output == "hello, 40 columns\n")

    std/term/terminal.fb, line 68

    • 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.

    Report an issue with this page or with FutureBlitz on GitHub.