Skip to content
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

Support multi line commands (was: Input a scope in crconsole) #5

Open
ShawnHuang opened this issue Oct 28, 2013 · 9 comments
Open

Support multi line commands (was: Input a scope in crconsole) #5

ShawnHuang opened this issue Oct 28, 2013 · 9 comments

Comments

@ShawnHuang
Copy link

I think it would be better if we can type a scope in crconsole.
Just like typing in chrome dev tool and chrome-remote-interface's repl.

02

03

@sidorares
Copy link
Owner

not sure if I get the idea. Are you talking about multi line input?

@ShawnHuang
Copy link
Author

Chrome dev tool's rule is multi line input. I think it's difficult to implement.
Chrome-remote-interface's repl used repl module,
and its rule that I guess is to detect some keywords (function, if, while) and to let users to complete code scope.
I can't differ crconsole which also use repl module from that, but I try to write a sample with the repl module that also has the same feature.

@sidorares
Copy link
Owner

multiline input would be tricky with repl/readline. Node starts 'multiline mode' when there is syntax error - see https://github.com/joyent/node/blob/master/lib/repl.js#L296

Not sure if that is desired behaviour at all. Maybe we should trigger this only by some errors, like "Unexpected end of input"

@ShawnHuang
Copy link
Author

OK, I got it. Thanks for your reply

@sidorares
Copy link
Owner

Feel free to try to implement it yourself :)

@ShawnHuang
Copy link
Author

I will try it:)

@ShawnHuang
Copy link
Author

I try to replace the eval function with the following code, but I am not sure that there is no bugs at that code.
:)

https://github.com/sidorares/crconsole/blob/master/index.js#L272

    var err, result;                                                                                                            
    try{                                                                                                                        
      var script = require("vm").createScript(cmd.slice(1, -2), {                                                                            
        filename: filename,                                                                                                     
        displayErrors: false                                                                                                    
      });                                                                                                                       
    } catch (e){                                                                                                                
      err = e;                                                                                                                  
    }                                                                                                                           
    var mess = !!err;                                                                                                           
    if(mess) cb(err, result);                                                                                                   
    else{                                                                                                                       
      this.client.Runtime.evaluate({expression: cmd.slice(1, -2), generatePreview: true}, function(err, resp) {                              
        return cb(null, resp);                                                                                                  
      });                                                                                                                       
    }

@sidorares
Copy link
Owner

It will throw exceptions for some valid code, for example if you reference on the right hand side variable which is defined in remote context but not defined locally. I suggest to use esprima and check if it can build complete AST as a flag

@ShawnHuang
Copy link
Author

Oh!! Let me think about it. Thank you!

@sidorares sidorares changed the title Input a scope in crconsole Support multi line commands (was: Input a scope in crconsole) Jun 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants