This commit is contained in:
obscuren 2014-05-21 23:36:55 +02:00
parent 941e0ba60a
commit 3f5b348451

View File

@ -1,17 +1,37 @@
package main package main
// #cgo darwin CFLAGS: -I/usr/local/opt/readline/include
// #cgo darwin LDFLAGS: -L/usr/local/opt/readline/lib
// #cgo LDFLAGS: -lreadline // #cgo LDFLAGS: -lreadline
// #include <stdio.h> // #include <stdio.h>
// #include <stdlib.h> // #include <stdlib.h>
// #include <readline/readline.h> // #include <readline/readline.h>
// #include <readline/history.h> // #include <readline/history.h>
import "C" import "C"
import ( import (
"os"
"os/signal"
"strings" "strings"
"syscall"
"unsafe" "unsafe"
) )
func initReadLine() {
C.rl_catch_sigwinch = 0
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGWINCH)
go func() {
for sig := range c {
switch sig {
case syscall.SIGWINCH:
C.rl_resize_terminal()
default:
}
}
}()
}
func readLine(prompt *string) *string { func readLine(prompt *string) *string {
var p *C.char var p *C.char
@ -59,6 +79,7 @@ func (self *JSRepl) setIndent() {
} }
func (self *JSRepl) read() { func (self *JSRepl) read() {
initReadLine()
L: L:
for { for {
switch result := readLine(&self.prompt); true { switch result := readLine(&self.prompt); true {