Std
Spectre
Overview
The Spectre module in std::sys provides rich terminal output: styled text, colors, tables, trees, progress bars, panels, grids, and interactive prompts. Inspired by Spectre.Console for .NET.
import std::sys;Terminal
Method
Description
Spectre.width() → i32Returns the terminal width in columns.Spectre.height() → i32Returns the terminal height in rows.Spectre.rawEnable()Enables raw terminal mode (no line buffering).Spectre.rawDisable()Restores normal terminal mode.Spectre.readKey() → i32Reads a single keypress.Text Styling
Style Constants
Style
Constant
Reset
Spectre.RESET (0)Bold
Spectre.BOLD (1)Dim
Spectre.DIM (2)Italic
Spectre.ITALIC (3)Underline
Spectre.UNDERLINE (4)Blink
Spectre.BLINK (5)Strikethrough
Spectre.STRIKETHROUGH (9)Foreground Colors
FG_BLACK (30), FG_RED (31), FG_GREEN (32), FG_YELLOW (33), FG_BLUE (34), FG_MAGENTA (35), FG_CYAN (36), FG_WHITE (37)
Background Colors
BG_BLACK (40), BG_RED (41), BG_GREEN (42), BG_YELLOW (43), BG_BLUE (44), BG_MAGENTA (45), BG_CYAN (46), BG_WHITE (47)
Methods
Spectre.styled("Hello", Spectre.BOLD); // bold text
Spectre.styled2("Error", Spectre.BOLD, Spectre.FG_RED); // bold red
Spectre.styledLn("Done", Spectre.FG_GREEN); // green + newline
Spectre.color256("text", 208); // 256-color mode
Spectre.rgb("text", 255, 128, 0); // true color RGB
Spectre.rgbBg("text", 0, 0, 128); // RGB background
Spectre.reset(); // reset all stylesMarkup
Rich text with inline tags, similar to Spectre.Console's markup syntax:
Spectre.markup("[bold]Hello[/] [red]World[/]");
Spectre.markupLine("[green]Success![/]");Widgets
SpectreTable
SpectreTable table = SpectreTable.create();
table.addHeader("Name");
table.addHeader("Score");
table.addRow();
table.addCell("Alice");
table.addCell("100");
table.addRow();
table.addCell("Bob");
table.addCell("85");
table.render();
table.destroy();SpectreTree
SpectreTree tree = SpectreTree.create();
i32 root = tree.add("Root", -1);
i32 child1 = tree.add("Child 1", root);
tree.add("Leaf", child1);
tree.add("Child 2", root);
tree.render();
tree.destroy();SpectreGrid
SpectreGrid grid = SpectreGrid.create(3); // 3 columns
grid.addRow();
grid.addCell("A");
grid.addCell("B");
grid.addCell("C");
grid.render();
grid.destroy();SpectreSpinner
SpectreSpinner spin = SpectreSpinner.create("Loading...");
for (i32 i in 0..10) {
spin.tick();
}
spin.finish("Done!");SpectreBar
SpectreBar.bar("CPU", 75, 100, 40, Spectre.FG_GREEN);
SpectreBar.chart("Resource Usage");Layout & Decoration
Spectre.rule(); // horizontal rule
Spectre.ruleTitle("Section"); // titled rule
Spectre.panel("Content here", "Title"); // bordered panel
SpectreAlign.center("Centered text");
SpectreAlign.right("Right-aligned");
SpectreAlign.repeat('-', 40);
SpectreTextPath.render("/home/user/docs/file.txt");
SpectreEmoji.printCheck("Passed");
SpectreEmoji.printCross("Failed");
SpectreEmoji.printWarning("Caution");
SpectreEmoji.printInfo("Note");Interactive Prompts
i32 choice = Spectre.prompt("Select option (1-3):");
i8* buf = i8[256];
i32 len = Spectre.promptInto("Enter name:", buf);
bool yes = Spectre.confirm("Continue?");Progress Bars
for (mut i32 i = 0; i <= 100; i = i + 1) {
Spectre.progressBar(i, 100, 50);
}
Spectre.progressFinish(50);