start of shell tabfill

This commit is contained in:
Lisa Milne 2023-11-09 20:49:18 +10:00
parent 3906795007
commit 90169d6546

View file

@ -9,6 +9,17 @@ var clite = {
}
},
events:{
keydown:function(e) {
return clite.events.keypress(e);
},
keypress:function(e) {
if (e.key == 'Tab') {
clite.shell.tabfill();
clite.events.refocus();
return false;
}
return true;
},
keyup:function(e) {
try {
if (e.key == 'Down' || e.key == 'ArrowDown') {
@ -19,6 +30,9 @@ var clite = {
clite.shell.history.up();
return false;
}
if (e.key == 'Tab') {
return false;
}
var t = clite.state.input.field.value;
if (e.key != 'Enter') {
clite.shell.history.setCurrent(t);
@ -720,6 +734,8 @@ clite.term = {
if (!t)
return;
t.appendChild(f);
i.onkeydown = clite.events.keydown;
i.onkeypress = clite.events.keypress;
i.onkeyup = clite.events.keyup;
i.onfocusout = clite.events.refocus;
i.onblur = clite.events.refocus;
@ -923,6 +939,40 @@ clite.shell = {
clite.shell.exec(args,stdio);
}
},
tabfill:function() {
var c = clite.shell.history.getCurrent();
var parts = clite.lib.strToArgs(c);
var ai = parts.length-1;
if (ai < 0)
return;
var a = parts[ai];
var add = '';
if (ai == 0) {
// test for shell macros/builtins
Object.keys(clite.shell.macro).forEach(function(key) {
if (add == '' && key.substring(0,a.length) == a) {
add = key.substring(a.length);
}
});
if (add == '') {
// test for commands
// TODO: test all of PATH
var fd = clite.io.open('/bin');
var f;
while (add == '' && (f = clite.io.read(fd)) != null) {
if (f.name.substring(0,a.length) == a) {
add = f.name.substring(a.length);
}
}
clite.io.close(fd);
}
}else{
// TODO: path fill
}
if (add == '')
return;
clite.shell.history.setCurrent(c+add);
},
env:{
USER:'root',
PWD:'/',