scalaenvironment-variablestruncatescala-repl

Scala REPL truncates the output


I would like to know if is there any way to avoid that Scala REPL truncates the output by setting a environment variable or whatever?

Example

scala> typeOf[Iterator[_]].members.mkString("\n")
res6: String =
override def toString(): String
def toStream: scala.collection.immutable.Stream[A]
def toIterator: Iterator[A]
def toTraversable: Traversable[A]
def sameElements: <?>
def copyToArray[B >: A](xs: Array[B],start: Int,len: Int): Unit
def patch: <?>
def duplicate: <?>
def length: <?>
def sliding$default$2: <?>
def sliding: <?>
def grouped: <?>
class GroupedIterator extends
def buffered: <?>
def indexOf: <?>
def indexOf: <?>
def indexWhere: <?>
def indexWhere: <?>
def find(p: A => Boolean): Option[A]
def contains: <?>
def exists(p: A => Boolean): Boolean
...

I would like to see all the content.

Thanks in advance.


Solution

  • According to source and retronym

      /** The maximum length of toString to use when printing the result
        *  of an evaluation.  0 means no maximum.  If a printout requires
        *  more than this number of characters, then the printout is
        *  truncated.
        */
      var maxPrintString = config.maxPrintString.option getOrElse 800
    

    where

    val maxPrintString = int("scala.repl.maxprintstring")
    

    hence start REPL like so

    scala -Dscala.repl.maxprintstring=0
    

    to have no truncation.


    Addressing the comment, intp.isettings seems to have been removed in Scala 2.13 by REPL: decouple the UI (shell) from the compiler [ci: last-only] #5903. There exists TODO which states:

      // TODO bring back access to shell features from the interpreter?
      // The repl backend has now cut its ties to the shell, except for the ReplReporter interface
      // Before, we gave the user access to: repl, reader, isettings (poor name), completion and history.
      // We could bring back some of this functionality if desired by adding it to ReplReporter
    

    hence in Scala 2.13 use -Dscala.repl.maxprintstring approach, however setting in from inside REPL should work pre-2.13

    scala> $intp.isettings.maxPrintString = 0