Commit 7877f1f
authored
Improve REPL code, echo and exception highlighting with pprint and fansi (#24298)
Before:
<img width="976" height="403" alt="Screenshot 2025-10-29 at 11 18 35 AM"
src="https://github.com/user-attachments/assets/3741b542-ad42-4bc6-af33-90bf9092bfa1"
/>
After:
<img width="932" height="343" alt="Screenshot 2025-10-29 at 11 18 36 AM"
src="https://github.com/user-attachments/assets/fa4060b1-7cde-4595-8996-bd890cf92002"
/>
Rather than just rendering everything as plaintext and coloring it
later, we:
- Preserve the colors that PPrint applies to the pretty-printed text.
- This means that for objects which are not handled via PPrint and go
via their `toString`, we do not spuriously highlight parts of them
depending on the specific hex hashcodes etc.
- This also means we can distinguish between the integer `123` and `new
Object{ override def toString = "123" }`, as the former will be colored
as a literal while the latter will be white
<img width="976" height="259" alt="Screenshot 2025-10-29 at 4 06 40 PM"
src="https://github.com/user-attachments/assets/01353d8b-6bad-459f-a59d-e25ff24d76aa"
/>
- We manually color exception stack traces using Fansi. This generally
just looks a lot better, again without random parts of it being
highlighted or not depending or whether specific regexes match class
names or file names.
- I kept it mostly red-and-white, to avoid the "rainbow" of noisy colors
that was there before and making it obviously it's a failure. The
- I kept the exception `.getMessage` in white, in case the exceptions
have their own colored messages so we don't over-write their colors
- For everything else, we continue using the prior highlighting logic
Some of the logic was refactored to pass around `fansi.Str`s rather than
`java.lang.String`s to make it easier to keep track of colors, but
otherwise I tried to minimize the churn and keep the overall code
structure unchanged.
Also tweaked some colors to improve the visual clarity of the REPL.
Changes:
- REPL prompts previously `BLUE`, now `MAGENTA`
- Types previously `MAGENTA`, now `GREEN`.
- Qualified types (e.g. `scala.Int`) are now correctly highlighted
`GREEN`
- `CYAN`, previously only used for term name bindings, is now used for
all name bindings including `object`s, `class`s, `trait`s, and `type`s
Before:
<img width="976" height="419" alt="Screenshot 2025-11-12 at 6 12 09 PM"
src="https://github.com/user-attachments/assets/a7fcc73c-95af-4479-b108-2b32b21c76e9"
/>
After:
<img width="976" height="419" alt="Screenshot 2025-11-12 at 6 22 24 PM"
src="https://github.com/user-attachments/assets/9129d571-dbb6-477f-8906-e23ad31c21af"
/>
Outcome:
- REPL prompts are now uniquely colored and easy to identify, rather
than sharing their color with comments. This is good as they are the
most important thing on screen in a REPL session, demarcating top-level
compilation units
- Now code is limited to `YELLOW`, `GREEN`, and `CYAN`. This is a more
restricted pallet than before (since they no longer use `MAGENTA`), but
is still colorful enough to make things easy to read
- The three colors have more consistent meaning despite the overlap:
- `YELLOW` is for keywords and upper-case term references
- `GREEN` is for literals and type expressions
- `CYAN` is for all name bindings, both term and type1 parent 88334c0 commit 7877f1f
File tree
11 files changed
+196
-190
lines changed- compiler
- src
- dotty/tools/dotc/printing
- scala/quoted/runtime/impl/printers
- test/dotty/tools/dotc/printing
- repl
- src/dotty/tools/repl
- test/dotty/tools/repl
11 files changed
+196
-190
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
705 | 705 | | |
706 | 706 | | |
707 | 707 | | |
708 | | - | |
| 708 | + | |
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
| |||
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
844 | | - | |
| 844 | + | |
845 | 845 | | |
846 | 846 | | |
847 | | - | |
848 | 847 | | |
849 | 848 | | |
850 | 849 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
601 | | - | |
| 601 | + | |
602 | 602 | | |
603 | 603 | | |
604 | 604 | | |
| |||
Lines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
| 31 | + | |
34 | 32 | | |
35 | 33 | | |
36 | 34 | | |
| |||
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
104 | | - | |
| 102 | + | |
105 | 103 | | |
106 | 104 | | |
107 | 105 | | |
| |||
112 | 110 | | |
113 | 111 | | |
114 | 112 | | |
115 | | - | |
116 | | - | |
| 113 | + | |
| 114 | + | |
117 | 115 | | |
118 | 116 | | |
119 | | - | |
120 | | - | |
| 117 | + | |
| 118 | + | |
121 | 119 | | |
122 | 120 | | |
| 121 | + | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
Lines changed: 48 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
| 240 | + | |
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
| 318 | + | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| |||
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
441 | | - | |
| 441 | + | |
442 | 442 | | |
443 | 443 | | |
444 | 444 | | |
| |||
764 | 764 | | |
765 | 765 | | |
766 | 766 | | |
767 | | - | |
| 767 | + | |
768 | 768 | | |
769 | | - | |
| 769 | + | |
770 | 770 | | |
771 | 771 | | |
772 | 772 | | |
| |||
873 | 873 | | |
874 | 874 | | |
875 | 875 | | |
876 | | - | |
877 | | - | |
| 876 | + | |
| 877 | + | |
878 | 878 | | |
879 | 879 | | |
880 | 880 | | |
881 | 881 | | |
882 | | - | |
| 882 | + | |
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
886 | 886 | | |
887 | | - | |
| 887 | + | |
888 | 888 | | |
889 | 889 | | |
890 | 890 | | |
891 | 891 | | |
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
895 | | - | |
| 895 | + | |
896 | 896 | | |
897 | 897 | | |
898 | 898 | | |
| |||
906 | 906 | | |
907 | 907 | | |
908 | 908 | | |
909 | | - | |
| 909 | + | |
910 | 910 | | |
911 | | - | |
| 911 | + | |
912 | 912 | | |
913 | 913 | | |
914 | 914 | | |
| |||
921 | 921 | | |
922 | 922 | | |
923 | 923 | | |
924 | | - | |
| 924 | + | |
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
| |||
972 | 972 | | |
973 | 973 | | |
974 | 974 | | |
975 | | - | |
976 | | - | |
| 975 | + | |
| 976 | + | |
977 | 977 | | |
978 | 978 | | |
979 | 979 | | |
| |||
1027 | 1027 | | |
1028 | 1028 | | |
1029 | 1029 | | |
1030 | | - | |
| 1030 | + | |
1031 | 1031 | | |
1032 | 1032 | | |
1033 | | - | |
| 1033 | + | |
1034 | 1034 | | |
1035 | 1035 | | |
1036 | 1036 | | |
| |||
1053 | 1053 | | |
1054 | 1054 | | |
1055 | 1055 | | |
1056 | | - | |
| 1056 | + | |
1057 | 1057 | | |
1058 | 1058 | | |
1059 | 1059 | | |
| |||
1066 | 1066 | | |
1067 | 1067 | | |
1068 | 1068 | | |
1069 | | - | |
| 1069 | + | |
1070 | 1070 | | |
1071 | 1071 | | |
1072 | 1072 | | |
1073 | 1073 | | |
1074 | | - | |
| 1074 | + | |
1075 | 1075 | | |
1076 | 1076 | | |
1077 | 1077 | | |
1078 | | - | |
| 1078 | + | |
1079 | 1079 | | |
1080 | 1080 | | |
1081 | 1081 | | |
| |||
1121 | 1121 | | |
1122 | 1122 | | |
1123 | 1123 | | |
1124 | | - | |
| 1124 | + | |
1125 | 1125 | | |
1126 | 1126 | | |
1127 | 1127 | | |
1128 | 1128 | | |
1129 | 1129 | | |
1130 | | - | |
| 1130 | + | |
1131 | 1131 | | |
1132 | | - | |
| 1132 | + | |
1133 | 1133 | | |
1134 | 1134 | | |
1135 | 1135 | | |
1136 | | - | |
| 1136 | + | |
1137 | 1137 | | |
1138 | 1138 | | |
1139 | 1139 | | |
1140 | | - | |
| 1140 | + | |
1141 | 1141 | | |
1142 | 1142 | | |
1143 | 1143 | | |
| |||
1175 | 1175 | | |
1176 | 1176 | | |
1177 | 1177 | | |
1178 | | - | |
| 1178 | + | |
1179 | 1179 | | |
1180 | 1180 | | |
1181 | 1181 | | |
1182 | 1182 | | |
1183 | | - | |
| 1183 | + | |
1184 | 1184 | | |
1185 | 1185 | | |
1186 | 1186 | | |
| |||
1189 | 1189 | | |
1190 | 1190 | | |
1191 | 1191 | | |
1192 | | - | |
| 1192 | + | |
1193 | 1193 | | |
1194 | 1194 | | |
1195 | 1195 | | |
1196 | 1196 | | |
1197 | 1197 | | |
1198 | 1198 | | |
1199 | | - | |
| 1199 | + | |
1200 | 1200 | | |
1201 | 1201 | | |
1202 | 1202 | | |
| |||
1207 | 1207 | | |
1208 | 1208 | | |
1209 | 1209 | | |
1210 | | - | |
| 1210 | + | |
1211 | 1211 | | |
1212 | 1212 | | |
1213 | 1213 | | |
1214 | 1214 | | |
1215 | 1215 | | |
1216 | 1216 | | |
1217 | | - | |
| 1217 | + | |
1218 | 1218 | | |
1219 | 1219 | | |
1220 | 1220 | | |
1221 | | - | |
| 1221 | + | |
1222 | 1222 | | |
1223 | 1223 | | |
1224 | 1224 | | |
| |||
1232 | 1232 | | |
1233 | 1233 | | |
1234 | 1234 | | |
1235 | | - | |
| 1235 | + | |
1236 | 1236 | | |
1237 | 1237 | | |
1238 | 1238 | | |
| |||
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1290 | 1290 | | |
1291 | 1291 | | |
1292 | 1292 | | |
| |||
1336 | 1336 | | |
1337 | 1337 | | |
1338 | 1338 | | |
1339 | | - | |
| 1339 | + | |
1340 | 1340 | | |
1341 | 1341 | | |
1342 | | - | |
| 1342 | + | |
1343 | 1343 | | |
1344 | 1344 | | |
1345 | | - | |
| 1345 | + | |
1346 | 1346 | | |
1347 | 1347 | | |
1348 | 1348 | | |
| |||
0 commit comments