changeset 61:7714b3322ee3

WebZui now logs print opcodes.
author Atul Varma <varmaa@toolness.com>
date Fri, 16 May 2008 12:23:14 -0700
parents 8c98e4025e9e
children 3355248e2638
files web-zui.js
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/web-zui.js	Fri May 16 12:06:50 2008 -0700
+++ b/web-zui.js	Fri May 16 12:23:14 2008 -0700
@@ -1,19 +1,31 @@
 var BACKSPACE_KEYCODE = 8;
 var RETURN_KEYCODE = 13;
 
-function WebZui() {
+function WebZui(logfunc) {
   this._size = [80, 255];
   this._console = null;
   this._activeWindow = 0;
   this._inputString = "";
   this._currentCallback = null;
   this._currStyles = ["z-roman"];
+
+  if (logfunc) {
+    this._log = logfunc;
+  } else {
+    this._log = function() {};
+  }
+
   var self = this;
 
   this.__proto__ = {
     onConsoleRender: function() {
       var height = $("#top-window").get(0).clientHeight;
       $("#content").get(0).style.padding = "" + height + "px 0 0 0";
+      self._scrollBottomWindow();
+    },
+
+    _scrollBottomWindow: function() {
+      window.scroll(0, document.body.scrollHeight);
     },
 
     _finalize: function() {
@@ -235,6 +247,9 @@
     onPrint: function(output) {
       var styles = self._currStyles.join(" ");
 
+      self._log("print wind: " + self._activeWindow + " output: " +
+                output.quote() + " style: " + styles);
+
       if (self._activeWindow == 0) {
         var lines = output.split("\n");
         for (var i = 0; i < lines.length; i++) {
@@ -253,7 +268,7 @@
             $("#content").append("<br/>");
         }
 
-        window.scroll(0, document.body.scrollHeight);
+        self._scrollBottomWindow();
       } else {
         self._console.write(output, styles);
       }
@@ -273,7 +288,7 @@
   }
 
   var engine = new GnustoEngine();
-  var zui = new WebZui();
+  var zui = new WebZui(logfunc);
   var runner = new EngineRunner(engine, zui, logfunc);
 
   engine.loadStory(zcode.slice());