【问题标题】:Scala REPL truncates the outputScala REPL 截断输出
【发布时间】:2020-04-23 20:26:40
【问题描述】:

我想知道是否有任何方法可以避免 Scala REPL 通过设置环境变量或其他方式截断输出?

例子

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
...

我想查看所有内容。

提前致谢。

【问题讨论】:

    标签: scala environment-variables truncate scala-repl


    【解决方案1】:

    根据sourceretronym

      /** 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
    

    在哪里

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

    因此像这样开始 REPL

    scala -Dscala.repl.maxprintstring=0
    

    没有截断。


    针对评论,intp.isettings 似乎已在 Scala 2.13 中被 REPL: decouple the UI (shell) from the compiler [ci: last-only] #5903 删除。存在TODO 声明:

      // 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
    

    因此在 Scala 2.13 中使用 -Dscala.repl.maxprintstring 方法,但是从 REPL 内部设置应该在 2.13 之前工作

    scala> $intp.isettings.maxPrintString = 0
    

    【讨论】:

    • 感谢您的回复,所以我可以这样做 => scala> :power ,然后 => vals.isettings.maxPrintString = Int.MaxValue, vals.isettings.maxPrintString: Int = 2147483647。谢谢非常喜欢。
    【解决方案2】:

    解决方法是直接打印字符串:

    println(res6)
    

    【讨论】:

      猜你喜欢
      • 2011-05-30
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      相关资源
      最近更新 更多