cmd/geth, jsre: restore command line editing on windows

PR #856 broke command line editing by wrapping stdout with a filter that
interprets ANSI escape sequences to fix colored printing on windows.
Implement the printer in Go instead so it can do its own
platform-dependent coloring.

As a nice side effect, the JS console is now noticeably more responsive
when printing results.

Fixes #1608
Fixes #1612
This commit is contained in:
Felix Lange
2015-08-11 17:14:46 +01:00
parent 05c66529b2
commit 0ef80bb3d0
27 changed files with 1941 additions and 872 deletions

View File

@ -65,7 +65,6 @@ func New(assetPath string) *JSRE {
}
re.loopWg.Add(1)
go re.runEventLoop()
re.Compile("pp.js", pp_js) // load prettyprint func definition
re.Set("loadScript", re.loadScript)
return re
}
@ -255,35 +254,19 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value {
return otto.TrueValue()
}
// PrettyPrint writes v to standard output.
func (self *JSRE) PrettyPrint(v interface{}) (val otto.Value, err error) {
var method otto.Value
// EvalAndPrettyPrint evaluates code and pretty prints the result to
// standard output.
func (self *JSRE) EvalAndPrettyPrint(code string) (err error) {
self.do(func(vm *otto.Otto) {
val, err = vm.ToValue(v)
var val otto.Value
val, err = vm.Run(code)
if err != nil {
return
}
method, err = vm.Get("prettyPrint")
if err != nil {
return
}
val, err = method.Call(method, val)
prettyPrint(vm, val)
fmt.Println()
})
return val, err
}
// Eval evaluates JS function and returns result in a pretty printed string format.
func (self *JSRE) Eval(code string) (s string, err error) {
var val otto.Value
val, err = self.Run(code)
if err != nil {
return
}
val, err = self.PrettyPrint(val)
if err != nil {
return
}
return fmt.Sprintf("%v", val), nil
return err
}
// Compile compiles and then runs a piece of JS code.