diff --git a/links/main.css b/links/main.css index efa1c57..a913be9 100644 --- a/links/main.css +++ b/links/main.css @@ -20,6 +20,8 @@ body { margin:0px; padding:0px; overflow:hidden; font-family:"input_mono_medium" #terminal #widget { text-align: right; bottom:30px} #terminal #widget .mouse { color:white; } +span.autocomplete { background:white; color:black; } + span.module { display: inline-block; color:#999; } span.method { display: inline-block; color:#999; } span.method .name { color:#fff; } diff --git a/scripts/core/keyboard.js b/scripts/core/keyboard.js index 9dfb77d..58f360f 100644 --- a/scripts/core/keyboard.js +++ b/scripts/core/keyboard.js @@ -14,6 +14,16 @@ function Keyboard() if(event.altKey == true){ this.alt_held = true; } + + // Autocomplete with tab + if(event.keyCode === 9){ + var ac = ronin.terminal.find_autocomplete(); + if(ac){ + event.preventDefault(); + ronin.terminal.input.value += ac; + } + } + ronin.cursor.update(event); ronin.widget.update(); ronin.terminal.update(); @@ -24,6 +34,8 @@ function Keyboard() this.shift_held = false; this.alt_held = false; + event.preventDefault(); + switch (event.key || event.keyCode || event.which) { case "Enter": this.key_enter(); break; case "ArrowUp": this.key_arrow_up(); break; @@ -44,6 +56,8 @@ function Keyboard() case 8: this.key_delete(); break; } + console.log(event) + // Passive ronin.widget.update(); ronin.terminal.update(); diff --git a/scripts/modules/terminal.js b/scripts/modules/terminal.js index 4a1caa2..de37171 100644 --- a/scripts/modules/terminal.js +++ b/scripts/modules/terminal.js @@ -54,11 +54,13 @@ function Terminal(rune) var command = this.cmd(); var module = command.module(); var method = command.method(); + var autocomplete = this.find_autocomplete(command,module,method); if(method && preview){ method.preview(command); } - this.hint_element.innerHTML = ""+this.input.value+""+(this.input.value ? " > " : "")+(module ? module.hint(method) : ronin.hint(method)); + + this.hint_element.innerHTML = ""+this.input.value+""+(autocomplete ? ''+autocomplete+'' : '')+(this.input.value ? " > " : "")+(module ? module.hint(method) : ronin.hint(method)); ronin.cursor.update(); } @@ -92,6 +94,31 @@ function Terminal(rune) return "Loading "+cmd.values(); } + + this.find_autocomplete = function() + { + html = "" + + var entry = this.input.value; + var module = this.cmd().module(); + var method = entry.indexOf(".") > -1 ? entry.split(".")[1] : null; + + if(entry.length == 0){ return null; } + + if(module && method){ + for(id in module.methods){ + if(method == module.methods[id].name){ break; } + if(method == module.methods[id].name.substr(0,method.length)){ return module.methods[id].name.replace(method,""); } + } + } + else{ + for(id in ronin.modules){ + if(entry == ronin.modules[id].name){ break; } + if(entry == ronin.modules[id].name.substr(0,entry.length)){ return ronin.modules[id].name.replace(entry,""); } + } + } + return null; + } } // Log