【问题标题】:Suppress return types in sbt console / Scala REPL抑制 sbt 控制台/Scala REPL 中的返回类型
【发布时间】:2012-06-16 19:10:40
【问题描述】:

我记得在 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()

【问题讨论】:

    标签: scala sbt read-eval-print-loop


    【解决方案1】:

    我的问题基本上反映在this mailing-list question 上。根据 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
    

    【讨论】:

      猜你喜欢
      • 2019-04-26
      • 2012-09-24
      • 2014-04-16
      • 1970-01-01
      • 2015-10-07
      • 2013-06-06
      • 1970-01-01
      • 1970-01-01
      • 2018-02-20
      相关资源
      最近更新 更多