Crates.io | clout |
lib.rs | clout |
version | 0.2.0 |
source | src |
created_at | 2019-08-12 12:26:46.151894 |
updated_at | 2020-07-18 12:23:52.417137 |
description | commandline output library |
homepage | |
repository | https://github.com/sphenlee/clout |
max_upload_size | |
id | 156119 |
size | 17,208 |
Clout is a command line output library.
It provides a similar interface to the logging crate but with a different focus:
Many libraries already output messages to the logging framework, and you generally don't want all these messages to get displayed to the end user. Clout allows you to generate output using a logging-style API without having to filter all these messages. (In fact you can use clout and logging together eg. by sending the logging messages to a file)
clout includes additional levels between Warn
and Info
. Status
is intended
for most output messages, and Success
is intended to indicate success.
Separating Info
and Status
is because typically CLI tools provide 3 levels of verbosity
(-v
, -vv
, and -vvv
is a common practice) but logging only provides two levels below info.
To use clout with the default settings:
clout::init()
.done()
.expect("clout failed to init");
This will output messages at Status
level or higher, and will
use terminal colours when available.
Macros similar to logging can be used to output messages.
Clout must be initialised before any messages are output.
Six levels are available - see the documentation for clout::Level
for
guidance about which level to use.
error!("an error");
warn!("a warining");
success!("a success");
status!("a status message");
info!("information message");
debug!("debug message");
trace!("tracing message");
If you're using the logging
crate at the same time it is suggested to use
these via a clout::
path.
The macros support the usual formatting based on the format!
macro.
status!("a formatted {}", "message");
clout::init()
.with_verbose(4)
.with_quiet(false)
.with_silent(false)
.with_use_color(clout::UseColor::Auto)
.done()
.expect("clout failed to init");
with_verbose
lets you select a verbosity level from a number. This is useful
to support -v
, -vv
etc.with_quiet
will hide everything except Error
messageswith_silent
will silence everythingwith_use_color
will control when clout uses colorsFor more details see the documentation for clout::Builder
.
Clout can be shutdown to prevent memory leaks if you care about that.
clout::shutdown().expect("failed to shutdown clout");