diff options
author | Erez Wanderman <erez.wanderman@outlook.com> | 2014-10-15 07:41:26 +0800 |
---|---|---|
committer | Erez Wanderman <erez.wanderman@outlook.com> | 2014-10-15 07:41:26 +0800 |
commit | 7227552f429e6ad035b22167d667712e61fcebbb (patch) | |
tree | c8617b81efa99b2a71140e9ca5a19175212ae326 /ethereum/repl/repl_windows.go | |
parent | 294b4374148fb2afa019779a4ef17bec5d4c3665 (diff) | |
download | go-tangerine-7227552f429e6ad035b22167d667712e61fcebbb.tar go-tangerine-7227552f429e6ad035b22167d667712e61fcebbb.tar.gz go-tangerine-7227552f429e6ad035b22167d667712e61fcebbb.tar.bz2 go-tangerine-7227552f429e6ad035b22167d667712e61fcebbb.tar.lz go-tangerine-7227552f429e6ad035b22167d667712e61fcebbb.tar.xz go-tangerine-7227552f429e6ad035b22167d667712e61fcebbb.tar.zst go-tangerine-7227552f429e6ad035b22167d667712e61fcebbb.zip |
Fix ethereum compilation and functioning on Windows.
repl console output is now colored.
repl "exit" command now works.
Diffstat (limited to 'ethereum/repl/repl_windows.go')
-rw-r--r-- | ethereum/repl/repl_windows.go | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/ethereum/repl/repl_windows.go b/ethereum/repl/repl_windows.go index 4106c89bc..bfae57088 100644 --- a/ethereum/repl/repl_windows.go +++ b/ethereum/repl/repl_windows.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "os" + "strings" ) func (self *JSRepl) read() { @@ -14,11 +15,61 @@ func (self *JSRepl) read() { if err != nil { fmt.Println("Error reading input", err) } else { - self.parseInput(string(str)) + if (string(str) == "exit") { + self.Stop() + break + } else { + self.parseInput(string(str)) + } } } } -func (self *JSRepl) PrintValue(value otto.Value) { - fmt.Println(value) +func addHistory(s string) { +} + +func printColored(outputVal string) { + for ; outputVal != "" ; { + codePart := "" + if (strings.HasPrefix(outputVal, "\033[32m")) { + codePart = "\033[32m" + changeColor(2) + } + if (strings.HasPrefix(outputVal, "\033[1m\033[30m")) { + codePart = "\033[1m\033[30m" + changeColor(8) + } + if (strings.HasPrefix(outputVal, "\033[31m")) { + codePart = "\033[31m" + changeColor(red) + } + if (strings.HasPrefix(outputVal, "\033[35m")) { + codePart = "\033[35m" + changeColor(5) + } + if (strings.HasPrefix(outputVal, "\033[0m")) { + codePart = "\033[0m" + resetColorful() + } + textPart := outputVal[len(codePart):len(outputVal)] + index := strings.Index(textPart, "\033") + if index == -1 { + outputVal = "" + } else { + outputVal = textPart[index:len(textPart)] + textPart = textPart[0:index] + } + fmt.Printf("%v", textPart) + } +} + +func (self *JSRepl) PrintValue(v interface{}) { + method, _ := self.re.Vm.Get("prettyPrint") + v, err := self.re.Vm.ToValue(v) + if err == nil { + val, err := method.Call(method, v) + if err == nil { + printColored(fmt.Sprintf("%v", val)) + } + } } |