From 90169d6546d2b1a14a640cc685d15eaf73a957e0 Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Thu, 9 Nov 2023 20:49:18 +1000 Subject: [PATCH] start of shell tabfill --- clite/core.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/clite/core.js b/clite/core.js index 9ba6308..3f882e1 100644 --- a/clite/core.js +++ b/clite/core.js @@ -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:'/',