@@ -30,11 +30,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
3030
3131 private var myClassLoader : AbstractFileClassLoader = _
3232
33- /** (value, maxElements) => String */
34- private var myReplStringOf : (Object , Int ) => String = _
35-
36- /** info to add if output got truncated */
37- private val infoOutputGotTruncated = " ... large output truncated, print value to show all"
33+ /** (value, maxElements, maxCharacters) => String */
34+ private var myReplStringOf : (Object , Int , Int ) => String = _
3835
3936 /** Class loader used to load compiled code */
4037 private [repl] def classLoader ()(using Context ) =
@@ -73,34 +70,37 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
7370 }
7471 }
7572
76- (value : Object , maxElements : Int ) => {
73+ (value : Object , maxElements : Int , maxCharacters : Int ) => {
7774 // `ScalaRuntime.stringOf` may truncate the output, in which case we want to indicate that fact to the user
7875 // In order to figure out if it did get truncated, we invoke it twice - once with the `maxElements` that we
7976 // want to print, and once without a limit. If the first is shorter, truncation did occur.
80- val maybeTruncated = stringOfMaybeTruncated(value, maxElements)
8177 val notTruncated = stringOfMaybeTruncated(value, Int .MaxValue )
82- if (maybeTruncated.length == notTruncated.length) maybeTruncated
83- else maybeTruncated + infoOutputGotTruncated
78+ val maybeTruncatedByElementCount = stringOfMaybeTruncated(value, maxElements)
79+ val maybeTruncated = truncate(maybeTruncatedByElementCount, maxCharacters)
80+
81+ // our string representation may have been truncated by element and/or character count
82+ // if so, append an info string - but only once
83+ if (notTruncated.length == maybeTruncated.length) maybeTruncated
84+ else s " $maybeTruncated ... large output truncated, print value to show all "
8485 }
8586
8687 }
8788 myClassLoader
8889 }
8990
90- /** Used to elide long output in replStringOf via `-Vrepl-max-print-characters` */
91- private [repl] def truncate (str : String )(using ctx : Context ): String =
92- val maxPrintCharacters = ctx.settings.VreplMaxPrintCharacters .valueIn(ctx.settingsState)
91+ private [repl] def truncate (str : String , maxPrintCharacters : Int )(using ctx : Context ): String =
9392 val ncp = str.codePointCount(0 , str.length) // to not cut inside code point
9493 if ncp <= maxPrintCharacters then str
95- else str.substring(0 , str.offsetByCodePoints(0 , maxPrintCharacters - 1 )) + infoOutputGotTruncated
94+ else str.substring(0 , str.offsetByCodePoints(0 , maxPrintCharacters - 1 ))
9695
9796 /** Return a String representation of a value we got from `classLoader()`. */
9897 private [repl] def replStringOf (value : Object )(using Context ): String =
9998 assert(myReplStringOf != null ,
10099 " replStringOf should only be called on values creating using `classLoader()`, but `classLoader()` has not been called so far" )
101100 val maxPrintElements = ctx.settings.VreplMaxPrintElements .valueIn(ctx.settingsState)
102- val res = myReplStringOf(value, maxPrintElements)
103- if res == null then " null // non-null reference has null-valued toString" else truncate(res)
101+ val maxPrintCharacters = ctx.settings.VreplMaxPrintCharacters .valueIn(ctx.settingsState)
102+ val res = myReplStringOf(value, maxPrintElements, maxPrintCharacters)
103+ if res == null then " null // non-null reference has null-valued toString" else res
104104
105105 /** Load the value of the symbol using reflection.
106106 *
0 commit comments