pub fn print(view: impl Into<View>, options: PrintOptions) -> Result<(), Error>Expand description
Shows view as static output that stays in the scrollback.
In Tern it is a flow surface opened with listen:false, its sheet, one
frame, then x with keep. Without TSP (or when stdout isn’t a tty) it
writes the plain rendering, or fallback, to stdout.
§Errors
When I/O fails or two siblings share an id.
§Example
use tern_sdk::{PrintOptions, ui, ui::View};
let view: View = View::new().main([ui::badge("deployed").tone("success")]);
tern_sdk::print(view, PrintOptions::new())?;
tern_sdk::print(
ui::card()
.head("cargo test")
.status(ui::Status::Done)
.child(ui::md("All **42** tests pass.")),
PrintOptions::new(),
)?;Examples found in repository?
examples/table.rs (line 86)
73fn main() -> Result<(), tern_sdk::Error> {
74 let mut entries: Vec<Entry> = fs::read_dir(".")?
75 .filter_map(Result::ok)
76 .filter_map(|e| {
77 let meta = e.metadata().ok()?;
78 Some(Entry {
79 name: e.file_name().to_string_lossy().into_owned(),
80 dir: meta.is_dir(),
81 size: meta.len(),
82 })
83 })
84 .collect();
85 entries.sort_by(|a, b| b.dir.cmp(&a.dir).then_with(|| a.name.cmp(&b.name)));
86 tern_sdk::print(view(&entries), PrintOptions::new())
87}