changeset 53:0abb2dbc2dd1

Renamed trivial-zui.js to web-zui.js, since it's not really trivial anymore.
author Atul Varma <varmaa@toolness.com>
date Fri, 16 May 2008 10:07:38 -0700
parents a1e72e9c4bf7
children 7dc2c7bded08
files gnusto.html trivial-zui.js web-zui.js
diffstat 3 files changed, 245 insertions(+), 245 deletions(-) [+]
line wrap: on
line diff
--- a/gnusto.html	Fri May 16 02:47:31 2008 -0700
+++ b/gnusto.html	Fri May 16 10:07:38 2008 -0700
@@ -18,5 +18,5 @@
 <script type="text/javascript" src="gnusto-engine.min.js"></script>
 <script type="text/javascript" src="engine-runner.js"></script>
 <script type="text/javascript" src="console.js"></script>
-<script type="text/javascript" src="trivial-zui.js"></script>
+<script type="text/javascript" src="web-zui.js"></script>
 </html>
--- a/trivial-zui.js	Fri May 16 02:47:31 2008 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,244 +0,0 @@
-var BACKSPACE_KEYCODE = 8;
-var RETURN_KEYCODE = 13;
-
-function TrivialZui() {
-  this._size = [80, 255];
-  this._console = null;
-  this._activeWindow = 0;
-  this._inputString = "";
-  this._currentCallback = null;
-  this._currStyles = ["z-roman"];
-  var self = this;
-
-  this.__proto__ = {
-    onConsoleRender: function() {
-      var height = $("#top-window").get(0).clientHeight;
-      $("#content").get(0).style.padding = "" + height + "px 0 0 0";
-    },
-
-    _windowKeypress: function(event) {
-      if ($("#current-input").length == 0) {
-        // We're not waiting for a line of input, but we may
-        // be waiting for a character of input.
-
-        // Note that we have to return a ZSCII keycode here.
-        //
-        // For more information, see:
-        //
-        //   http://www.gnelson.demon.co.uk/zspec/sect03.html
-        if (self._currentCallback) {
-          var keyCode = 0;
-          if (event.charCode) {
-            keyCode = event.charCode;
-          } else {
-            // TODO: Deal w/ arrow keys, etc.
-            switch (event.keyCode) {
-            case RETURN_KEYCODE:
-              keyCode = event.keyCode;
-              break;
-            }
-          }
-          if (keyCode != 0) {
-            var callback = self._currentCallback;
-
-            self._currentCallback = null;
-            callback(keyCode);
-          }
-        }
-        return false;
-      }
-
-      var oldInputString = self._inputString;
-
-      if (event.charCode) {
-        var newChar = String.fromCharCode(event.charCode);
-        var lastChar = self._inputString.slice(-1);
-        if (!(newChar == " " && lastChar == " ")) {
-          self._inputString += newChar;
-        }
-      } else {
-        switch (event.keyCode) {
-        case BACKSPACE_KEYCODE:
-          if (self._inputString) {
-            self._inputString = self._inputString.slice(0, -1);
-          }
-          break;
-        case RETURN_KEYCODE:
-          var finalInputString = self._inputString;
-          var callback = self._currentCallback;
-
-          self._inputString = "";
-          self._currentCallback = null;
-          finalInputString = finalInputString.entityify();
-          $("#current-input").replaceWith(
-            ('<span class="finished-input">' + finalInputString +
-             '</span><br/>')
-          );
-          callback(finalInputString);
-        }
-      }
-      if ($("#current-input") &&
-          oldInputString != self._inputString) {
-        $("#current-input").html(
-          self._inputString.entityify() +
-            '<span id="cursor">_</span>'
-        );
-      }
-    },
-
-    _windowResize: function() {
-      var contentLeft = $("#content").get(0).offsetLeft + "px";
-      $("#top-window").get(0).style.left = contentLeft;
-    },
-
-    _eraseBottomWindow: function() {
-      $("#content").html("");
-    },
-
-    getSize: function() {
-      return self._size;
-    },
-
-    onLineInput: function(callback) {
-      self._currentCallback = callback;
-      $("#content").append(
-        '<span id="current-input"><span id="cursor">_</span></span>'
-      );
-    },
-
-    onCharacterInput: function(callback) {
-      self._currentCallback = callback;
-    },
-
-    onQuit: function() {
-    },
-
-    onSetStyle: function(textStyle, foreground, background) {
-      switch (textStyle) {
-      case 0:
-        this._currStyles = ["z-roman"];
-        break;
-      case 1:
-        this._currStyles.push("z-reverse-video");
-        break;
-      case 2:
-        this._currStyles.push("z-bold");
-        break;
-      case 4:
-        this._currStyles.push("z-italic");
-        break;
-      case 8:
-        this._currStyles.push("z-fixed-pitch");
-        break;
-      default:
-        throw new Error("Unknown style: " + textStyle);
-      }
-    },
-
-    onSetWindow: function(window) {
-      // From the Z-Spec, section 8.7.2.
-      if (window == 1)
-        self._console.moveTo(0, 0);
-
-      self._activeWindow = window;
-    },
-
-    onEraseWindow: function(window) {
-      if (window == -2) {
-        self._console.clear();
-        self._eraseBottomWindow();
-      } else if (window == -1) {
-        // From the Z-Spec, section 8.7.3.3.
-        self.onSplitWindow(0);
-
-        // TODO: Depending on the Z-Machine version, we want
-        // to move the cursor to the bottom-left or top-left.
-        self._eraseBottomWindow();
-      } else if (window == 0) {
-        self._eraseBottomWindow();
-      } else if (window == 1) {
-        self._console.clear();
-      }
-    },
-
-    onSetCursor: function(x, y) {
-      self._console.moveTo(x - 1, y - 1);
-    },
-
-    onSetBufferMode: function(flag) {
-      // TODO: How to emulate non-word wrapping in HTML?
-    },
-
-    onSplitWindow: function(numlines) {
-      if (numlines == 0) {
-        self._console.close();
-        self._console = null;
-      } else
-        self._console = new Console(self._size[0],
-                                    numlines,
-                                    $("#top-window").get(0),
-                                    self);
-    },
-
-    onPrint: function(output) {
-      var styles = self._currStyles.join(" ");
-
-      if (self._activeWindow == 0) {
-        var lines = output.split("\n");
-        for (var i = 0; i < lines.length; i++) {
-          var addNewline = false;
-
-          if (lines[i]) {
-            var chunk = lines[i].entityify();
-            chunk = '<span class="' + styles + '">' + chunk + '</span>';
-            $("#content").append(chunk);
-            if (i < lines.length - 1)
-              addNewline = true;
-          } else
-            addNewline = true;
-
-          if (addNewline)
-            $("#content").append("<br/>");
-        }
-
-        window.scroll(0, document.body.scrollHeight);
-      } else {
-        self._console.write(output, styles);
-      }
-    }
-  };
-
-  self._windowResize();
-
-  $(window).keypress(self._windowKeypress);
-  $(window).resize(self._windowResize);
-
-  // We want to make sure that all key events don't bubble up, so
-  // that anything listening in--such as Firefox's "Search for text
-  // when I start typing" feature--doesn't think that we're not
-  // doing anything with the keypresses.  If we don't do this, such
-  // listeners may think that they can intervene and capture
-  // keystrokes before they get to us in the future.
-
-  var suppressionFunc = function(evt) { return false; };
-
-  $(window).keyup(suppressionFunc);
-  $(window).keydown(suppressionFunc);
-
-  self._eraseBottomWindow();
-}
-
-$(document).ready(function() {
-  var logfunc = undefined;
-
-  if (window.console) {
-    logfunc = function(msg) { console.log(msg); };
-  }
-
-  var engine = new GnustoEngine();
-  var zui = new TrivialZui();
-  var runner = new EngineRunner(engine, zui, logfunc);
-
-  engine.loadStory(troll_z5);
-  runner.run();
-});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web-zui.js	Fri May 16 10:07:38 2008 -0700
@@ -0,0 +1,244 @@
+var BACKSPACE_KEYCODE = 8;
+var RETURN_KEYCODE = 13;
+
+function WebZui() {
+  this._size = [80, 255];
+  this._console = null;
+  this._activeWindow = 0;
+  this._inputString = "";
+  this._currentCallback = null;
+  this._currStyles = ["z-roman"];
+  var self = this;
+
+  this.__proto__ = {
+    onConsoleRender: function() {
+      var height = $("#top-window").get(0).clientHeight;
+      $("#content").get(0).style.padding = "" + height + "px 0 0 0";
+    },
+
+    _windowKeypress: function(event) {
+      if ($("#current-input").length == 0) {
+        // We're not waiting for a line of input, but we may
+        // be waiting for a character of input.
+
+        // Note that we have to return a ZSCII keycode here.
+        //
+        // For more information, see:
+        //
+        //   http://www.gnelson.demon.co.uk/zspec/sect03.html
+        if (self._currentCallback) {
+          var keyCode = 0;
+          if (event.charCode) {
+            keyCode = event.charCode;
+          } else {
+            // TODO: Deal w/ arrow keys, etc.
+            switch (event.keyCode) {
+            case RETURN_KEYCODE:
+              keyCode = event.keyCode;
+              break;
+            }
+          }
+          if (keyCode != 0) {
+            var callback = self._currentCallback;
+
+            self._currentCallback = null;
+            callback(keyCode);
+          }
+        }
+        return false;
+      }
+
+      var oldInputString = self._inputString;
+
+      if (event.charCode) {
+        var newChar = String.fromCharCode(event.charCode);
+        var lastChar = self._inputString.slice(-1);
+        if (!(newChar == " " && lastChar == " ")) {
+          self._inputString += newChar;
+        }
+      } else {
+        switch (event.keyCode) {
+        case BACKSPACE_KEYCODE:
+          if (self._inputString) {
+            self._inputString = self._inputString.slice(0, -1);
+          }
+          break;
+        case RETURN_KEYCODE:
+          var finalInputString = self._inputString;
+          var callback = self._currentCallback;
+
+          self._inputString = "";
+          self._currentCallback = null;
+          finalInputString = finalInputString.entityify();
+          $("#current-input").replaceWith(
+            ('<span class="finished-input">' + finalInputString +
+             '</span><br/>')
+          );
+          callback(finalInputString);
+        }
+      }
+      if ($("#current-input") &&
+          oldInputString != self._inputString) {
+        $("#current-input").html(
+          self._inputString.entityify() +
+            '<span id="cursor">_</span>'
+        );
+      }
+    },
+
+    _windowResize: function() {
+      var contentLeft = $("#content").get(0).offsetLeft + "px";
+      $("#top-window").get(0).style.left = contentLeft;
+    },
+
+    _eraseBottomWindow: function() {
+      $("#content").html("");
+    },
+
+    getSize: function() {
+      return self._size;
+    },
+
+    onLineInput: function(callback) {
+      self._currentCallback = callback;
+      $("#content").append(
+        '<span id="current-input"><span id="cursor">_</span></span>'
+      );
+    },
+
+    onCharacterInput: function(callback) {
+      self._currentCallback = callback;
+    },
+
+    onQuit: function() {
+    },
+
+    onSetStyle: function(textStyle, foreground, background) {
+      switch (textStyle) {
+      case 0:
+        this._currStyles = ["z-roman"];
+        break;
+      case 1:
+        this._currStyles.push("z-reverse-video");
+        break;
+      case 2:
+        this._currStyles.push("z-bold");
+        break;
+      case 4:
+        this._currStyles.push("z-italic");
+        break;
+      case 8:
+        this._currStyles.push("z-fixed-pitch");
+        break;
+      default:
+        throw new Error("Unknown style: " + textStyle);
+      }
+    },
+
+    onSetWindow: function(window) {
+      // From the Z-Spec, section 8.7.2.
+      if (window == 1)
+        self._console.moveTo(0, 0);
+
+      self._activeWindow = window;
+    },
+
+    onEraseWindow: function(window) {
+      if (window == -2) {
+        self._console.clear();
+        self._eraseBottomWindow();
+      } else if (window == -1) {
+        // From the Z-Spec, section 8.7.3.3.
+        self.onSplitWindow(0);
+
+        // TODO: Depending on the Z-Machine version, we want
+        // to move the cursor to the bottom-left or top-left.
+        self._eraseBottomWindow();
+      } else if (window == 0) {
+        self._eraseBottomWindow();
+      } else if (window == 1) {
+        self._console.clear();
+      }
+    },
+
+    onSetCursor: function(x, y) {
+      self._console.moveTo(x - 1, y - 1);
+    },
+
+    onSetBufferMode: function(flag) {
+      // TODO: How to emulate non-word wrapping in HTML?
+    },
+
+    onSplitWindow: function(numlines) {
+      if (numlines == 0) {
+        self._console.close();
+        self._console = null;
+      } else
+        self._console = new Console(self._size[0],
+                                    numlines,
+                                    $("#top-window").get(0),
+                                    self);
+    },
+
+    onPrint: function(output) {
+      var styles = self._currStyles.join(" ");
+
+      if (self._activeWindow == 0) {
+        var lines = output.split("\n");
+        for (var i = 0; i < lines.length; i++) {
+          var addNewline = false;
+
+          if (lines[i]) {
+            var chunk = lines[i].entityify();
+            chunk = '<span class="' + styles + '">' + chunk + '</span>';
+            $("#content").append(chunk);
+            if (i < lines.length - 1)
+              addNewline = true;
+          } else
+            addNewline = true;
+
+          if (addNewline)
+            $("#content").append("<br/>");
+        }
+
+        window.scroll(0, document.body.scrollHeight);
+      } else {
+        self._console.write(output, styles);
+      }
+    }
+  };
+
+  self._windowResize();
+
+  $(window).keypress(self._windowKeypress);
+  $(window).resize(self._windowResize);
+
+  // We want to make sure that all key events don't bubble up, so
+  // that anything listening in--such as Firefox's "Search for text
+  // when I start typing" feature--doesn't think that we're not
+  // doing anything with the keypresses.  If we don't do this, such
+  // listeners may think that they can intervene and capture
+  // keystrokes before they get to us in the future.
+
+  var suppressionFunc = function(evt) { return false; };
+
+  $(window).keyup(suppressionFunc);
+  $(window).keydown(suppressionFunc);
+
+  self._eraseBottomWindow();
+}
+
+$(document).ready(function() {
+  var logfunc = undefined;
+
+  if (window.console) {
+    logfunc = function(msg) { console.log(msg); };
+  }
+
+  var engine = new GnustoEngine();
+  var zui = new WebZui();
+  var runner = new EngineRunner(engine, zui, logfunc);
+
+  engine.loadStory(troll_z5);
+  runner.run();
+});