Skip to content

Commit dbc55de

Browse files
author
Me No Dev
committed
Output coloring
1 parent 2e23185 commit dbc55de

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

src/EspExceptionDecoder.java

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
public class EspExceptionDecoder implements Tool, DocumentListener {
4949
Editor editor;
50-
JTextArea outputArea;
50+
JLabel outputArea;
5151
JTextArea inputArea;
5252
JFrame frame;
5353
File tool;
@@ -70,8 +70,18 @@ public void run() {
7070
try {
7171
InputStreamReader reader = new InputStreamReader(p.getInputStream());
7272
int c;
73-
while ((c = reader.read()) != -1)
74-
outputArea.append(""+((char) c));
73+
String line = "";
74+
while ((c = reader.read()) != -1){
75+
if((char)c == '\r')
76+
continue;
77+
if((char)c == '\n'){
78+
printLine(line);
79+
line = "";
80+
} else {
81+
line += (char)c;
82+
}
83+
}
84+
printLine(line);
7585
reader.close();
7686

7787
reader = new InputStreamReader(p.getErrorStream());
@@ -198,16 +208,48 @@ private void createAndUpload(){
198208
inputArea.getDocument().addDocumentListener(this);
199209
frame.getContentPane().add(new JScrollPane(inputArea), BorderLayout.PAGE_START);
200210

201-
outputArea = new JTextArea(16, 60);
202-
outputArea.setLineWrap(true);
203-
outputArea.setWrapStyleWord(true);
204-
outputArea.setEditable(false);
205-
frame.getContentPane().add(new JScrollPane(outputArea), BorderLayout.CENTER);
206-
211+
outputArea = new JLabel();
212+
JScrollPane outputScrollPane = new JScrollPane(outputArea);
213+
outputScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
214+
outputScrollPane.setPreferredSize(new Dimension(640, 200));
215+
outputScrollPane.setMinimumSize(new Dimension(10, 10));
216+
frame.getContentPane().add(outputScrollPane, BorderLayout.CENTER);
217+
207218
frame.pack();
208219
frame.setVisible(true);
209220
}
210221

222+
private void printLine(String line){
223+
String address = "", method = "", file = "";
224+
if(line.startsWith("0x")){
225+
address = line.substring(0, line.indexOf(':'));
226+
line = line.substring(line.indexOf(':') + 2);
227+
} else if(line.startsWith("(inlined by)")){
228+
line = line.substring(13);
229+
address = "inlined by";
230+
}
231+
int atIndex = line.indexOf(" at ");
232+
if(atIndex == -1)
233+
return;
234+
method = line.substring(0, atIndex);
235+
line = line.substring(atIndex + 4);
236+
file = line.substring(0, line.lastIndexOf(':'));
237+
if(file.length() > 0){
238+
int lastfs = file.lastIndexOf('/');
239+
int lastbs = file.lastIndexOf('\\');
240+
int slash = (lastfs > lastbs)?lastfs:lastbs;
241+
if(slash != -1){
242+
String filename = file.substring(slash+1);
243+
file = file.substring(0,slash+1) + "<b>" + filename + "</b>";
244+
}
245+
}
246+
line = line.substring(line.lastIndexOf(':') + 1);
247+
String html = "" +
248+
"<font color=green>" + address + ": </font>" +
249+
"<b><font color=blue>" + method + "</font></b> at " + file + " line <b>" + line + "</b>";
250+
outputArea.setText(outputArea.getText() + html +"<br>");
251+
}
252+
211253
public void run() {
212254
createAndUpload();
213255
}
@@ -233,7 +275,7 @@ private void parseText(){
233275
while(m.find()) {
234276
command[i++] = content.substring(m.start(), m.end());
235277
}
236-
outputArea.setText("Decoding "+count+" results\n");
278+
outputArea.setText("<html><i>Decoding "+count+" results</i><br>");
237279
sysExec(command);
238280
}
239281

0 commit comments

Comments
 (0)