Skip to main content

print

Function print 

Source
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 93)
80fn main() -> Result<(), tern_sdk::Error> {
81	let mut entries: Vec<Entry> = fs::read_dir(".")?
82		.filter_map(Result::ok)
83		.filter_map(|e| {
84			let meta = e.metadata().ok()?;
85			Some(Entry {
86				name: e.file_name().to_string_lossy().into_owned(),
87				dir:  meta.is_dir(),
88				size: meta.len(),
89			})
90		})
91		.collect();
92	entries.sort_by(|a, b| b.dir.cmp(&a.dir).then_with(|| a.name.cmp(&b.name)));
93	tern_sdk::print(view(&entries), PrintOptions::new().css(CSS))
94}