-
-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiline Input #22
Comments
There is already this kind of code in Scheme Example (only on the page not in repo). It count if parents in S-Expressions are balanced. Check code (in the source) http://terminal.jcubic.pl/examples.php#dterm, the code check if parents/brackets are ballanced if no it accept more input and concatenate it and only then execute the code. This feature is not for the terminal but for specific implementation, terminal can only help in implement it by the client. I can only make multiline input easier. |
It was not easy to find, so I'll leave here the link: https://github.com/jcubic/jquery.terminal-www/blob/a4c593e516b738d361a745a214ce852306cda9b4/examples.php.in#L2265-L2296 |
IMHO better multiline is Shift+Enter, I've created better parenthesis match but in single input here https://jcubic.github.io/lips/ (source: https://github.com/jcubic/lips/blob/gh-pages/index.html#L192) |
But there is also an option to overwrite ENTER keymap and insert newline when parenthesis are not balanced, I'll try to create example or update my parenthesis matching. |
Our case is when a backend is responsible for distinguish whether a command is incomplete. But I guess I'm able to implement it just on server side and allows a client to send incomplete commands (maybe prompting will need some tweaking). |
Here is better solution, for your case: var term;
$(function() {
term = $('<div/>').attr('id', 'term')
.appendTo('body')
.terminal(function(command) {
this.echo('executing ' + command);
}, {
name: 'multiline',
keymap: {
ENTER: function(e, original) {
this.pause();
$.jrpc('service.php', 'enter', [this.get_command()],
(response) => {
if (response.result == '__ENTER__') {
this.insert('\n');
} else if (response.result == '__EXEC__') {
original();
} else if (response.error) {
// you need to decide what to do, user still
// can edit whole command
// you can highlight all parenthesis using jQuery
// since each character is in own span
this.error('Syntax error');
}
this.resume();
}
);
}
},
prompt: 'exec> '
});
}); <?php
require('json-rpc.php');
if (function_exists('xdebug_disable')) {
xdebug_disable();
}
function balance($code) {
$pa = str_split(preg_replace("/[^()]/", "", $code));
$i = 0;
foreach ($pa as $p) {
if ($p == '(') {
$i++;
} else if ($p == ')') {
$i--;
}
}
return $i;
}
class Service {
function enter($code) {
$p = balance($code);
if ($p < 0) {
throw new Exception("Parenthesis error");
} else if ($p > 0) {
return "__ENTER__";
} else {
return "__EXEC__";
}
}
}
handle_json_rpc(new Service());
?> Instead of JSON-RPC you can use normal ajax call and inside interpreter function you can call ajax. The only limitation is that you will have two requests. If you want one you will to put your code instead of |
Admittedly this is a niche case, but it would be a nice configurable feature for the plugin to count the number of opening braces/parens/brackets and continue to accept input until the count is zero for each.
The text was updated successfully, but these errors were encountered: