Richard said:
I'm not sure what the difference is, but this cut-down version actually
works properly in regards to the Console.STDIN and Console.STDOUT
properties. There must be something else in the Atomic OS sourcecode
that's causing the problems.
Anyway, here's a sample of how the Console object is to be used...
[-- code starts --]
<html>
<head>
<title>jsConsole II</title>
<script language="JavaScript">
// CONSOLE.JS
Console = new Object();
Console.scrolldelta = 0;
Console.init = function () {
this.STDIN = document.getElementById('console0_stdin');
this.STDOUT = document.getElementById('console0_stdout');
this.PROMPT = document.getElementById('console0_prompt');
// Make console a positional element
document.getElementById('console0').style.position = 'absolute';
// Resize console elements
this.STDOUT.style.width = (SCREEN_WIDTH-20)+'px';
this.STDOUT.style.height = (SCREEN_HEIGHT-100)+'px';
this.PROMPT.style.width = (SCREEN_WIDTH-20)+'px';
this.STDIN.style.width = (SCREEN_WIDTH-20)+'px';
// Make stdout read-only
this.STDOUT.disabled = true;
this.STDOUT.style.backgroundColor = '#ddd';
this.STDOUT.style.color = '#000';
this.STDOUT.style.border = '0px solid #000';
// Define scrolldelta
this.scrolldelta = this.STDOUT.scrollHeight;
}
Console.resize = function () {
// Determine size of visible area in browser window
SCREEN_WIDTH = io_AvailBrowserWidth();
SCREEN_HEIGHT = io_AvailBrowserHeight();
// Resize console elements
this.STDOUT.style.width = (SCREEN_WIDTH-20)+'px';
this.STDOUT.style.height = (SCREEN_HEIGHT-100)+'px';
this.PROMPT.style.width = (SCREEN_WIDTH-20)+'px';
this.STDIN.style.width = (SCREEN_WIDTH-20)+'px';
// recalibrate scrolldelta
var tmp = this.STDOUT.value;
this.STDOUT.value = '';
this.scrolldelta = this.STDOUT.scrollHeight;
this.STDOUT.value = tmp;
// Pass the message along to the window manager
if (DesktopUID != -1) {
wm_ResizeDesktop();
}
}
Console.toFront = function () {
document.getElementById('console0').style.zIndex = ++topZ
}
Console.toBack = function () {
document.getElementById('console0').style.zIndex = 0;
}
Console.focus = function () {
// this.STDIN.focus();
//
// Broken, workaround:
// document.getElementById('console0_stdin').focus();
this.STDIN.focus();
}
Console.unfocus = function () {
// Temporary hack
document.getElementById('console0_stdin').blur();
}
Console.writeln = function (str) {
// this.STDOUT.value += "\n" + str;
//
// Broken, workaround:
// document.getElementById('console0_stdout').value += "\n" + str;
this.STDOUT.value += "\n" + str;
}
window.onresize = Console.resize;
//
----------------------------------------------------------------------
// SCREEN.JS
var SCREEN_WIDTH = '0';
var SCREEN_HEIGHT = '0';
function io_InitScreen() {
SCREEN_WIDTH = io_AvailBrowserWidth();
SCREEN_HEIGHT = io_AvailBrowserHeight();
}
function io_AvailBrowserWidth() {
if(window.innerWidth) {
return window.innerWidth;
}
return -1;
}
function io_AvailBrowserHeight() {
if(window.innerHeight) {
return window.innerHeight;
}
return -1;
}
//
----------------------------------------------------------------------
// KEYBOARD.JS
var keyENTER = 13;
var keyUP = 38;
var keyDOWN = 40;
var keyPGUP =33;
var keyPGDN = 34;
function io_GetKey(e) {
if (window.event) return window.event.keyCode;
else if (e) return e.keyCode; // was e.which
else return null;
}
function io_MatchKey(key, test) {
if (key == test) return true;
else return false;
}
//
----------------------------------------------------------------------
// THIS IS A QUICK WASH SHELL HACK FOR EXAMPLE
function CommandlineHandler(event) {
var key = io_GetKey(event);
if (io_MatchKey(key, keyENTER)) {
var result = eval(document.getElementById('console0_stdin').value);
document.getElementById('console0_stdout').value += "\n" + result;
}
}
//
----------------------------------------------------------------------
// INIT.JS
var DOSCOMPAT = false;
var HOSTNAME = 'localhost';
var USERNAME = 'guest';
var GROUPNAME = 'guest';
var CWD = 'guest';
var PATH = '/bin:/sbin';
function system_Init() {
io_InitScreen();
Console.init();
// wm_InitWidgetManager();
// DOMFS.init();
// WashPrompt();
// WashCommand('/etc/rclocal');
Console.focus();
}
//
----------------------------------------------------------------------
</script>
</head>
<body onLoad="system_Init()">
<div id="console0">
<textarea id="console0_stdout"></textarea><br/>
<span id="console0_prompt"></span><br/>
<input type="text" id="console0_stdin"
onKeyPress="CommandlineHandler(event);">
</div>
</body>
</html>
[-- code ends --]
(Just a quick reminder that we're in the process of cleaning this code
up so that it's all object oriented...)