Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Li Haoyi
    @lihaoyi
    go tell your friends :)
    or chip in a bit of support https://www.patreon.com/lihaoyi
    Alan Johnson
    @acjay
    will do!
    good news: an 0.4.3 issue i had reported a couple days ago is fixed. the upgrade was worth it
    lihaoyi/upickle-pprint#204
    Srepfler Srdan
    @schrepfler
    is there any way we could get pretty printing of case classes where we see things more like a key:value (or key=value) pair?
    Guillaume Massé
    @MasseGuillaume
    Not yet. Put there is a pr in Scala 2.13 that will allow this built in.
    Srepfler Srdan
    @schrepfler
    Sweet, I think I saw some comment about that
    Wojtek Pituła
    @Krever
    Hey, is there an easy way to have field names when printing case classes?
    Srepfler Srdan
    @schrepfler
    that would be awesome, splunk for example indexes very easily stuff which are printed with the key=value convention
    I think there’s a logging style which recomends this more than logging to json as some people are advocating for structured logging but I can’t find a reference
    http://dev.splunk.com/view/logging/SP-CAAAFCK
    https://brandur.org/logfmt
    at=info method=GET path=/ host=mutelight.org fwd="124.133.52.161"
      dyno=web.2 connect=4ms service=8ms status=200 bytes=1653
    it would be really awesome to have something like that automatically pretty print case classes
    Srepfler Srdan
    @schrepfler
    let's see what this Scala 2.13 brings on the table
    Li Haoyi
    @lihaoyi
    if you want json logging, use upickle
    can do binary msgpack logging as well :)
    Srepfler Srdan
    @schrepfler
    lol
    let’s write direct to parquet then
    :D
    Li Haoyi
    @lihaoyi
    sure why not
    or Arrow
    just need to write a upickle visitor
    Srepfler Srdan
    @schrepfler
    that would be interesting, use big data tools to analyse logs directly
    and it would cost you less if you ship them around both in disk and network
    though I suppose everybody gzips the text anyhow
    Frank P. Tominc
    @franktominc
    I'm having a problem somewhere in the toolchain, not sure where. If I add only the pprint dependency I got some NoClassDef exceptions saying it couldn't find scala-reflect. Not really hard to fix, but it's annoying. Is there a way to make it a transitive dependency, so I don't need to add it manually on the build.sbt?
    Mark Moore
    @MarkRBM
    would we expect pprint to cut off output and add an ellipsis when being used with ammonite in a .sc file ?
    I don’t think its my shell truncating the output, if its pprint, is there a way for me to turn off truncation?
    sorry I see in the docs now that truncation is talked about a good bit, trying to find how to turn it off
    Li Haoyi
    @lihaoyi
    height = 99999
    Dermot Haughey
    @hderms
    curious if it would make sense to be able to turn that off wholesale or if there is some technical reason it's difficult
    I was just about to come in here to ask the same question as @MarkRBM
    Li Haoyi
    @lihaoyi
    no reason
    feel free to send a PR to make -1 disable truncation
    Dermot Haughey
    @hderms
    cool i'll look into doing it
    Anton Sviridov
    @keynmol

    Boy this room doesn't get much action :D

    I'm doing something for mdoc and playing with width and height values gives me surprising results:

    @ import $ivy.`com.lihaoyi::pprint:0.5.4`
    import $ivy.$
    
    @ val x = List.fill(15)("helloasdasdasdasdasdasdasdasd!")
    x: List[String] = List(
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
    ...
    
    @ pprint.PPrinter.BlackWhite.tokenize(x, height=5, width=10, initialOffset=0).foreach(print)
    List(
      "helloasdasdasdasdasdasdasda...
    
    @ pprint.PPrinter.BlackWhite.tokenize(x, height=2, width=10, initialOffset=0).foreach(print)
    List(
    ...
    
    @ pprint.PPrinter.BlackWhite.tokenize(x, height=8, width=10, initialOffset=0).foreach(print)
    List(
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasd...

    Are those values expressed in characters or tokens? and if it's tokens - how is height interpreted?

    Li Haoyi
    @lihaoyi
    width and height are meant to be in characters; can you try using 0.6.0? i fixed some bugs in the latest version
    initialOffset is meant to be any characters to the left of the first line of the thing you're printing, so it can wrap to the next line early if necessary
    Anton Sviridov
    @keynmol
    let me try 0.6.0
    I'm getting the same result:
    ➜  pprint git:(master) amm
    Loading...
    Welcome to the Ammonite Repl 2.2.0-4-4bd225e (Scala 2.13.3 Java 1.8.0_252)
    @ import $ivy.`com.lihaoyi::pprint:0.6.0`
    import $ivy.$
    
    @ val x = List.fill(15)("helloasdasdasdasdasdasdasdasd!")
    x: List[String] = List(
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasdasdasdasdasd!",
    ...
    
    @ pprint.PPrinter.BlackWhite.tokenize(x, height=5, width=10, initialOffset=0).foreach(print)
    List(
      "helloasdasdasdasdasdasdasda...
    
    @ pprint.PPrinter.BlackWhite.tokenize(x, height=2, width=10, initialOffset=0).foreach(print)
    List(
    ...
    
    @ pprint.PPrinter.BlackWhite.tokenize(x, height=8, width=10, initialOffset=0).foreach(print)
    List(
      "helloasdasdasdasdasdasdasdasd!",
      "helloasdasdasdasd...

    I'm also looking at one of the tests (I might be reading it wrong, I've only now imported pprint)

            test{
              val Check = new Check(width = 60, height = 5)
              Check(
                "a" * 1000,
                "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "..."
              )
            }

    It seems like it expects the width to be 60, but it checks that the string is truncated to roughly ~480 characters?

    Li Haoyi
    @lihaoyi
    the height takes into account terminal wrapping, in addition to any newlines that may be present in the output

    so if you lay out the string

    "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
                 "..."

    And wrap it every 60 characters, it gets truncated with ... when consuming a total of 5 vertical lines of space

    Li Haoyi
    @lihaoyi
    pprint doesn't actually do the wrapping of long strings, but assumes the terminal will wrap them at the specified width and truncates them accordingly to fit within the specified height
    Anton Sviridov
    @keynmol

    I see, and from the examples above does the height truncation look right to you?

    And with regards to width - if pprint is being run outside of a terminal (i.e. in mdoc it's used for markdown generation), it would default to the values it has, right? I guess pprint actually doesn't interact with terminal directly

    Anton Sviridov
    @keynmol
    Definitely some interesting interplay between width and height:
    ➜  pprint git:(master) ✗ cat test.sc
    import $ivy.`com.lihaoyi::pprint:0.6.0`
    
    val x = List.fill(sys.env("LIST_LENGTH").toInt)("a")
    
    pprint.PPrinter.BlackWhite
            .tokenize(x,
                      height=sys.env("HEIGHT").toInt,
                      width=sys.env("WIDTH").toInt,
                      initialOffset=0)
            .foreach(print)
    ➜  pprint git:(master) ✗ LIST_LENGTH=30 HEIGHT=15 WIDTH=2 amm test.sc
    List(
      "a",
      "a",
      "a",
      "a"...#
    ➜  pprint git:(master) ✗ LIST_LENGTH=30 HEIGHT=15 WIDTH=10 amm test.sc
    List(
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
      "a",
    .
    Li Haoyi
    @lihaoyi
    yeah the examples all look right
    if you manually line wrap them at width, it should be height lines tall (including the ...)
    if you’re not in a terminal, you may have to postprocess the output to wrap things yourself
    vito-c
    @vito-c
    Anyone know how to define a pprint.Config object so that you can change the width for your project ?