diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-14 19:14:11 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-14 19:14:11 +0800 |
commit | 3a66c4ed477cde437705f02811225fa11b0ae5ff (patch) | |
tree | 4fb74e85fc85ad9cf532d6f0b24e31a821c15fa7 /cmd/geth | |
parent | 29181003d4f50611a9082805509eed425c81db1a (diff) | |
parent | 0ef80bb3d05ecb44297d25c889a85555bc55ef0c (diff) | |
download | go-tangerine-3a66c4ed477cde437705f02811225fa11b0ae5ff.tar go-tangerine-3a66c4ed477cde437705f02811225fa11b0ae5ff.tar.gz go-tangerine-3a66c4ed477cde437705f02811225fa11b0ae5ff.tar.bz2 go-tangerine-3a66c4ed477cde437705f02811225fa11b0ae5ff.tar.lz go-tangerine-3a66c4ed477cde437705f02811225fa11b0ae5ff.tar.xz go-tangerine-3a66c4ed477cde437705f02811225fa11b0ae5ff.tar.zst go-tangerine-3a66c4ed477cde437705f02811225fa11b0ae5ff.zip |
Merge pull request #1642 from ethereum/fix-js-console-windows
cmd/geth, jsre: restore command line editing on windows
Diffstat (limited to 'cmd/geth')
-rw-r--r-- | cmd/geth/js.go | 39 | ||||
-rw-r--r-- | cmd/geth/main.go | 19 |
2 files changed, 15 insertions, 43 deletions
diff --git a/cmd/geth/js.go b/cmd/geth/js.go index ff319ab6b..1ca59e2f4 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -248,22 +248,22 @@ func (self *jsre) batch(statement string) { // show summary of current geth instance func (self *jsre) welcome() { - self.re.Eval(`console.log('instance: ' + web3.version.client);`) - self.re.Eval(`console.log(' datadir: ' + admin.datadir);`) - self.re.Eval(`console.log("coinbase: " + eth.coinbase);`) - self.re.Eval(`var lastBlockTimestamp = 1000 * eth.getBlock(eth.blockNumber).timestamp`) - self.re.Eval(`console.log("at block: " + eth.blockNumber + " (" + new Date(lastBlockTimestamp).toLocaleDateString() - + " " + new Date(lastBlockTimestamp).toLocaleTimeString() + ")");`) - + self.re.Run(` + (function () { + console.log('instance: ' + web3.version.client); + console.log(' datadir: ' + admin.datadir); + console.log("coinbase: " + eth.coinbase); + var ts = 1000 * eth.getBlock(eth.blockNumber).timestamp; + console.log("at block: " + eth.blockNumber + " (" + new Date(ts) + ")"); + })(); + `) if modules, err := self.supportedApis(); err == nil { loadedModules := make([]string, 0) for api, version := range modules { loadedModules = append(loadedModules, fmt.Sprintf("%s:%s", api, version)) } sort.Strings(loadedModules) - - self.re.Eval(fmt.Sprintf("var modules = '%s';", strings.Join(loadedModules, " "))) - self.re.Eval(`console.log(" modules: " + modules);`) + fmt.Println("modules:", strings.Join(loadedModules, " ")) } } @@ -305,12 +305,12 @@ func (js *jsre) apiBindings(f xeth.Frontend) error { utils.Fatalf("Error loading web3.js: %v", err) } - _, err = js.re.Eval("var web3 = require('web3');") + _, err = js.re.Run("var web3 = require('web3');") if err != nil { utils.Fatalf("Error requiring web3: %v", err) } - _, err = js.re.Eval("web3.setProvider(jeth)") + _, err = js.re.Run("web3.setProvider(jeth)") if err != nil { utils.Fatalf("Error setting web3 provider: %v", err) } @@ -329,13 +329,13 @@ func (js *jsre) apiBindings(f xeth.Frontend) error { } } - _, err = js.re.Eval(shortcuts) + _, err = js.re.Run(shortcuts) if err != nil { utils.Fatalf("Error setting namespaces: %v", err) } - js.re.Eval(`var GlobalRegistrar = eth.contract(` + registrar.GlobalRegistrarAbi + `); registrar = GlobalRegistrar.at("` + registrar.GlobalRegistrarAddr + `");`) + js.re.Run(`var GlobalRegistrar = eth.contract(` + registrar.GlobalRegistrarAbi + `); registrar = GlobalRegistrar.at("` + registrar.GlobalRegistrarAddr + `");`) return nil } @@ -454,8 +454,7 @@ func (self *jsre) parseInput(code string) { fmt.Println("[native] error", r) } }() - value, err := self.re.Run(code) - if err != nil { + if err := self.re.EvalAndPrettyPrint(code); err != nil { if ottoErr, ok := err.(*otto.Error); ok { fmt.Println(ottoErr.String()) } else { @@ -463,7 +462,6 @@ func (self *jsre) parseInput(code string) { } return } - self.printValue(value) } var indentCount = 0 @@ -482,10 +480,3 @@ func (self *jsre) setIndent() { self.ps1 += " " } } - -func (self *jsre) printValue(v interface{}) { - val, err := self.re.PrettyPrint(v) - if err == nil { - fmt.Printf("%v", val) - } -} diff --git a/cmd/geth/main.go b/cmd/geth/main.go index d5391801d..2dc3c438f 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -19,7 +19,6 @@ package main import ( "fmt" - "io" "io/ioutil" _ "net/http/pprof" "os" @@ -46,8 +45,6 @@ import ( "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/comms" - "github.com/mattn/go-colorable" - "github.com/mattn/go-isatty" ) const ( @@ -398,14 +395,6 @@ func run(ctx *cli.Context) { func attach(ctx *cli.Context) { utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name)) - // Wrap the standard output with a colorified stream (windows) - if isatty.IsTerminal(os.Stdout.Fd()) { - if pr, pw, err := os.Pipe(); err == nil { - go io.Copy(colorable.NewColorableStdout(), pr) - os.Stdout = pw - } - } - var client comms.EthereumClient var err error if ctx.Args().Present() { @@ -438,14 +427,6 @@ func attach(ctx *cli.Context) { func console(ctx *cli.Context) { utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name)) - // Wrap the standard output with a colorified stream (windows) - if isatty.IsTerminal(os.Stdout.Fd()) { - if pr, pw, err := os.Pipe(); err == nil { - go io.Copy(colorable.NewColorableStdout(), pr) - os.Stdout = pw - } - } - cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx) ethereum, err := eth.New(cfg) if err != nil { |