aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-10 21:31:54 +0800
committerFelix Lange <fjl@twurst.com>2015-03-10 21:31:54 +0800
commit0395c174ca5221dd936c19143ced454dac56d54a (patch)
treead2dde31bd45de9022b96669d4a1db8c6571ff68 /cmd
parent80985f97da8174576ee227909035a364af2fd6c9 (diff)
downloaddexon-0395c174ca5221dd936c19143ced454dac56d54a.tar.gz
dexon-0395c174ca5221dd936c19143ced454dac56d54a.tar.zst
dexon-0395c174ca5221dd936c19143ced454dac56d54a.zip
cmd/ethereum: fix line editing setup and history
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ethereum/js.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/cmd/ethereum/js.go b/cmd/ethereum/js.go
index de73e83a2..5432fb9b1 100644
--- a/cmd/ethereum/js.go
+++ b/cmd/ethereum/js.go
@@ -63,6 +63,7 @@ type jsre struct {
ethereum *eth.Ethereum
xeth *xeth.XEth
ps1 string
+ atexit func()
prompter
}
@@ -77,11 +78,13 @@ func newJSRE(ethereum *eth.Ethereum) *jsre {
js.prompter = dumbterm{bufio.NewReader(os.Stdin)}
} else {
lr := liner.NewLiner()
- lr.SetCtrlCAborts(true)
- defer lr.Close()
js.withHistory(func(hist *os.File) { lr.ReadHistory(hist) })
- defer js.withHistory(func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) })
+ lr.SetCtrlCAborts(true)
js.prompter = lr
+ js.atexit = func() {
+ js.withHistory(func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) })
+ lr.Close()
+ }
}
return js
}
@@ -100,7 +103,6 @@ func (self *jsre) UnlockAccount(addr []byte) bool {
}
// TODO: allow retry
if err := self.ethereum.AccountManager().Unlock(addr, pass); err != nil {
- fmt.Println("Unlocking failed: ", err)
return false
} else {
fmt.Println("Account is now unlocked for this session.")
@@ -127,7 +129,7 @@ func (self *jsre) interactive() {
for {
input, err := self.Prompt(self.ps1)
if err != nil {
- return
+ break
}
if input == "" {
continue
@@ -136,7 +138,7 @@ func (self *jsre) interactive() {
self.setIndent()
if indentCount <= 0 {
if input == "exit" {
- return
+ break
}
hist := str[:len(str)-1]
self.AppendHistory(hist)
@@ -144,6 +146,9 @@ func (self *jsre) interactive() {
str = ""
}
}
+ if self.atexit != nil {
+ self.atexit()
+ }
}
func (self *jsre) withHistory(op func(*os.File)) {