抑制sbt控制台/ Scala REPL中的返回类型

6
我记得在Scala REPL中有一个开关可以抑制返回类型的打印,但我找不到它。我特别希望将此开关添加到sbt构建文件中。类似于returnTypes in console := false
例如,现在我有:
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()

出于明显的原因,我希望

scala> within( Span( 0, 33 ))
res7: Vector()
1个回答

5

我的问题与这个邮件列表中的问题基本相同。根据Rex Kerr的想法,下面的内容可以放到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
}
"""

但不幸的是,仍然需要在控制台启动后手动执行以下三个REPL转义命令:

:power
:wrap shortresults
:silent

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接