diff options
author | zelig <viktor.tron@gmail.com> | 2014-06-25 23:20:26 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2014-06-25 23:20:26 +0800 |
commit | 08de13a57b4a59fc4a8ccf9e707ede57cc380a0c (patch) | |
tree | 94bd0dc4887284c6e0ae57a7b40825dae52eee0e /ethereum/repl.go | |
parent | 6f09a3e8200ba2eeeeb296141d6644d04078a9c4 (diff) | |
parent | 9654b809120d1cc3c53ffe268fe47869ef0dc0a8 (diff) | |
download | go-tangerine-08de13a57b4a59fc4a8ccf9e707ede57cc380a0c.tar.gz go-tangerine-08de13a57b4a59fc4a8ccf9e707ede57cc380a0c.tar.zst go-tangerine-08de13a57b4a59fc4a8ccf9e707ede57cc380a0c.zip |
merge upstream
Diffstat (limited to 'ethereum/repl.go')
-rw-r--r-- | ethereum/repl.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/ethereum/repl.go b/ethereum/repl.go index a95d73300..c162c78b0 100644 --- a/ethereum/repl.go +++ b/ethereum/repl.go @@ -1,10 +1,15 @@ package main import ( + "bufio" "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethpub" + "github.com/ethereum/eth-go/ethutil" "github.com/obscuren/otto" + "io" + "os" + "path" ) type Repl interface { @@ -16,20 +21,40 @@ type JSRepl struct { re *JSRE prompt string + + history *os.File } func NewJSRepl(ethereum *eth.Ethereum) *JSRepl { - return &JSRepl{re: NewJSRE(ethereum), prompt: "> "} + hist, err := os.OpenFile(path.Join(ethutil.Config.ExecPath, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm) + if err != nil { + panic(err) + } + + return &JSRepl{re: NewJSRE(ethereum), prompt: "> ", history: hist} } func (self *JSRepl) Start() { logger.Infoln("init JS Console") + reader := bufio.NewReader(self.history) + for { + line, err := reader.ReadString('\n') + if err != nil && err == io.EOF { + break + } else if err != nil { + fmt.Println("error reading history", err) + break + } + + addHistory(line[:len(line)-1]) + } self.read() } func (self *JSRepl) Stop() { self.re.Stop() logger.Infoln("exit JS Console") + self.history.Close() } func (self *JSRepl) parseInput(code string) { |