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:
		
							
								
								
									
										33
									
								
								jsre/jsre.go
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user