Skip to content
FutureBlitz

    Install

    Import std.term.terminal

    FakeTerminal

    std.term.terminal

    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.

    Examples

    Local terminal = FakeTerminal(40, 10)
    terminal.WriteLine("hello")
    Expect(terminal.TakeOutput() == "hello\n")
    terminal.Feed("q")
    Expect(terminal.ReadKey()?.IsChar('q') == True)
    Expect(terminal.ReadKey() == Null)

    std/term/terminal.fb, line 402

    • 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 wide it is, as it was made or last resized.

    • Override Property Rows: Int property #

      How many rows high it is, as it was made or last resized.

    • Override Property Colors: ColorLevel property #

      The colors it shows, as it was made.

    • Override Property IsInteractive: Bool property #

      Whether it's interactive, as it was made, as a terminal is, rather than a pipe or a file.

    • Override Property IsInputInteractive: Bool property #

      Whether its input is interactive, which is as IsInteractive is.

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

      Keeps text, which Output and TakeOutput give.

    • Override Method Flush() method #

      Counts the flush, which Flushes gives.

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

      Gives what was fed next in into, and how many bytes; -1 at the end of what was fed; -2 for a Resize, once its size has changed; or after waiting through a Pause, 0 when timeout ends before it.

    • Override Method SetInputMode(mode: Int) method #

      Keeps mode, which InputMode gives.

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

      Keeps leave, what leaves the alternate screen, which Leave gives.

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