1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.api.Instruction;
8 public static boolean ansi_color = true;
10 public static PrintWriter log = new PrintWriter(new OutputStreamWriter(System.out));
12 public static void print(Object o) {
13 if (log==null) return;
16 } catch (Exception e) {
17 throw new RuntimeException(e);
20 public static void println() { println(""); }
21 public static void println(Object o) {
22 if (log==null) return;
26 } catch (Exception e) {
27 throw new RuntimeException(e);
31 public static void dispatch(Dispatchable d) {
32 println(green("dispatch: " + indent(d+"", " ")));
34 public static void dispatch(Instruction d) {
35 println(green("dispatch: " + indent(d+"", " ")));
38 public static void data(String data, BenkoBox source, BenkoBox dest) {
39 println((" data: ") + indent(purple(data) +
41 (" : " + source))+(" -> "+purple(""+dest)), " "));
44 public static void token(BenkoBox source, BenkoBox dest) {
45 println(purple(" token: ") + (source + " -> " + purple(dest+"")));
48 public static String clreol() { return ""; }
50 public static String black(Object o) { if (!ansi_color) return o+""; return o+""; }
51 public static String red(Object o) { if (!ansi_color) return o+""; return "\033[31m"+o+"\033[0m"; }
52 public static String green(Object o) { if (!ansi_color) return o+""; return "\033[32m"+o+"\033[0m"; }
53 public static String yellow(Object o) { if (!ansi_color) return o+""; return "\033[33m"+o+"\033[0m"; }
54 public static String blue(Object o) { if (!ansi_color) return o+""; return "\033[34m"+o+"\033[0m"; }
55 public static String purple(Object o) { if (!ansi_color) return o+""; return "\033[35m"+o+"\033[0m"; }
56 public static String cyan(Object o) { if (!ansi_color) return o+""; return "\033[36m"+o+"\033[0m"; }
57 public static String invert(Object o) { if (!ansi_color) return o+""; return "\033[7m"+o+"\033[0m"; }
58 public static String bold(Object o) { if (!ansi_color) return o+""; return "\033[1m"+o+"\033[0m"; }
60 public static void error(Object o) { println(red(o)); }
62 public static String indent(String s, String indent) {
63 StringBuffer ret = new StringBuffer();
64 for(int i=0; i<s.length(); i++) {
66 if (!(c=='\n' && i==s.length()-1))
68 if (c=='\n' && i<s.length()-1)
71 return ret.toString();