aboutsummaryrefslogtreecommitdiffstats
path: root/jsre/jsre.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-08-12 00:14:46 +0800
committerFelix Lange <fjl@twurst.com>2015-08-12 18:04:00 +0800
commit0ef80bb3d05ecb44297d25c889a85555bc55ef0c (patch)
treee20fd801a5cd219ee8e5dcf82acd003a44bb02e5 /jsre/jsre.go
parent05c66529b2c22fba20c55a69c4817395c532d4c8 (diff)
downloaddexon-0ef80bb3d05ecb44297d25c889a85555bc55ef0c.tar
dexon-0ef80bb3d05ecb44297d25c889a85555bc55ef0c.tar.gz
dexon-0ef80bb3d05ecb44297d25c889a85555bc55ef0c.tar.bz2
dexon-0ef80bb3d05ecb44297d25c889a85555bc55ef0c.tar.lz
dexon-0ef80bb3d05ecb44297d25c889a85555bc55ef0c.tar.xz
dexon-0ef80bb3d05ecb44297d25c889a85555bc55ef0c.tar.zst
dexon-0ef80bb3d05ecb44297d25c889a85555bc55ef0c.zip
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
Diffstat (limited to 'jsre/jsre.go')
-rw-r--r--jsre/jsre.go33
1 files changed, 8 insertions, 25 deletions
diff --git a/jsre/jsre.go b/jsre/jsre.go
index d4c982897..bb0cc71ed 100644
--- a/jsre/jsre.go
+++ b/jsre/jsre.go
@@ -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.