mirror of https://github.com/chzyer/readline.git
45 lines
798 B
Go
45 lines
798 B
Go
package readline
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
)
|
|
|
|
// IsTerminal returns true if the given file descriptor is a terminal.
|
|
func IsTerminal(fd int) bool {
|
|
return terminal.IsTerminal(fd)
|
|
}
|
|
|
|
func MakeRaw(fd int) (*terminal.State, error) {
|
|
return terminal.MakeRaw(fd)
|
|
}
|
|
|
|
func Restore(fd int, state *terminal.State) error {
|
|
return terminal.Restore(fd, state)
|
|
}
|
|
|
|
func IsPrintable(key rune) bool {
|
|
isInSurrogateArea := key >= 0xd800 && key <= 0xdbff
|
|
return key >= 32 && !isInSurrogateArea
|
|
}
|
|
|
|
func prefixKey(r rune) rune {
|
|
switch r {
|
|
case 'b':
|
|
r = MetaPrev
|
|
case 'f':
|
|
r = MetaNext
|
|
case 'd':
|
|
r = MetaDelete
|
|
}
|
|
return r
|
|
}
|
|
|
|
func Debug(o ...interface{}) {
|
|
f, _ := os.OpenFile("debug.tmp", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
|
fmt.Fprintln(f, o...)
|
|
f.Close()
|
|
}
|