11 releases (7 breaking)

0.8.1 Apr 20, 2020
0.7.1 Aug 29, 2019
0.7.0 Jun 14, 2019
0.5.0 Mar 31, 2019
0.2.0 Nov 30, 2018

#404 in Command-line interface

Download history 1/week @ 2024-01-01 38/week @ 2024-01-08 123/week @ 2024-01-15 25/week @ 2024-01-22 27/week @ 2024-01-29 29/week @ 2024-02-05 132/week @ 2024-02-12 30/week @ 2024-02-19 74/week @ 2024-02-26 68/week @ 2024-03-04 98/week @ 2024-03-11 110/week @ 2024-03-18 39/week @ 2024-03-25 138/week @ 2024-04-01 27/week @ 2024-04-08 32/week @ 2024-04-15

241 downloads per month
Used in 9 crates (6 directly)

Apache-2.0/MIT and LGPL-3.0-or-later

1.5K SLoC


Documentation CI

Syntax highlighting library with batteries included.

⚠️ 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.

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.


~360K SLoC