mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
urgh file loading
This commit is contained in:
parent
ef30e3100a
commit
1381e55db6
1 changed files with 34 additions and 8 deletions
|
|
@ -3,7 +3,7 @@ var clite = {
|
|||
isinit:false,
|
||||
terminal:null,
|
||||
input:{
|
||||
ispass:false,
|
||||
type:'text',
|
||||
form:null,
|
||||
field:null
|
||||
}
|
||||
|
|
@ -63,14 +63,16 @@ var clite = {
|
|||
},
|
||||
file:function(name,callback) {
|
||||
if (window.location.protocol == 'file:') {
|
||||
clite.log.write('no file: support');
|
||||
clite.shell.writeLine('open file: '+name);
|
||||
clite.term.setCustom({type:'file',callback:callback});
|
||||
clite.events.refocus();
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(name)
|
||||
.then(response => response.text())
|
||||
.then((data) => {
|
||||
callback(data)
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -92,7 +94,7 @@ var clite = {
|
|||
|
||||
clite.events.refocus();
|
||||
|
||||
clite.core.load.file('data/filesys.txt',alert);
|
||||
clite.core.load.file('data/filesys.txt',clite.shell.writeLine);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -123,7 +125,7 @@ clite.term = {
|
|||
l.innerHTML = clite.shell.prompt.getHTML();
|
||||
f.appendChild(l);
|
||||
var i = document.createElement('input');
|
||||
i.type = clite.state.input.ispass ? 'password' : 'text';
|
||||
i.type = clite.term.getType();
|
||||
i.value = clite.shell.history.getCurrent();
|
||||
f.appendChild(i);
|
||||
clite.state.input.form = f;
|
||||
|
|
@ -135,12 +137,36 @@ clite.term = {
|
|||
i.onkeyup = clite.events.keyup;
|
||||
i.onfocusout = clite.events.refocus;
|
||||
i.onblur = clite.events.refocus;
|
||||
if (i.type == 'file') {
|
||||
i.onchange = function(e) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function() {
|
||||
clite.state.input.type.callback(reader.result);
|
||||
clite.term.setPass(false);
|
||||
clite.shell.writeLine('loaded');
|
||||
};
|
||||
reader.onerror = function() {
|
||||
clite.state.input.type.callback(null);
|
||||
clite.term.setPass(false);
|
||||
clite.shell.writeLine('load failed');
|
||||
};
|
||||
reader.readAsText(e.target.files[0]);
|
||||
}
|
||||
}
|
||||
f.onsubmit = function() {return false;};
|
||||
},
|
||||
setPass:function(is) {
|
||||
clite.state.input.ispass = !!is;
|
||||
if (typeof clite.state.input.ispass != 'Boolean')
|
||||
clite.state.input.ispass = false;
|
||||
clite.state.input.type = (!!is) ? 'password' : 'text';
|
||||
},
|
||||
setCustom:function(type) {
|
||||
clite.state.input.type = type;
|
||||
},
|
||||
getType:function() {
|
||||
if (typeof clite.state.input.type == 'string')
|
||||
return clite.state.input.type;
|
||||
if (typeof clite.state.input.type == 'object' && typeof clite.state.input.type.type == 'string')
|
||||
return clite.state.input.type.type;
|
||||
return 'text';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue