aboutsummaryrefslogtreecommitdiffstats
path: root/ethereum/repl_darwin.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-17 21:15:46 +0800
committerobscuren <geffobscura@gmail.com>2014-05-17 21:15:46 +0800
commit770808ce0d44cadfedbe01694c836be2eaf0e82c (patch)
treef79310a0ea409805897d738f2c2fb7aa5d597355 /ethereum/repl_darwin.go
parent2ac292dc7ada20d64188b9d35f23600e4642021b (diff)
downloaddexon-770808ce0d44cadfedbe01694c836be2eaf0e82c.tar
dexon-770808ce0d44cadfedbe01694c836be2eaf0e82c.tar.gz
dexon-770808ce0d44cadfedbe01694c836be2eaf0e82c.tar.bz2
dexon-770808ce0d44cadfedbe01694c836be2eaf0e82c.tar.lz
dexon-770808ce0d44cadfedbe01694c836be2eaf0e82c.tar.xz
dexon-770808ce0d44cadfedbe01694c836be2eaf0e82c.tar.zst
dexon-770808ce0d44cadfedbe01694c836be2eaf0e82c.zip
Readline repl for linux & osx
Diffstat (limited to 'ethereum/repl_darwin.go')
-rw-r--r--ethereum/repl_darwin.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/ethereum/repl_darwin.go b/ethereum/repl_darwin.go
new file mode 100644
index 000000000..b6de190e4
--- /dev/null
+++ b/ethereum/repl_darwin.go
@@ -0,0 +1,55 @@
+package main
+
+// #cgo LDFLAGS: -lreadline
+// #include <stdio.h>
+// #include <stdlib.h>
+// #include <readline/readline.h>
+// #include <readline/history.h>
+import "C"
+import "unsafe"
+
+func readLine(prompt *string) *string {
+ var p *C.char
+
+ //readline allows an empty prompt(NULL)
+ if prompt != nil {
+ p = C.CString(*prompt)
+ }
+
+ ret := C.readline(p)
+
+ if p != nil {
+ C.free(unsafe.Pointer(p))
+ }
+
+ if ret == nil {
+ return nil
+ } //EOF
+
+ s := C.GoString(ret)
+ C.free(unsafe.Pointer(ret))
+ return &s
+}
+
+func addHistory(s string) {
+ p := C.CString(s)
+ C.add_history(p)
+ C.free(unsafe.Pointer(p))
+}
+
+func (self *JSRepl) read() {
+ prompt := "eth >>> "
+
+L:
+ for {
+ switch result := readLine(&prompt); true {
+ case result == nil:
+ break L //exit loop
+
+ case *result != "": //ignore blank lines
+ addHistory(*result) //allow user to recall this line
+
+ self.parseInput(*result)
+ }
+ }
+}