Skip to main content

Module document

Module document 

Source
Available on crate feature document only.
Expand description

The semantic document a command’s human output is built from.

A Document is an ordered list of Blocks: headings, paragraphs, Fields, Tables, Sections, Notices, rules, and verbatim text. Text inside a block is a Text of Spans, and each span has a Role that says what it means, not how it looks.

The types hold no borders, widths, colours, or streams. The renderer lays a document out and a Theme turns each role into a style, so one document renders the same way in every CLI. Enable the document feature to build documents without any rendering engine.

use ctl_core::document::{Document, Fields, Notice, NoticeLevel, Table};

let document = Document::new()
    .heading("Queue")
    .fields(Fields::new().row("pending", "2"))
    .table(
        Table::new(["id", "title"])
            .id_column(0)
            .row(["A-1", "Ship"]),
    )
    .notice(Notice::new(NoticeLevel::Warning, "one row is stale"));
assert_eq!(document.blocks().len(), 4);

Structs§

Document
An ordered list of blocks that make up a command’s human output.
Fields
A record: label and value rows, aligned by the renderer.
Notice
A one-line message with a level label, such as warning, and an optional code.
Rule
A horizontal rule across the width, optionally titled.
Section
A heading over a nested Document.
Span
A run of text in one Role. A Text holds spans, and a span is read through Self::role and Self::value.
Stacked
When a Table stacks its rows, and how many cells form each label.
Table
Rows of cells under an optional header row.
Text
Text made of Spans, each carrying a Role.

Enums§

Block
One block of a Document.
NoticeLevel
The severity of a Notice. It picks the label (success, warning, or error) and the style of the label.
Role
What a Span means. A Theme chooses the style that draws each role.