Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jonny Schäfer
tubus
Commits
5286688d
Commit
5286688d
authored
Jan 06, 2016
by
Jonny Schäfer
Browse files
readline replacement
parent
bd104fc3
Changes
3
Hide whitespace changes
Inline
Side-by-side
cli.go
View file @
5286688d
...
...
@@ -47,7 +47,7 @@ func cliHome() {
// cliPrompt reads a line from stdin
func
cliPrompt
()
string
{
cliHome
()
read
,
err
:=
r
ead
l
ine
()
read
,
err
:=
termR
ead
L
ine
()
if
err
!=
nil
{
logicQuit
(
"EOF"
)
}
...
...
readline.go
deleted
100644 → 0
View file @
bd104fc3
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?"
)
}
term.go
0 → 100644
View file @
5286688d
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
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment