|
Hi, I am about to create a web version for a LISP-like interpreter. What I really need is tab completion. That is, something like completing the input in a form like "(command ...)". Here the command begins with a parenthesis. Does jquery.terminal offer a way to do that with minimal effort? |
Replies: 2 comments 2 replies
|
You can look at how I've created completion for LIPS Scheme. Not sure if you saw it. You can find the code for the terminal on that website here: https://github.com/jcubic/lips/blob/master/lib/js/terminal.js#L200-L220 completion: function(string) {
let tokens = lips.tokenize(this.before_cursor(), true);
tokens = tokens.map(token => token.token);
// Array.from is need to for jQuery terminal version <2.5.0
// when terminal is outside iframe and lips is inside
// jQuery Terminal was using instanceof that don't work between iframes
var env = Array.from(interpreter.get('env')().to_array());
if (!tokens.length) {
return env;
}
const last = tokens.pop();
if (last.trim().length) {
const globals = Object.getOwnPropertyNames(window);
const prefix = tokens.join('');
const re = new RegExp('^' + $.terminal.escape_regex(last));
var commands = env.concat(globals).filter(name => {
return re.test(name);
}).map(name => prefix + name);
return Array.from(commands);
}
},The code uses my lisp parser to parse the whole code and get the last word that can be completed. |
|
What's cool about my terminal is that it also has parentheses matching and scheme syntax highlighting. Similar code (but older) is on the BiwaScheme website. |
You can look at how I've created completion for LIPS Scheme. Not sure if you saw it. You can find the code for the terminal on that website here:
https://github.com/jcubic/lips/blob/master/lib/js/terminal.js#L200-L220