@@ -26,6 +26,35 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
26
26
27
27
var myClassLoader : AbstractFileClassLoader = uninitialized
28
28
29
+ private def pprintRender (value : Any , width : Int , height : Int , initialOffset : Int )(using Context ): String = {
30
+ def fallback () =
31
+ dotty.shaded.pprint.PPrinter .BlackWhite .apply(
32
+ value, width = width, height = height, initialOffset = initialOffset
33
+ ).plainText
34
+ try
35
+ val cl = classLoader()
36
+ val pprintCls = Class .forName(" dotty.shaded.pprint.PPrinter$BlackWhite$" , false , cl)
37
+ val fansiStrCls = Class .forName(" dotty.shaded.fansi.Str" , false , cl)
38
+ val BlackWhite = pprintCls.getField(" MODULE$" ).get(null )
39
+ val BlackWhite_apply = pprintCls.getMethod(" apply" ,
40
+ classOf [Any ], // value
41
+ classOf [Int ], // width
42
+ classOf [Int ], // height
43
+ classOf [Int ], // indentation
44
+ classOf [Int ], // initialOffset
45
+ classOf [Boolean ], // escape Unicode
46
+ classOf [Boolean ], // show field names
47
+ )
48
+ val FansiStr_plainText = fansiStrCls.getMethod(" plainText" )
49
+ val fansiStr = BlackWhite_apply .invoke(
50
+ BlackWhite , value, width, height, 2 , initialOffset, false , true
51
+ )
52
+ FansiStr_plainText .invoke(fansiStr).asInstanceOf [String ]
53
+ catch
54
+ case _ : ClassNotFoundException => fallback()
55
+ case _ : NoSuchMethodException => fallback()
56
+ }
57
+
29
58
30
59
/** Class loader used to load compiled code */
31
60
private [repl] def classLoader ()(using Context ) =
@@ -55,7 +84,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
55
84
/** Return a String representation of a value we got from `classLoader()`. */
56
85
private [repl] def replStringOf (sym : Symbol , value : Object )(using Context ): String = {
57
86
// pretty-print things with 100 cols 50 rows by default,
58
- dotty.shaded.pprint. PPrinter . BlackWhite .apply (value, width = 100 , height = 50 ).plainText
87
+ pprintRender (value, width = 100 , height = 50 , initialOffset = 0 /* TODO: include offset */ )
59
88
}
60
89
61
90
/** Load the value of the symbol using reflection.
0 commit comments