change benkobox=>pump
[fleet.git] / src / edu / berkeley / fleet / interpreter / Log.java
1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.sbp.util.ANSI;
3 import edu.berkeley.fleet.api.*;
4 import java.io.*;
5
6 public class Log {
7
8     public static boolean ansi_color = true;
9     public static PrintWriter log = new PrintWriter(new OutputStreamWriter(System.out));
10
11     public static void print(Object o) {
12         if (log==null) return;
13         try {
14             log.print(o);
15         } catch (Exception e) {
16             throw new RuntimeException(e);
17         }
18     }
19     public static void println() { println(""); }
20     public static void println(Object o) {
21         if (log==null) return;
22         try {
23             log.println(o);
24             log.flush();
25         } catch (Exception e) {
26             throw new RuntimeException(e);
27         }
28     }
29
30     /*
31     public static void dispatch(Dispatchable d) {
32         println(ANSI.green("dispatch: " + indent(d+"", "          ")));
33     }
34     */
35     public static void dispatch(Instruction d) {
36         println(ANSI.green("dispatch: " + indent(d+"", "          ")));
37     }
38
39     public static void data(String data, Pump source, Destination dest) {
40         println(("    data: ") + indent(ANSI.purple(data) +
41                                         (source==null ? "" :
42                                          (" : " + source))+(" -> "+ANSI.purple(""+dest)), "          "));
43     }
44
45     public static void token(Pump source, Destination dest) {
46         println(ANSI.purple("   token: ") + (source + " -> " + ANSI.purple(dest+"")));
47     }
48
49     public static String clreol() { return ""; }
50     public static void error(Object o) { println(ANSI.red(o)); }
51
52     public static String indent(String s, String indent) {
53         StringBuffer ret = new StringBuffer();
54         for(int i=0; i<s.length(); i++) {
55             char c = s.charAt(i);
56             if (!(c=='\n' && i==s.length()-1))
57                 ret.append(c);
58             if (c=='\n' && i<s.length()-1)
59                 ret.append(indent);
60         }
61         return ret.toString();
62     }
63 }