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.
-
At the left, the space after it.
-
In the middle, an odd space after it.
-
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.
-
None.
-
ASCII's - | +.
-
Single lines, ─ │ ┌.
-
Single lines with rounded corners, ╭.
-
Double lines, ═ ║ ╔.
-
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.
-
The lines it's drawn with.
-
How the header's cells look: bold, at first.
-
How the lines look.
-
The most columns it takes, lines and all, or 0 for as many as it needs.
-
The spaces on each side of a cell's text.
-
A table whose header row is
headers, or that has none, without any. -
How many rows it has, after its header.
-
Adds a row of
cells, from the first column. A row with fewercellsthan another has empty ones after them. -
Puts the
column's cells wherealignmentsays, the header's too. Panics for a column below 0. -
Its lines, with a line break between each two, styled as
colorsshows them, or plain for NONE. A table without a header or a row is "". -
Writes it to stdout, with a line break after, as stdout shows colors.
-
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.
-
Its text.
-
What's in its top line, or "" for nothing.
-
The lines it's drawn with.
-
How the lines look.
-
How the title looks.
-
Where the content's lines go inside it.
-
The spaces on each side of the content.
-
The columns inside its lines, padding and all, or 0 for as many as the content needs.
-
A Box of
content, withtitlein its top line. -
Its lines, with a line break between each two, styled as
colorsshows them, or plain for NONE. -
Writes it to stdout, with a line break after, as stdout shows colors.
-
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.
-
Nothing.
-
The percent done.
-
The count done, of the total.
-
The time elapsed.
-
An estimate of the time left.
-
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.
-
How many make the bar full.
-
What goes before the bar.
-
The bar's columns, which give way to the rest where the terminal's line is narrower.
-
What follows the bar.
-
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.
-
How its full and its empty columns look.
-
How its empty columns look.
-
The least time between two draws.
-
A bar of
totalon stderr, from now. -
A bar of
totalonterminal, from now. -
A bar of
totalonterminal, fromstart. -
How many are done.
-
Whether Finish has drawn it for the last time.
-
Sets how many are done, and draws it, if it's time to.
-
Sets how many are done at
now, and draws it, if it's time to. -
Adds
countto how many are done, and draws it, if it's time to. -
Adds
countto how many are done atnow, and draws it, if it's time to. -
Writes
texton a line of its own above the bar, which is drawn again below it. -
Writes
texton a line of its own above the bar atnow. -
Draws it for the last time, as it is, and ends its line.
-
Draws it for the last time at
now, and ends its line. -
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.
-
What it shows, one frame after another.
-
What goes after it.
-
How long each frame shows.
-
How its frame looks.
-
A spinner on stderr, from now.
-
A spinner on
terminal, from now. -
A spinner on
terminal, fromstart. -
Whether a Finish has written its last line.
-
Draws it again, when its frame or its message has changed since it last was.
-
Draws it again at
now, when its frame or its message has changed. -
Takes it away, and writes
texton its line, which ends. -
Finishes it with a green ✔ before
text. -
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.
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.
Report an issue with this page or with FutureBlitz on GitHub.