better colorization of interpreter logs
[fleet.git] / src / edu / berkeley / fleet / interpreter / Log.java
index a83d15c..914e524 100644 (file)
@@ -5,7 +5,6 @@ import java.io.*;
 
 public class Log {
 
-    public static boolean ansi_color = true;
     public static PrintWriter log = new PrintWriter(new OutputStreamWriter(System.out));
     public static boolean quiet = false;
 
@@ -13,9 +12,7 @@ public class Log {
         if (log==null || quiet) return;
         try {
             log.print(o);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+        } catch (Exception e) { throw new RuntimeException(e); }
     }
     public static void println() { println(""); }
     public static void println(Object o) {
@@ -23,31 +20,31 @@ public class Log {
         try {
             log.println(o);
             log.flush();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /*
-    public static void dispatch(Dispatchable d) {
-        println(ANSI.green("dispatch: " + indent(d+"", "          ")));
-    }
-    */
-    public static void dispatch(Instruction d) {
-        println(ANSI.green("dispatch: " + indent(d+"", "          ")));
-    }
-
-    public static void data(String data, Dock source, Destination dest) {
-        println(("    data: ") + indent(ANSI.purple(data) +
-                                        (source==null ? "" :
-                                         (" : " + source))+(" -> "+ANSI.purple(""+dest)), "          "));
+        } catch (Exception e) { throw new RuntimeException(e); }
     }
 
-    public static void token(Dock source, Destination dest) {
-        println(ANSI.purple("   token: ") + (source + " -> " + ANSI.purple(dest+"")));
+    public static void packet(Packet p) {
+        BitVector data = p.getValue();
+        Dock source = p.getSource();
+        Destination dest = p.getDestination();
+        if (dest.getDock().getInstructionDestination()==dest) {
+            if (p.isToken()) {
+                println(ANSI.yellow(ANSI.bold("  torpedo: ")) + (source + " -> " + ANSI.yellow(ANSI.bold(dest+""))));
+            } else {
+                Instruction d = source.getShip().getFleet().decodeInstruction(data, source);
+                println(ANSI.red("dispatch: " + indent(d+"", "          ")));
+            }
+        } else {
+            if (p.isToken()) {
+                println(ANSI.blue(ANSI.bold("   token: ")) + (source + " -> " + ANSI.blue(ANSI.bold(dest+""))));
+            } else {
+                println(indent(ANSI.cyan("    data: "+data) +
+                               (source==null ? "" :
+                                (" : " + source))+(" -> "+ANSI.cyan(""+dest)), "          "));
+            }
+        }
     }
 
-    public static String clreol() { return ""; }
     public static void error(Object o) { println(ANSI.red(o)); }
 
     public static String indent(String s, String indent) {