mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
local file system loading working again
This commit is contained in:
parent
8dad3466d0
commit
93a4885563
2 changed files with 159 additions and 9 deletions
166
clite/bios.js
166
clite/bios.js
|
|
@ -46,9 +46,8 @@ var bios = {
|
||||||
head.appendChild(script);
|
head.appendChild(script);
|
||||||
},
|
},
|
||||||
file:function(name,callback) {
|
file:function(name,callback) {
|
||||||
if (window.location.protocol == 'file:') { // this is a dirty hack and I hate it, just let me open a file: path!
|
if (window.location.protocol == 'file:') {
|
||||||
//clite.term.setCustom({type:'file',callback:callback});
|
bios.io.write(3,{file:name,fn:callback});
|
||||||
//clite.term.writeLine('open file: '+name);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,6 +91,10 @@ var bios = {
|
||||||
}
|
}
|
||||||
bios.input.keybuffer.rcvr = d;
|
bios.input.keybuffer.rcvr = d;
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
bios.input.upload.data.callback = d.fn;
|
||||||
|
bios.input.upload.data.file = d.file;
|
||||||
|
bios.input.setState(2);
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -143,10 +146,33 @@ var bios = {
|
||||||
input:{
|
input:{
|
||||||
el:null,
|
el:null,
|
||||||
state:0,
|
state:0,
|
||||||
|
setState:function(v) { // 1 for normal keyboard input, 2 for file access
|
||||||
|
if (bios.input.state == v)
|
||||||
|
return;
|
||||||
|
switch (bios.input.state) {
|
||||||
|
case 1:
|
||||||
|
bios.input.keyboard.disable();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
bios.input.upload.disable();
|
||||||
|
break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
switch (v) {
|
||||||
|
case 2:
|
||||||
|
bios.input.upload.enable();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
bios.input.keyboard.enable();
|
||||||
|
v = 1;
|
||||||
|
}
|
||||||
|
bios.input.state = v;
|
||||||
|
},
|
||||||
init:function() {
|
init:function() {
|
||||||
bios.input.el = document.getElementById('input');
|
bios.input.el = document.getElementById('input');
|
||||||
bios.input.keyboard.init();
|
bios.input.keyboard.init();
|
||||||
bios.input.state = 1;
|
bios.input.upload.init();
|
||||||
|
bios.input.setState(1);
|
||||||
},
|
},
|
||||||
keybuffer:{
|
keybuffer:{
|
||||||
rcvr:null,
|
rcvr:null,
|
||||||
|
|
@ -364,7 +390,8 @@ bios.video.graphic = {
|
||||||
|
|
||||||
bios.input.keyboard = {
|
bios.input.keyboard = {
|
||||||
data:{
|
data:{
|
||||||
el:null
|
el:null,
|
||||||
|
enabled:false
|
||||||
},
|
},
|
||||||
internal:{
|
internal:{
|
||||||
rawDown:function(e) {
|
rawDown:function(e) {
|
||||||
|
|
@ -495,18 +522,141 @@ bios.input.keyboard = {
|
||||||
bios.input.keyboard.data.el = document.createElement('textarea');
|
bios.input.keyboard.data.el = document.createElement('textarea');
|
||||||
bios.input.keyboard.data.el.id = 'kbd';
|
bios.input.keyboard.data.el.id = 'kbd';
|
||||||
bios.input.keyboard.data.el.className = 'kbd';
|
bios.input.keyboard.data.el.className = 'kbd';
|
||||||
bios.input.keyboard.data.el.style.zIndex = '100';
|
//bios.input.keyboard.data.el.style.zIndex = '100';
|
||||||
bios.input.keyboard.data.el.style.display = 'block';
|
bios.input.keyboard.data.el.style.display = 'block';
|
||||||
}
|
}
|
||||||
bios.input.keyboard.data.el.addEventListener('keydown',bios.input.keyboard.internal.rawDown);
|
bios.input.keyboard.data.el.addEventListener('keydown',bios.input.keyboard.internal.rawDown);
|
||||||
bios.input.keyboard.data.el.addEventListener('keyup',bios.input.keyboard.internal.rawUp);
|
bios.input.keyboard.data.el.addEventListener('keyup',bios.input.keyboard.internal.rawUp);
|
||||||
bios.input.keyboard.data.el.addEventListener('focusout',bios.input.keyboard.internal.resetFocus);
|
if (bios.input.keyboard.data.enabled) {
|
||||||
|
bios.input.keyboard.data.el.addEventListener('focusout',bios.input.keyboard.internal.resetFocus);
|
||||||
|
bios.input.keyboard.internal.resetFocus();
|
||||||
|
}
|
||||||
return bios.input.keyboard.data.el;
|
return bios.input.keyboard.data.el;
|
||||||
},
|
},
|
||||||
init:function() {
|
init:function() {
|
||||||
var el = bios.input.keyboard.getElement();
|
var el = bios.input.keyboard.getElement();
|
||||||
bios.input.el.appendChild(el);
|
bios.input.el.appendChild(el);
|
||||||
bios.input.keyboard.internal.resetFocus();
|
},
|
||||||
|
enable:function() {
|
||||||
|
bios.input.keyboard.data.enabled = true;
|
||||||
|
bios.input.keyboard.getElement();
|
||||||
|
},
|
||||||
|
disable:function() {
|
||||||
|
bios.input.keyboard.data.enabled = false;
|
||||||
|
bios.input.keyboard.getElement();
|
||||||
|
bios.input.keyboard.data.el.removeEventListener('focusout',bios.input.keyboard.internal.resetFocus);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bios.input.upload = {
|
||||||
|
data:{
|
||||||
|
el:null,
|
||||||
|
enabled:false,
|
||||||
|
reader:null,
|
||||||
|
callback:null,
|
||||||
|
file:null,
|
||||||
|
panel:null
|
||||||
|
},
|
||||||
|
internal:{
|
||||||
|
createUploadPanel:function() {
|
||||||
|
if (bios.video.mode.current != 1 || bios.input.upload.data.file == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var l = 28;
|
||||||
|
if (bios.input.upload.data.file.length > l)
|
||||||
|
l = bios.input.upload.data.file.length;
|
||||||
|
var w = l+4;
|
||||||
|
var h = 6;
|
||||||
|
var x = 40-(w/2);
|
||||||
|
var y = 9;
|
||||||
|
|
||||||
|
for (var i=0; i<w; i++) {
|
||||||
|
bios.video.io.write(x+i,y,' ');
|
||||||
|
bios.video.io.setBG(x+i,y,15);
|
||||||
|
}
|
||||||
|
for (var j=0; j<4; j++) {
|
||||||
|
y++;
|
||||||
|
bios.video.io.write(x,y,' ');
|
||||||
|
bios.video.io.setBG(x,y,15);
|
||||||
|
for (var i=1; i<w-1; i++) {
|
||||||
|
bios.video.io.write(x+i,y,' ');
|
||||||
|
bios.video.io.setBG(x+i,y,0);
|
||||||
|
}
|
||||||
|
bios.video.io.write(x+w-1,y,' ');
|
||||||
|
bios.video.io.setBG(x+w-1,y,15);
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
for (var i=0; i<w; i++) {
|
||||||
|
bios.video.io.write(x+i,y,' ');
|
||||||
|
bios.video.io.setBG(x+i,y,15);
|
||||||
|
}
|
||||||
|
var ho = x+2;
|
||||||
|
var fo = x+2;
|
||||||
|
if (l == 28) {
|
||||||
|
fo += ((28-bios.input.upload.data.file.length)/2);
|
||||||
|
}else{
|
||||||
|
ho += ((bios.input.upload.data.file.length-28)/2);
|
||||||
|
}
|
||||||
|
bios.core.writeStringVGA(ho,11,'Press Enter and Select File:',15);
|
||||||
|
bios.core.writeStringVGA(fo,12,bios.input.upload.data.file,15);
|
||||||
|
},
|
||||||
|
removeUploadPanel:function() {
|
||||||
|
if (bios.video.mode.current != 1 || bios.input.upload.data.panel == null)
|
||||||
|
return;
|
||||||
|
// TODO: create should store the current state so this can restore it
|
||||||
|
},
|
||||||
|
resetFocus:function(e) {
|
||||||
|
setTimeout(function() {
|
||||||
|
try{
|
||||||
|
document.getElementById('lfs').focus();
|
||||||
|
} catch(err) {}
|
||||||
|
},10);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getElement:function() {
|
||||||
|
bios.input.upload.data.el = document.getElementById('lfs');
|
||||||
|
if (typeof bios.input.upload.data.el === 'undefined' || bios.input.upload.data.el == null) {
|
||||||
|
bios.input.upload.data.el = document.createElement('input');
|
||||||
|
bios.input.upload.data.el.id = 'lfs';
|
||||||
|
bios.input.upload.data.el.className = 'lfs';
|
||||||
|
//bios.input.upload.data.el.style.zIndex = '100';
|
||||||
|
bios.input.upload.data.el.style.display = 'block';
|
||||||
|
bios.input.upload.data.el.type = 'file';
|
||||||
|
}
|
||||||
|
bios.input.upload.data.el.onchange = function(e) {
|
||||||
|
bios.input.upload.data.reader = new FileReader();
|
||||||
|
bios.input.upload.data.reader.onload = function() {
|
||||||
|
bios.input.setState(1);
|
||||||
|
bios.input.upload.data.callback(bios.input.upload.data.reader.result);
|
||||||
|
};
|
||||||
|
bios.input.upload.data.reader.onerror = function() {
|
||||||
|
bios.input.setState(1);
|
||||||
|
bios.input.upload.data.callback(null);
|
||||||
|
};
|
||||||
|
bios.input.upload.data.reader.readAsText(e.target.files[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bios.input.upload.data.enabled) {
|
||||||
|
bios.input.upload.data.el.addEventListener('focusout',bios.input.upload.internal.resetFocus);
|
||||||
|
bios.input.upload.internal.resetFocus();
|
||||||
|
}
|
||||||
|
return bios.input.upload.data.el;
|
||||||
|
},
|
||||||
|
init:function() {
|
||||||
|
var el = bios.input.upload.getElement();
|
||||||
|
bios.input.el.appendChild(el);
|
||||||
|
},
|
||||||
|
enable:function() {
|
||||||
|
bios.input.upload.data.enabled = true;
|
||||||
|
bios.input.upload.getElement();
|
||||||
|
bios.input.upload.internal.createUploadPanel();
|
||||||
|
},
|
||||||
|
disable:function() {
|
||||||
|
bios.input.upload.data.enabled = false;
|
||||||
|
bios.input.upload.getElement();
|
||||||
|
bios.input.upload.data.el.removeEventListener('focusout',bios.input.upload.internal.resetFocus);
|
||||||
|
bios.input.upload.internal.removeUploadPanel();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ body {display:grid; align-items:center;}
|
||||||
|
|
||||||
div {display:block; margin:0; padding:0;}
|
div {display:block; margin:0; padding:0;}
|
||||||
div.vga {margin:auto; z-index:10; background-color:#000000;}
|
div.vga {margin:auto; z-index:10; background-color:#000000;}
|
||||||
div.io {position:absolute; top:0px; left:0px; width:100px; height:100px; z-index:3;}
|
div.io {position:absolute; top:0px; left:0px; width:100px; height:100px; z-index:3; overflow:hidden;}
|
||||||
div.ioblank {position:absolute; top:0px; left:0px; width:100px; height:100px; z-index:9; background-color:black;}
|
div.ioblank {position:absolute; top:0px; left:0px; width:100px; height:100px; z-index:9; background-color:black;}
|
||||||
div.io textarea {display:block; width:50px; height:50px;}
|
div.io textarea {display:block; width:50px; height:50px;}
|
||||||
div.io audio {display:block; width:20px; height:20px;}
|
div.io audio {display:block; width:20px; height:20px;}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue