Skip to content
FutureBlitz

    Install

    Import std.term.widgets

    std.term.widgets

    std.term's line widgets: a Table and a Box, which give their text, and a ProgressBar and a Spinner, which draw themselves on a terminal's line again as they go, where it's interactive, and once they're done where it isn't, as for a pipe or a file. Each draws to the console, the bars to stderr, or to a Terminal given, and goes by the colors it shows. Widths are in a terminal's columns, as VisibleWidth counts them.

    std/term/widgets.fb

    Types

    Alignment enum

    Public Enum Alignment

    Where text goes in a width wider than it.

    std/term/widgets.fb, line 23

    • LEFT enum member #

      At the left, the space after it.

    • CENTER enum member #

      In the middle, an odd space after it.

    • RIGHT enum member #

      At the right, the space before it.

    BorderStyle enum

    Public Enum BorderStyle

    The lines a Table, a Box, or a Canvas's box is drawn with.

    std/term/widgets.fb, line 33

    • NONE enum member #

      None.

    • ASCII enum member #

      ASCII's - | +.

    • SINGLE enum member #

      Single lines, ─ │ ┌.

    • ROUNDED enum member #

      Single lines with rounded corners, ╭.

    • DOUBLE enum member #

      Double lines, ═ ║ ╔.

    • HEAVY enum member #

      Heavy lines, ━ ┃ ┏.

    Table class

    Public Class Table

    A table of text, with a header row or not, its columns as wide as their widest cell, which Render draws with a BorderStyle's lines. A cell can have several lines, and each column its own Alignment. With a MaxWidth, the widest columns give way first, down to their widest character, and their cells wrap.

    std/term/widgets.fb, line 117

    • Public Field Border: BorderStyle field #

      The lines it's drawn with.

    • Public Field HeaderStyle: Style field #

      How the header's cells look: bold, at first.

    • Public Field BorderColor: Style field #

      How the lines look.

    • Public Field MaxWidth: Int field #

      The most columns it takes, lines and all, or 0 for as many as it needs.

    • Public Field Padding: Int field #

      The spaces on each side of a cell's text.

    • Public New(headers: String...) constructor #

      A table whose header row is headers, or that has none, without any.

    • Public Property RowCount: Int property #

      How many rows it has, after its header.

    • Public Method AddRow(cells: String...) method #

      Adds a row of cells, from the first column. A row with fewer cells than another has empty ones after them.

    • @PanicsAtCaller Public Method Align(column: Int, alignment: Alignment) method #

      Puts the column's cells where alignment says, the header's too. Panics for a column below 0.

    • Public Method Render(colors: ColorLevel = ColorLevel.NONE): String method #

      Its lines, with a line break between each two, styled as colors shows them, or plain for NONE. A table without a header or a row is "".

    • Public Method Print() method #

      Writes it to stdout, with a line break after, as stdout shows colors.

    • Public Method Draw(terminal: Terminal) method #

      Writes it to terminal, with a line break after, as it shows colors.

    Box class

    Public Class Box

    Text in a box, with a Title in its top line or not, which Render draws with a BorderStyle's lines. It's as wide as its widest line, or Width wide inside its lines, where the lines wider than that wrap.

    std/term/widgets.fb, line 317

    • Public Field Content: String field #

      Its text.

    • Public Field Title: String field #

      What's in its top line, or "" for nothing.

    • Public Field Border: BorderStyle field #

      The lines it's drawn with.

    • Public Field BorderColor: Style field #

      How the lines look.

    • Public Field TitleStyle: Style field #

      How the title looks.

    • Public Field Align: Alignment field #

      Where the content's lines go inside it.

    • Public Field Padding: Int field #

      The spaces on each side of the content.

    • Public Field Width: Int field #

      The columns inside its lines, padding and all, or 0 for as many as the content needs.

    • Public New(content: String, title: String = "") constructor #

      A Box of content, with title in its top line.

    • Public Method Render(colors: ColorLevel = ColorLevel.NONE): String method #

      Its lines, with a line break between each two, styled as colors shows them, or plain for NONE.

    • Public Method Print() method #

      Writes it to stdout, with a line break after, as stdout shows colors.

    • Public Method Draw(terminal: Terminal) method #

      Writes it to terminal, with a line break after, as it shows colors.

    ProgressParts enum

    @Flags Public Enum ProgressParts

    What a ProgressBar shows after its bar.

    std/term/widgets.fb, line 411

    • NONE = 0 enum member #

      Nothing.

    • PERCENT enum member #

      The percent done.

    • COUNT enum member #

      The count done, of the total.

    • ELAPSED enum member #

      The time elapsed.

    • ETA enum member #

      An estimate of the time left.

    • RATE enum member #

      The rate, how many a second.

    ProgressBar class

    Public Class ProgressBar

    A bar of how much of a Total is done, on a line of its own, with a Label before it and its Parts after it, which it draws again in place as its Value changes, no more often than Interval but at its start and its end, on an interactive terminal; on another, it's drawn once, at its Finish. It goes to stderr, or to a Terminal given. What reads the clock also takes an Instant, so a test gives the time.

    std/term/widgets.fb, line 432

    • Public Field Total: Int64 field #

      How many make the bar full.

    • Public Field Label: String field #

      What goes before the bar.

    • Public Field Width: Int field #

      The bar's columns, which give way to the rest where the terminal's line is narrower.

    • Public Field Parts: ProgressParts field #

      What follows the bar.

    • Public Field Characters: String field #

      The bar's characters: a full column first, an empty one last, and any between, for a column that's partly full, from the fullest down, as "█▉▊▋▌▍▎▏ " or "#>-" has them.

    • Public Field FilledStyle: Style field #

      How its full and its empty columns look.

    • Public Field EmptyStyle: Style field #

      How its empty columns look.

    • Public Field Interval: Duration field #

      The least time between two draws.

    • Public New(total: Int64) constructor #

      A bar of total on stderr, from now.

    • Public New(total: Int64, terminal: Terminal) constructor #

      A bar of total on terminal, from now.

    • Public New(total: Int64, terminal: Terminal, start: Instant) constructor #

      A bar of total on terminal, from start.

    • Public Property Value: Int64 property #

      How many are done.

    • Public Property IsFinished: Bool property #

      Whether Finish has drawn it for the last time.

    • Public Method Set(value: Int64) method #

      Sets how many are done, and draws it, if it's time to.

    • Public Method Set(value: Int64, now: Instant) method #

      Sets how many are done at now, and draws it, if it's time to.

    • Public Method Add(count: Int64 = 1) method #

      Adds count to how many are done, and draws it, if it's time to.

    • Public Method Add(count: Int64, now: Instant) method #

      Adds count to how many are done at now, and draws it, if it's time to.

    • Public Method PrintAbove(text: String) method #

      Writes text on a line of its own above the bar, which is drawn again below it.

    • Public Method PrintAbove(text: String, now: Instant) method #

      Writes text on a line of its own above the bar at now.

    • Public Method Finish() method #

      Draws it for the last time, as it is, and ends its line.

    • Public Method Finish(now: Instant) method #

      Draws it for the last time at now, and ends its line.

    • Public Method Render(now: Instant): String method #

      The line it draws at now, as its terminal shows colors, in its columns.

    Spinner class

    Public Class Spinner

    A spinner, on a line of its own, whose frame turns each Interval, with its Message after it, for work whose end isn't known. Tick draws it again when its frame or message has changed, on an interactive terminal; on another, only its Finish's line is written. It goes to stderr, or to a Terminal given. What reads the clock also takes an Instant, so a test gives the time.

    std/term/widgets.fb, line 642

    • Public Field Frames: String[] field #

      What it shows, one frame after another.

    • Public Field Message: String field #

      What goes after it.

    • Public Field Interval: Duration field #

      How long each frame shows.

    • Public Field FrameStyle: Style field #

      How its frame looks.

    • Public New(message: String) constructor #

      A spinner on stderr, from now.

    • Public New(message: String, terminal: Terminal) constructor #

      A spinner on terminal, from now.

    • Public New(message: String, terminal: Terminal, start: Instant) constructor #

      A spinner on terminal, from start.

    • Public Property IsFinished: Bool property #

      Whether a Finish has written its last line.

    • Public Method Tick() method #

      Draws it again, when its frame or its message has changed since it last was.

    • Public Method Tick(now: Instant) method #

      Draws it again at now, when its frame or its message has changed.

    • Public Method Finish(text: String) method #

      Takes it away, and writes text on its line, which ends.

    • Public Method Succeed(text: String) method #

      Finishes it with a green ✔ before text.

    • Public Method Fail(text: String) method #

      Finishes it with a red ✖ before text.

    Functions

    Aligned function

    Public Function Aligned(text: String, width: Int, alignment: Alignment): String

    text in width columns: padded with spaces as alignment says, or as it is when it's as wide or wider.

    std/term/widgets.fb, line 83

    Truncated function

    Public Function Truncated(text: String, width: Int): String

    text cut to width columns, with "…" for what's cut, between grapheme clusters, or as it is when it fits. It has no escape codes, which this would cut too.

    std/term/widgets.fb, line 98

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