Crate stijl [] [src]

Simple styled text streams.

Basic usage

stdout() and stderr() are drop-in replacements for std::io::stdout() and std::io::stderr(), which wrap them in a Stream that supports eight foreground colors and emphasized text.

Example

use std::io::Write;
use stijl::{Stream, DoStyle, Red};

let str = &mut stijl::stdout(DoStyle::Auto);
str.fg(Red);
str.em();
write!(str, "Warning: ");
str.reset();
writeln!(str, " winter is coming.");

Platform notes

stdout and stderr return a TermStream object for terminals that understand terminfo-style escape sequences, including the Cygwin and MSYS terminals, and the Windows 10 console (Anniversary Update or newer). They return a ConStream struct for consoles in earlier versions of Windows.

Multithreading

The objects returned by stdout() and stderr() implement LockableStream.

To reduce contention, multiple threads can write to their own BufStream objects and when finished, print them to a LockableStream.

Example

use stijl::{BufStream, DoStyle};

let mut buf = BufStream::new();
// ...
// Do work
// Write to buf
// ...
let stream = &mut stijl::stdout(DoStyle::Auto);
let stream = &mut stream.lock();
buf.playback(stream)?;

Structs

BufStream

A Stream that records writes and style changes.

Color

A terminal color.

Error

An error that occurred writing to a Stream.

TermStream

A styled stream using terminfo escape sequences.

Enums

DoStyle

Strategies for applying styles to standard output streams.

Constants

Black

Color 0.

Blue

Color 4 (color 1 in Windows console)

Cyan

Color 6 (color 3 in Windows console)

Green

Color 2

Magenta

Color 5

Red

Color 1 (color 4 in Windows console)

White

Color 7

Yellow

Color 3 (color 6 in Windows console)

Traits

LockableStream

A Stream with synchronized access.

Stream

An output stream with simple styling.

Functions

stderr

A LockableStream wrapping stderr.

stdout

A LockableStream wrapping stdout.

Type Definitions

Result

Either success or failure.