Some keyboard input on web.
This commit is contained in:
72
web/fini.fs
72
web/fini.fs
@ -29,35 +29,79 @@ r|
|
||||
eval(text);
|
||||
return sp;
|
||||
})
|
||||
| 2 jseval!
|
||||
: jseval ( a n -- ) 2 call ;
|
||||
| 1 jseval!
|
||||
: jseval ( a n -- ) 1 call ;
|
||||
|
||||
r|
|
||||
r"
|
||||
if (!globalObj['write']) {
|
||||
var console = document.createElement('pre');
|
||||
console.id = 'console';
|
||||
document.body.appendChild(console);
|
||||
var con = document.createElement('pre');
|
||||
con.id = 'console';
|
||||
document.body.appendChild(con);
|
||||
window.inbuffer = [];
|
||||
window.outbuffer = '';
|
||||
window.onkeypress = function(e) {
|
||||
window.inbuffer.push(e.keyCode);
|
||||
};
|
||||
window.onkeydown = function(e) {
|
||||
if (e.keyCode == 8) {
|
||||
window.inbuffer.push(e.keyCode);
|
||||
}
|
||||
};
|
||||
}
|
||||
| jseval
|
||||
" jseval
|
||||
|
||||
r|
|
||||
(function(sp) {
|
||||
var n = i32[sp>>2]; sp -= 4;
|
||||
var a = i32[sp>>2]; sp -= 4;
|
||||
var text = GetString(a, n);
|
||||
if (globalObj['write']) {
|
||||
var text = GetString(a, n);
|
||||
write(text);
|
||||
} else {
|
||||
var console = document.getElementById('console');
|
||||
console.innerText += text.replace(/[\r]/g, '');
|
||||
var con = document.getElementById('console');
|
||||
for (var i = 0; i < n; ++i) {
|
||||
var ch = u8[a + i];
|
||||
if (ch == 12) {
|
||||
window.outbuffer = '';
|
||||
} else if (ch == 8) {
|
||||
window.outbuffer = window.outbuffer.slice(0, -1);
|
||||
} else if (ch == 13) {
|
||||
} else {
|
||||
window.outbuffer += String.fromCharCode(ch);
|
||||
}
|
||||
}
|
||||
con.innerText = window.outbuffer + String.fromCharCode(0x2592);
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
}
|
||||
return sp;
|
||||
})
|
||||
| 1 jseval!
|
||||
| 2 jseval!
|
||||
: web-type ( a n -- ) 2 call ;
|
||||
' web-type is type
|
||||
|
||||
: web-type 1 call ; ' web-type is type
|
||||
: web-key yield 0 ; ' web-key is key
|
||||
: web-key? yield 0 ; ' web-key? is key?
|
||||
r|
|
||||
(function(sp) {
|
||||
if (window.inbuffer.length) {
|
||||
sp += 4; i32[sp>>2] = window.inbuffer.shift();
|
||||
} else {
|
||||
sp += 4; i32[sp>>2] = 0;
|
||||
}
|
||||
return sp;
|
||||
})
|
||||
| 3 jseval!
|
||||
: web-key ( -- n ) begin yield 3 call dup if exit then drop again ;
|
||||
' web-key is key
|
||||
|
||||
r|
|
||||
(function(sp) {
|
||||
sp += 4; i32[sp>>2] = window.inbuffer.length ? -1 : 0;
|
||||
return sp;
|
||||
})
|
||||
| 4 jseval!
|
||||
: web-key? ( -- f ) yield 4 call ;
|
||||
' web-key? is key?
|
||||
|
||||
: page 12 emit ;
|
||||
|
||||
transfer forth
|
||||
forth
|
||||
|
||||
Reference in New Issue
Block a user