2015-09-20 18:14:29 +03:00
|
|
|
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
|
2015-09-21 08:13:30 +03:00
|
|
|
case KeyEsc:
|
|
|
|
|
2015-09-20 18:14:29 +03:00
|
|
|
}
|
|
|
|
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()
|
|
|
|
}
|