Mercurial > web-gnusto
view console.js @ 43:e45b81cdb4d0
Modified indentation to be 2 spaces instead of 4, as per Mozilla's JS style guidelines.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 15 May 2008 23:42:23 -0700 |
parents | 768813231e54 |
children | b427293b62e4 |
line wrap: on
line source
function Console(width, height, element) { this._width = width; this._height = height; this._element = element; this._pos = [0, 0]; this.clear(); } Console.prototype = { clear: function() { this._characters = []; for (var y = 0; y < this._height; y++) { var row = []; for (var x = 0; x < this._width; x++) { row.push(" "); } this._characters.push(row); } this.render(); }, moveTo: function(x, y) { this._pos = [x, y]; }, write: function(string) { var x = this._pos[0]; var y = this._pos[1]; for (var i = 0; i < string.length; i++) { var character = null; if (string[i] == " ") character = " "; else if (string[i] == "\n") { x = 0; y += 1; } else character = string[i].entityify(); if (character != null) { this._characters[y][x] = character; x += 1; } } this._pos = [x, y]; this.render(); }, render: function() { var string = ""; for (var y = 0; y < this._height; y++) { for (var x = 0; x < this._width; x++) { string += this._characters[y][x]; } string += "<br/>"; } this._element.innerHTML = string; }, close: function() { this._element.innerHTML = ""; } } var con = null; function testConsole(element) { console.log("creating"); con = new Console(60, 3, element); console.log("writing"); con.write("blargy blarg"); console.log("rendering"); con.render(); }