Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Use pretty printing library such as pprint #83

Open
julien-truffaut opened this issue Dec 13, 2015 · 12 comments
Open

Use pretty printing library such as pprint #83

julien-truffaut opened this issue Dec 13, 2015 · 12 comments

Comments

@julien-truffaut
Copy link

It is sometimes difficult to read the output of the REPL, could it be possible to use something like pprint

@tpolecat
Copy link
Owner

The issue here (as discussed on gitter, repeated here for the record) is that tut just hooks into an IMain instance which just spits stuff to an output stream; we never see the results of an evaluation. So to do this we would need to use Ammonite or the script engine or something. Worth keeping in mind if we do a rewrite.

@davegurnell
Copy link
Contributor

Can it be reimplemented on top of Ammonite? That seems to pretty print values pretty well. I don't think it pretty prints types yet, but it might be a step in the right direction.

Edit: Ammonite uses a separate pretty printing library, so one wouldn't necessarily need to rely on the whole codebase. However, I tinkered with this tuff a while back and I found it easier to use Ammonite's wrapped IMain than raw IMain.

@tpolecat
Copy link
Owner

I tried Ammonite a couple times and it blew up (here and here) so I don't think it's quite ready to deal with the kinds of types that I need to support for my personal work. But this may just be a matter of contributing some fixes; I haven't looked at the implementation at all.

I also am somewhat hesitant to change the look and feel because the intent is that tut should present realistic REPL interactions. Maybe there is some kind of middle ground.

This issue is related to #33.

@davegurnell
Copy link
Contributor

Understood. As you know, @d6y, @noelwelsh and I are interested in using tut for our books at Underscore, so we're a bit of an odd customer. We'd be happy if we could write a thin wrapper around the core library, to customise the output without messing up the out-of-the-box behaviour.

Edit: Having tried to work directly with IMain, I think there's a worthwhile project simply providing a functional wrapper that gives control over input and output without having to capture stdout and so on. I haven't looked at the tut codebase in detail, but if that abstraction is there we could definitely make use of it.

@ryan-williams
Copy link
Contributor

I'm poking at letting Tut (optionally) use an ammonite repl instead of IMain; the two ammonite issues cited above seem long fixed.

Tut's interactions with IMain also seem quite minimal, so I'm hopeful this is possible / not too hard.

@ryan-williams
Copy link
Contributor

ryan-williams commented Mar 15, 2018

Turns out I was mistaken in thinking that Ammonite/PPrint would support customizable pretty-printing for various types (com-lihaoyi/PPrint#11), which somewhat saps my motivation to work on this 🙁

@tpolecat
Copy link
Owner

At the risk of sounding like a crazy person, making the compiler itself pluggable in this regard seems like a better strategy. We just need to nerdsnipe someone into figuring out how to do it.

@ryan-williams
Copy link
Contributor

That sounds good… but at the risk of sounding like a crazier person, I am going to work in parallel on a version of tut that e.g. wraps lines in println(_.show), using customizable cats.Show instances, possibly based on ammonite since it seems to offer better control over some of its output/error/result streams…

@tpolecat
Copy link
Owner

tpolecat commented Mar 15, 2018

👍 You can do better with something like trait TPrint[T] { val toString: String } and then tshow[T: TPrint: Show](t: T): String = ... which is kind of what Ammonite used to do.

@ryan-williams
Copy link
Contributor

Making sure I'm following: you've formalized customizable display of both the type and value, piggy-backing on PPrint's existing TPrint type-class for the former, and using cats.Show for the latter?

@tpolecat
Copy link
Owner

tpolecat commented Mar 15, 2018

Yeah just saying you can derive pretty-printers for types too. Whether with Ammonite/PPrint or without.

@ryan-williams
Copy link
Contributor

Taking a break from this for today; here's a branch with some minimal progress:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants