gilo/key/key.go

43 lines
832 B
Go
Raw Normal View History

2021-04-01 16:17:13 -04:00
package key
import "unicode"
2021-04-01 16:17:13 -04:00
// ----------------------------------------------------------------------------
// !Terminal Input Escape Code Sequences
// ----------------------------------------------------------------------------
const (
2021-04-06 16:37:58 -04:00
Backspace = '\x7f'
Esc = '\x1b'
2021-04-01 20:26:40 -04:00
Enter = '\r'
2021-04-01 16:17:13 -04:00
)
// Is this an ASCII character?
2021-04-02 19:24:20 -04:00
func IsAscii(char rune) bool {
return char <= unicode.MaxASCII
2021-04-01 16:17:13 -04:00
}
// Is this an ASCII ctrl character?
func IsCtrl(char rune) bool {
2021-04-02 19:24:20 -04:00
if !IsAscii(char) {
2021-04-01 16:17:13 -04:00
return false
}
return char == 0x7f || char < 0x20
}
// Return the input code of a Ctrl-key chord.
func Ctrl(char rune) rune {
2021-04-02 19:24:20 -04:00
if !IsAscii(char) {
2021-04-01 16:17:13 -04:00
return 0
}
ch := char & 0x1f
return ch
}
// Is the character a general token separator type?
func IsSeparator(char rune) bool {
return unicode.IsPunct(char) || unicode.IsSpace(char)
}