Skip to main content

Module ui

Module ui 

Source
Expand description

Terminal rendering primitives.

This layer turns data into lines of text and knows nothing about game state. The concrete screens (level panel, hint panel, success panel, status table, …) are built on top of it.

ModuleContents
stylethe colour palette and markdown element styles as anstyle::Style constants
textvisible width, padding, centering, verbatim word wrapping, ANSI-aware cutting
panelPanel, a rounded box with a title in the top border
markdownrender_markdown (CommonMark with paragraph reflow) and split_pages
promptwait_for_enter and confirm

Everything that produces lines takes a Term: the layout width plus a flag saying whether ANSI colour should be emitted. Renderers return Vec<String> with one entry per output line; every entry is self-contained (styles opened on a line are closed on it), so lines can be printed, indented, boxed or reordered freely. print_lines writes them through anstream, which strips colour again when the destination does not want it.

use shellgame::ui::{Panel, Term, render_markdown, style};

let term = Term::plain(40);
let panel = Panel::new(style::CYAN).title("Level 1.1");
let body = render_markdown("Přejděte do `start`.", &term.with_width(panel.body_width(&term)));
let lines = panel.render(&body, &term);
assert_eq!(lines[0], "╭───────────── Level 1.1 ──────────────╮");
assert_eq!(lines[2], "│  Přejděte do start.                  │");

Re-exports§

pub use markdown::render_markdown;
pub use markdown::split_pages;
pub use panel::Panel;
pub use prompt::PromptOutcome;
pub use prompt::confirm;
pub use prompt::enter_prompt;
pub use prompt::wait_for_enter;

Modules§

markdown
CommonMark for the terminal, built on pulldown_cmark.
panel
Rounded boxes with a centered title in the top border, like Rich’s Panel.
prompt
Interactive prompts: “press Enter to continue” and yes/no confirmation.
screens
The screens of the game: every message the player sees, as lines of text.
style
Named styles: the palette of the Python UI plus the markdown element styles.
text
Text measurement, padding and word wrapping.

Structs§

Term
What the output looks like: layout width, colour and destination.

Enums§

Stream
The standard stream a Term writes to.

Functions§

clear_screen
Clears the screen and moves the cursor to the top left corner.
print_line
Writes one line, see print_lines.
print_lines
Writes lines to the stream of term, one per line.