Comments (6)
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.
from jquery.terminal.
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
from jquery.terminal.
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)
from jquery.terminal.
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.
from jquery.terminal.
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).
from jquery.terminal.
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 "__EXEC__"
and return exec value if result will be __ENTER__
you insert \n
normaly but if you have different value you just echo it and call original()
note this in this case your interpreter can be empty (use $.noop
) it will be only used to handle displaying of prompt.
from jquery.terminal.
Related Issues (20)
- See if you can change the keyboard on mobile
- Allow to change link target attribute HOT 1
- Create PoC for command hints HOT 1
- Error when running sequence of animations without newline
- Conflict with other library!! HOT 4
- Cursor animation is affected by update in interval HOT 1
- Don't update DOM when line didn't change HOT 1
- Prompt visible during multiline typing animation
- Greetings should allow instance of String object
- Issue with formatting when rendering images with & and &
- Formatting from prompt visible when exec with animation
- Text selection is not visible when echo raw
- Possible cancel of command promises HOT 3
- Create Terminal inspired Merch HOT 1
- Animate exec hash HOT 1
- Add reverse style to formatting
- Limit XML formatter targets
- skip animation doesn't work
- Infinite Loop when animating of empty line
- Async push + pause
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery.terminal.