Skip to content
FutureBlitz

    Install

    Import std.term.screen

    std.term.screen

    std.term's full-screen apps: a Screen takes the whole terminal, on its alternate screen, in raw mode, with the cursor hidden, and shows a Canvas of cells there, writing only the cells that changed since it last did. A Canvas holds a grapheme cluster and a Style in each cell, two cells for a wide one, and draws text, fills, and boxes, each kept to the canvas, or to a Region of it.

    std/term/screen.fb

    Types

    Cell struct

    Public Struct Cell Implements Hashable, Printable

    One of a canvas's cells: the grapheme cluster that shows there, a space where it's blank, and how it looks. The right half of a wide one, which the cell before it shows, holds "".

    std/term/screen.fb, line 20

    • Public Field Text: String field #

      The grapheme cluster that shows there, a space where it's blank, or "" for a wide one's right half.

    • Public Field Look: Style field #

      How it looks.

    • Public Method ToString(): String method #

      Its text.

    Canvas class

    Public Class Canvas Implements Printable

    A grid of Cells, Columns by Rows, each blank at first, which a Screen shows. What's drawn on it stops at its edges, and a wide grapheme cluster that doesn't fit before an edge isn't drawn.

    std/term/screen.fb, line 33

    • @PanicsAtCaller Public New(columns: Int, rows: Int) constructor #

      A canvas of columns by rows, each cell blank. Panics for a negative size.

    • Public Property Columns: Int property #

      How many columns it has.

    • Public Property Rows: Int property #

      How many rows it has.

    • Public Property Area: Region property #

      All of it, from (0, 0).

    • @PanicsAtCaller Operator [](column: Int, row: Int): Cell operator #

      The cell at column and row. Panics outside it.

    • Public Method Clear() method #

      Makes every cell blank, as the terminal shows plain text.

    • Public Method Clear(look: Style) method #

      Makes every cell a space in look, as behind a screen's text.

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

      Makes it columns by rows, keeping the cells it still has, and blank ones past them. Panics for a negative size.

    • Public Method Print(column: Int, row: Int, text: String): Int method #

      Writes text on row from column, a grapheme cluster a cell, or two for a wide one, in plain text, as far as the canvas goes. Control characters, like tabs and line breaks, take no cell. Gives the column after what it wrote.

    • Public Method Print(column: Int, row: Int, text: String, look: Style): Int method #

      Writes text on row from column in look, as far as the canvas goes.

    • Public Method Print(area: Region, text: String, look: Style): Int method #

      Writes text in area in look, its lines wrapped to its width, as many as fit, and gives how many rows it took.

    • @PanicsAtCaller Public Method Fill(area: Region, text: String, look: Style) method #

      Fills area's cells with text, a grapheme cluster, in look: each cell, or each two for a wide one, with a space in a last column that has no room for it. Panics for text that isn't one grapheme cluster, one or two columns wide.

    • Public Method SetLook(area: Region, look: Style) method #

      Makes each of area's cells look as look says, keeping their text, as a selection does.

    • Public Method DrawBox(area: Region, border: BorderStyle, look: Style, title: String = ""): Region method #

      Draws a box around area's edge with border's lines in look, with title in its top line or not, and gives what's inside it. An area narrower or shorter than 2 has nothing inside.

    • Public Method ToString(): String method #

      Its cells' text, row by row, with a line break after each but the last, and without the spaces at each row's end.

    Screen class

    Public Class Screen

    The whole terminal, for a full-screen app: made, it changes to the terminal's alternate screen, hides the cursor, takes pasted text as a paste and the mouse's reports, if it's asked to, and starts raw mode, all of which Close puts back, as does the program's end, however it ends. Draw on its Frame, then Present shows what changed since the last Present; ReadEvent and PollEvent give keys, the mouse, pastes, and resizes, after which the next Present draws it all.

    std/term/screen.fb, line 276

    • Public New() constructor #

      The console's whole screen, with the mouse's reports, and Ctrl+C ending the program.

    • Public New(terminal: Terminal, mouse: Bool = True, ctrlCIsKey: Bool = False) constructor #

      terminal's whole screen, with the mouse's reports or not, and Ctrl+C a key with ctrlCIsKey, or ending the program without it.

    • Public Property Columns: Int property #

      How many columns it has, the terminal's.

    • Public Property Rows: Int property #

      How many rows it has, the terminal's.

    • Public Property Area: Region property #

      All of it, from (0, 0).

    • Public Property Frame: Canvas property #

      What the next Present shows, to draw on, as the last Present left it.

    • Public Property IsOpen: Bool property #

      Whether it's still the terminal's, until Close.

    • Public Method Clear() method #

      Makes its Frame blank, to draw it all again.

    • Public Method ShowCursor(column: Int, row: Int) method #

      Shows the cursor at column and row once the next Present is done, as for a text input.

    • Public Method HideCursor() method #

      Hides the cursor once the next Present is done.

    • Public Method Redraw() method #

      Has the next Present write every cell, as when something else has written on the screen.

    • @PanicsAtCaller Public Method Present(): Int method #

      Shows its Frame: writes the cells that changed since the last Present, or every cell after a resize or a Redraw, moving the cursor only to where they are, and sends them on at once. Gives how many cells it wrote. Panics once it's closed.

    • Public Method ReadEvent(): InputEvent? method #

      The next event, which waits for it, or Null at the end of the input. A RESIZE resizes its Frame, keeping what's on it, and has the next Present draw it all.

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

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

    • Public Method Run(draw: Func(Canvas), handle: Func(InputEvent): Bool) method #

      Runs an app until handle gives False or the input ends: draw draws each frame on a blank Frame, which is presented, then handle takes the next event.

    • Public Method Close() method #

      Gives the terminal back: the mouse's reports and pastes off, the cursor shown, its first screen back, and raw mode over. Once is enough, and its Destroy does it too.

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