Commit 5286688d authored by Jonny Schäfer's avatar Jonny Schäfer
Browse files

readline replacement

parent bd104fc3
...@@ -47,7 +47,7 @@ func cliHome() { ...@@ -47,7 +47,7 @@ func cliHome() {
// cliPrompt reads a line from stdin // cliPrompt reads a line from stdin
func cliPrompt() string { func cliPrompt() string {
cliHome() cliHome()
read, err := readline() read, err := termReadLine()
if err != nil { if err != nil {
logicQuit("EOF") logicQuit("EOF")
} }
......
package main
// This file uses cgo. The following comment block contains c code, that
// is actually in use. Do not add newlines above the import statement!
// See cgo manual for additional information.
/*
#cgo LDFLAGS: -lreadline
#include <stdio.h>
#include <stdlib.h>
#include <readline/readline.h>
#include <readline/history.h>
char* readempty() {
return readline("");
}
*/
import "C"
import (
"fmt"
"unsafe"
)
func readline() (string, error) {
cline := C.readempty()
if cline != nil {
gline := C.GoString(cline)
C.free(unsafe.Pointer(cline))
return gline, nil
}
return "", fmt.Errorf("EOF?")
}
package main
import (
"golang.org/x/crypto/ssh/terminal"
"io"
"os"
)
var (
termTerminal *terminal.Terminal
)
func init() {
stdio := struct {
io.Reader
io.Writer
}{
os.Stdin,
os.Stdout,
}
_, err := terminal.MakeRaw(int(os.Stdin.Fd()))
errorCare(err)
termTerminal = terminal.NewTerminal(stdio, "")
}
// termReadLine reads a line from stdin
func termReadLine() (string, error) {
return termTerminal.ReadLine()
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment