Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress return types in sbt console / Scala REPL

I remember there is switch somewhere to suppress the printing of return types in the Scala REPL, but I cannot find it. I am particularly interested in adding this switch to an sbt build file. Something like returnTypes in console := false.

E.g. now I have

scala> within( Span( 0, 33 ))
res7: scala.collection.immutable.IndexedSeq[(de.sciss.lucre.expr.SpanLike, scala.collection.immutable.IndexedSeq[(de.sciss.lucre.expr.Expr[de.sciss.lucre.stm.InMemory,de.sciss.lucre.expr.SpanLike], de.sciss.lucre.expr.Expr[de.sciss.lucre.stm.InMemory,Long])])] = Vector()

and for obvious reasons I want

scala> within( Span( 0, 33 ))
res7: Vector()
like image 387
0__ Avatar asked Jun 16 '12 19:06

0__


1 Answers

My question is basically mirrored by this mailing-list question. Based on Rex Kerr's idea, the following could go into build.sbt:

initialCommands in console := """// helper method to disable type printing
def shortresults[T](t: => T) = {
   val s = t.toString
   val name = s.takeWhile(_ != ':')
   val idx = s.indexOf(" = ")
   val full = if (idx >= 0) name + s.substring(idx) else s
   val short = if (full.length>799) full.substring(0,796)+"..." else full
   print(short)
   t
}
"""

But unfortunately, still the following three REPL escape commands need to be manually executed after the console is up and running:

:power
:wrap shortresults
:silent
like image 87
0__ Avatar answered Nov 08 '22 14:11

0__