Skip to main content

urushi/
lib.rs

1//! Composable styling, layout, and rendering for terminal applications.
2//!
3//! `urushi` separates logical [`View`] construction, layout resolution, ANSI
4//! serialization, and output. [`resolve`] turns a view into a [`ResolvedView`]
5//! under an [`Available`] area. [`render`] then serializes that rectangle using
6//! explicit [`RenderSettings`]. [`render_text`] bypasses layout for a
7//! [`StyledText`], preserving source tabs and line boundaries. [`print()`],
8//! [`println()`], [`eprint()`], and [`eprintln()`] are the convenient text path
9//! for the process standard streams; their `*_view` peers resolve layout first.
10//!
11//! # Example
12//!
13//! ```
14//! use urushi::{Available, BlockStyle, Border, RenderSettings, TextStyle, View, render, resolve};
15//!
16//! let style = BlockStyle::new().border(Border::ROUNDED).padding((0, 1));
17//! let view = View::block(style, View::text("こんにちは, urushi!", TextStyle::new()));
18//! let resolved = resolve(&view, Available::NONE).unwrap();
19//!
20//! assert_eq!(render(&resolved, &RenderSettings::default()).lines().count(), 3);
21//! ```
22//!
23//! Width calculations are aware of East Asian wide characters. Terminal
24//! contracts and inspection live in the workspace-independent
25//! `urushi-terminal` crate; arbitrary writers combine its detection with
26//! [`resolve`], [`render`], and [`std::io::Write`].
27
28mod component;
29mod key;
30mod output;
31mod render;
32mod style;
33#[cfg(test)]
34mod test_support;
35mod text;
36mod theme;
37mod view;
38
39pub use component::{
40    List, ListEnumerator, ListItem, ListItemPresentation, ListPosition, ListPresentation,
41    Scrollbar, ScrollbarGlyphs, ScrollbarOrientation, ScrollbarPresentation, ScrollbarThumbSizing,
42    Table, TableBorder, TableCell, TablePresentation, TableRow, TableRowCells, TableRowPosition,
43    TableRowPresentation, TextTable, TextTableRow, Tree, TreeNode, TreeNodePresentation,
44    TreePosition, TreePresentation, alphabet_enumerator, arabic_enumerator, asterisk_enumerator,
45    bullet_enumerator, dash_enumerator, roman_enumerator,
46};
47pub use key::Key;
48pub use output::{
49    eprint, eprint_view, eprintln, eprintln_view, print, print_view, println, println_view,
50};
51pub use render::{RenderSettings, TerminalTextStyle, render, render_text};
52pub use style::{
53    Align, BlockStyle, Border, Color, GridStyle, Hyperlink, InvalidFillWeight, Length, Overflow,
54    Sides, TextAttribute, TextAttributes, TextStyle, Underline, UnderlineStyle, UnderlineStyleSet,
55    VerticalAlign,
56};
57pub use text::{
58    Grapheme, InvalidTabMarker, PrintableLines, PrintableText, StyledText, StyledTextError,
59    TabPolicy, TextSpan,
60};
61pub use theme::{
62    BlockThemeRole, ColorScheme, ComponentRole, ComponentTheme, ListRole, PanelRole, ScrollbarRole,
63    SemanticTokens, TableRole, TextThemeRole, Theme, ThemeMode, ThemePreset, ThemeSet, TreeRole,
64};
65pub use urushi_derive::TableRow;
66pub use urushi_terminal::{ColorLevel, TerminalBackground, TerminalCapabilities, TerminalStyle};
67pub use view::{
68    AnchoredRect, Available, Axis, BlockTitle, Canvas, CanvasCell, CanvasContext, CanvasItem,
69    CanvasSizing, CellContribution, Composition, LayoutError, LayoutErrorKind, LineContinuations,
70    LineGlyphs, LineNetwork, Position, PositionedCell, Projection, ProjectionBoundary,
71    ResolvedView, Resolver, Size, StyledGrapheme, View, Viewport, VisibleRect, measure, resolve,
72    try_measure,
73};