Mercurial > web-gnusto
diff trivial-zui.js @ 32:3a85b5915ea6
Added bad implementation of character input. The 'info' command in Troll no longer crashes the Z-Machine, but because we don't currently support multiple windows and the the 'info' command uses the top window as an interface, it still looks like it's hanging.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 12 May 2008 11:23:47 -0700 |
parents | 5d7bf3684fc3 |
children | 8d34fb3e9108 |
line wrap: on
line diff
--- a/trivial-zui.js Mon May 12 10:43:51 2008 -0700 +++ b/trivial-zui.js Mon May 12 11:23:47 2008 -0700 @@ -9,8 +9,36 @@ this.__proto__ = { _windowKeypress: function(event) { - if (!$("#current-input")) + 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; + } var oldInputString = self._inputString; @@ -59,6 +87,10 @@ ); }, + onCharacterInput: function(callback) { + self._currentCallback = callback; + }, + onQuit: function() { },