33import com .github .tomaslanger .chalk .Chalk ;
44import java .io .File ;
55import java .io .FileNotFoundException ;
6+ import java .io .PrintStream ;
67import java .util .ArrayList ;
78import java .util .List ;
89import java .util .Scanner ;
@@ -16,6 +17,7 @@ public class PiccodeException extends RuntimeException implements PiccodeInfo {
1617 public String file ;
1718 public int line , col ;
1819 public String message ;
20+ public PrintStream out = System .out ;
1921
2022 public Integer frame = null ;
2123
@@ -67,7 +69,7 @@ public void report(boolean die, String kind) {
6769 );
6870
6971 if (file == null ) {
70- System . out .println ("" + fmt );
72+ out .println ("" + fmt );
7173 return ;
7274 }
7375
@@ -76,19 +78,19 @@ public void report(boolean die, String kind) {
7678 index = 0 ;
7779 }
7880 var code_line = lines [index ].replaceAll ("\t " , " " .repeat (1 ));
79- System . out .println (gap2 + fmt );
80- System . out .println (line_fmt + " " + code_line );
81+ out .println (gap2 + fmt );
82+ out .println (line_fmt + " " + code_line );
8183 var tick = "─" .repeat (col + 1 ) + "╯" ;
8284 var tick2 = " " .repeat (col + 1 ) + "^" ;
83- System . out .println (gap2 + "│" + tick2 );
84- System . out .println (gap2 + "╰" + tick );
85+ out .println (gap2 + "│" + tick2 );
86+ out .println (gap2 + "╰" + tick );
8587 if (line + 1 < lines .length ) {
8688 line_fmt = String .format (" %d │" , line + 1 );
8789 System .out .println (line_fmt );
8890 }
8991
9092 if (!notes .isEmpty ()) {
91- System . out .println ((Chalk .on ("." ).yellow () + "\n " ).repeat (2 ));
93+ out .println ((Chalk .on ("." ).yellow () + "\n " ).repeat (2 ));
9294 for (var note : notes ) {
9395 note .report (false , "INFO" );
9496 }
@@ -107,7 +109,7 @@ public void report(boolean die, String kind) {
107109
108110 if (!list .isEmpty ()) {
109111 var thread = frame == null ? "" : String .format (".THREAD[%s]" , frame );
110- System . out .println ("\n [STACK TRACE]" + thread );
112+ out .println ("\n [STACK TRACE]" + thread );
111113 for (int i = 0 ; i < list .size (); i ++) {
112114 var _frame = list .get (i );
113115 var callSite = _frame .caller ;
@@ -118,7 +120,7 @@ public void report(boolean die, String kind) {
118120 ? Chalk .on (callSite .toString ()).red ()
119121 : callSite .toString ());
120122
121- System . out .println (_str );
123+ out .println (_str );
122124 }
123125 }
124126
0 commit comments