5 releases (3 breaking)

0.4.1 Feb 5, 2019
0.4.0 Feb 5, 2019
0.3.0 Jan 16, 2019
0.2.0 Nov 30, 2018
0.1.0 Nov 29, 2018

#42 in Command-line interface

Download history 60/week @ 2018-11-28 45/week @ 2018-12-05 33/week @ 2018-12-12 35/week @ 2018-12-19 16/week @ 2018-12-26 11/week @ 2019-01-02 203/week @ 2019-01-09 318/week @ 2019-01-16 221/week @ 2019-01-23 259/week @ 2019-01-30

386 downloads per month
Used in 4 crates


1.5K SLoC


Documentation Build Status

Syntax highlighting library with batteries included.

Quick start


The above output was created with the following code:

let printer = PrettyPrinter::default()


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()

let example = r#"
def fib(n)        
    return 1 if n <= 1
    fib(n-1) + fib(n-2)
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 = "*"

But why?

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.

  • Line numbers
  • More built-in color-themes
  • Automatic pagination
  • Proper terminal handling
  • Showing non-printable characters
  • File headers
  • Windows support

prettyprint offers all of this in one crate (thanks to bat).

Known limitations

  • Doesn't run on 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.


~164K SLoC