Crates.io | prettyprint |
lib.rs | prettyprint |
version | 0.8.1 |
source | src |
created_at | 2018-11-29 22:27:41.653322 |
updated_at | 2020-04-20 09:12:40.974055 |
description | Print beautifully formatted files and strings to your terminal |
homepage | https://github.com/mre/prettyprint |
repository | https://github.com/mre/prettyprint |
max_upload_size | |
id | 99283 |
size | 1,410,034 |
Syntax highlighting library with batteries included.
:warning: For new projects, you might want to use
bat
instead, which can be used as a library now.prettyprint
is in maintenance mode now, which means it will not see any major updates anymore, but pull requests will still be reviewed and dependencies will be kept up-to-date for the time being. You might want consider migrating away, though.
The above output was created with the following code:
let printer = PrettyPrinter::default()
.language("rust")
.build()?;
printer.file("fixtures/fib.rs")?;
Note that prettyprint
is a builder and can be customized. For example, if you don't like the grid or the header, you can disable those:
let printer = PrettyPrinter::default()
.header(false)
.grid(false)
.language("ruby")
.build()?;
let example = r#"
def fib(n)
return 1 if n <= 1
fib(n-1) + fib(n-2)
end
"#;
printer.string_with_header(example, "fib.rb")?;
"What!? It can also print strings, Matthias? That's insane."
It's true. You're welcome.
Add this to your Cargo.toml
:
prettyprint = "*"
syntect
is a great package for highlighting text.
When writing a command-line tool that prints text however, you might be looking for some additional functionality.
prettyprint
offers all of this in one crate (thanks to bat).
no-std
targets. I don't plan to support those.prettyprint
is simply a fork of bat
, with some functionality stripped out and bundled up as a library.
I built it, because I needed it for cargo-inspect.
All credits go to the original authors.