aboutsummaryrefslogtreecommitdiffstats
path: root/ethereum
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-19 19:04:31 +0800
committerobscuren <geffobscura@gmail.com>2014-05-19 19:04:31 +0800
commit16421106d47efb65331ed9f0499f12038158cbf1 (patch)
tree2a525671c3022b9465c009dfe0c8979f9389c53c /ethereum
parent3b7707c3fd2f99ee1019b8214cba1784af519f53 (diff)
downloadgo-tangerine-16421106d47efb65331ed9f0499f12038158cbf1.tar
go-tangerine-16421106d47efb65331ed9f0499f12038158cbf1.tar.gz
go-tangerine-16421106d47efb65331ed9f0499f12038158cbf1.tar.bz2
go-tangerine-16421106d47efb65331ed9f0499f12038158cbf1.tar.lz
go-tangerine-16421106d47efb65331ed9f0499f12038158cbf1.tar.xz
go-tangerine-16421106d47efb65331ed9f0499f12038158cbf1.tar.zst
go-tangerine-16421106d47efb65331ed9f0499f12038158cbf1.zip
Added multi-line support
Diffstat (limited to 'ethereum')
-rw-r--r--ethereum/javascript_console.go5
-rw-r--r--ethereum/repl_darwin.go37
-rw-r--r--ethereum/repl_windows.go2
3 files changed, 35 insertions, 9 deletions
diff --git a/ethereum/javascript_console.go b/ethereum/javascript_console.go
index 884b9a629..1e1ae0e48 100644
--- a/ethereum/javascript_console.go
+++ b/ethereum/javascript_console.go
@@ -101,14 +101,15 @@ func (self *JSRE) Run(code string) (otto.Value, error) {
type JSRepl struct {
re *JSRE
+
+ prompt string
}
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
- return &JSRepl{re: NewJSRE(ethereum)}
+ return &JSRepl{re: NewJSRE(ethereum), prompt: "> "}
}
func (self *JSRepl) Start() {
- fmt.Println("Eth JavaScript console")
self.read()
}
diff --git a/ethereum/repl_darwin.go b/ethereum/repl_darwin.go
index b6de190e4..483d4cedf 100644
--- a/ethereum/repl_darwin.go
+++ b/ethereum/repl_darwin.go
@@ -6,7 +6,11 @@ package main
// #include <readline/readline.h>
// #include <readline/history.h>
import "C"
-import "unsafe"
+
+import (
+ "strings"
+ "unsafe"
+)
func readLine(prompt *string) *string {
var p *C.char
@@ -37,19 +41,40 @@ func addHistory(s string) {
C.free(unsafe.Pointer(p))
}
-func (self *JSRepl) read() {
- prompt := "eth >>> "
+var indentCount = 0
+var str = ""
+
+func (self *JSRepl) setIndent() {
+ open := strings.Count(str, "{")
+ open += strings.Count(str, "(")
+ closed := strings.Count(str, "}")
+ closed += strings.Count(str, ")")
+ indentCount = open - closed
+ if indentCount <= 0 {
+ self.prompt = "> "
+ } else {
+ self.prompt = strings.Join(make([]string, indentCount*2), "..")
+ self.prompt += " "
+ }
+}
+func (self *JSRepl) read() {
L:
for {
- switch result := readLine(&prompt); true {
+ switch result := readLine(&self.prompt); true {
case result == nil:
break L //exit loop
case *result != "": //ignore blank lines
- addHistory(*result) //allow user to recall this line
+ str += *result + "\n"
+
+ self.setIndent()
+
+ if indentCount <= 0 {
+ addHistory(str) //allow user to recall this line
- self.parseInput(*result)
+ self.parseInput(str)
+ }
}
}
}
diff --git a/ethereum/repl_windows.go b/ethereum/repl_windows.go
index c65bb1cb4..c42fd6e6a 100644
--- a/ethereum/repl_windows.go
+++ b/ethereum/repl_windows.go
@@ -9,7 +9,7 @@ import (
func (self *JSRepl) read() {
reader := bufio.NewReader(os.Stdin)
for {
- fmt.Printf("eth >>> ")
+ fmt.Printf(self.prompt)
str, _, err := reader.ReadLine()
if err != nil {
fmt.Println("Error reading input", err)