Mercurial > web-gnusto
changeset 49:2c4d6b171f60
Text styles now display properly in the lower window (but not the upper one, yet).
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 16 May 2008 02:12:44 -0700 |
parents | f472fdcc4027 |
children | a9d7445d07d4 |
files | engine-runner.js gnusto.css trivial-zui.js |
diffstat | 3 files changed, 68 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/engine-runner.js Fri May 16 00:43:45 2008 -0700 +++ b/engine-runner.js Fri May 16 02:12:44 2008 -0700 @@ -25,6 +25,14 @@ }, onBreakpoint: function(callback) { }, + + // From the Z-Machine spec for set_text_style: Sets the text style + // to: Roman (if 0), Reverse Video (if 1), Bold (if 2), Italic (4), + // Fixed Pitch (8). In some interpreters (though this is not + // required) a combination of styles is possible (such as reverse + // video and bold). In these, changing to Roman should turn off all + // the other styles currently set. + onSetStyle: function(textStyle, foreground, background) { },
--- a/gnusto.css Fri May 16 00:43:45 2008 -0700 +++ b/gnusto.css Fri May 16 02:12:44 2008 -0700 @@ -32,3 +32,24 @@ .finished-input { color: gray; } + +.z-roman { + color: #000000; +} + +.z-reverse-video { + color: #ffffff; + background: #000000; +} + +.z-bold { + font-variant: small-caps; +} + +.z-italic { + font-style: italic; +} + +.z-fixed-pitch { + font-family: monaco; +}
--- a/trivial-zui.js Fri May 16 00:43:45 2008 -0700 +++ b/trivial-zui.js Fri May 16 02:12:44 2008 -0700 @@ -7,6 +7,7 @@ this._activeWindow = 0; this._inputString = ""; this._currentCallback = null; + this._currStyles = ["z-roman"]; var self = this; this.__proto__ = { @@ -113,6 +114,25 @@ }, 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) { @@ -162,9 +182,25 @@ onPrint: function(output) { if (self._activeWindow == 0) { - output = output.entityify(); - output = output.replace('\n', '<br/>', 'g'); - $("#content").append(output); + var styles = self._currStyles.join(" "); + + 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);