Giter Club home page Giter Club logo

Comments (6)

jcubic avatar jcubic commented on May 20, 2024

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.

Totktonada avatar Totktonada commented on May 20, 2024

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.

jcubic avatar jcubic commented on May 20, 2024

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.

jcubic avatar jcubic commented on May 20, 2024

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.

Totktonada avatar Totktonada commented on May 20, 2024

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.

jcubic avatar jcubic commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.