Style ordinary output
Use the core urushi crate when a command writes output and returns. This path
does not enter raw mode, read input, or start an event loop.
Write styled text directly
Section titled “Write styled text directly”StyledText preserves the source line structure and tabs. Use it when layout
does not need to add borders, padding, dimensions, or composition.
use urushi::{Color, StyledText, TextStyle};
let text = StyledText::new( "Build complete", TextStyle::new().foreground(Color::GREEN).bold(),);
urushi::println(&text)?;The result is one line. This preview preserves the color and weight selected by
the TextStyle:
Build complete
print and println target stdout. eprint and eprintln target stderr.
Write a layout-aware view
Section titled “Write a layout-aware view”Use a View when output needs wrapping, alignment, borders, spacing, or a
specific available width.
use urushi::{BlockStyle, Border, Color, TextStyle, View};
let style = BlockStyle::new() .border(Border::ROUNDED) .border_foreground(Color::BRIGHT_BLACK) .padding((0, 1));
let view = View::block( style, View::text("Build complete", TextStyle::new().bold()),);
urushi::println_view(&view)?;The same message becomes a complete terminal rectangle. The border uses the muted bright-black color and the child text remains bold:
╭────────────────╮
│ Build complete │
╰────────────────╯
The *_view functions resolve the complete view against the detected terminal
width before rendering it.
| Target | Text | View |
|---|---|---|
| stdout, no newline | print |
print_view |
| stdout, newline | println |
println_view |
| stderr, no newline | eprint |
eprint_view |
| stderr, newline | eprintln |
eprintln_view |
Keep raw ANSI out of content
Section titled “Keep raw ANSI out of content”Text passed to Urushi is plain text. Apply color, attributes, underline, and
hyperlinks through TextStyle; do not embed escape sequences in strings.
Embedded control sequences cannot participate correctly in width measurement,
wrapping, or capability degradation.
Choose text or view output
Section titled “Choose text or view output”Choose StyledText when the exact source lines should be preserved. Choose a
View when the output should adapt to an available terminal rectangle.
Next, compose blocks and layouts or read the standard-stream behavior. For every output helper, setting, and default, use the CLI reference.