2021-04-01 16:17:13 -04:00
|
|
|
package key
|
|
|
|
|
2021-04-07 16:26:05 -04:00
|
|
|
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
|
|
|
)
|
|
|
|
|
2021-04-13 14:54:44 -04:00
|
|
|
// IsAscii Is this an ASCII character?
|
2021-04-02 19:24:20 -04:00
|
|
|
func IsAscii(char rune) bool {
|
2021-04-07 16:26:05 -04:00
|
|
|
return char <= unicode.MaxASCII
|
2021-04-01 16:17:13 -04:00
|
|
|
}
|
|
|
|
|
2021-04-13 14:54:44 -04:00
|
|
|
// IsCtrl Is this an ASCII ctrl character?
|
2021-04-01 16:17:13 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-04-13 14:54:44 -04:00
|
|
|
// Ctrl Return the input code of a Ctrl-key chord.
|
2021-04-01 16:17:13 -04:00
|
|
|
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
|
|
|
|
}
|
2021-04-07 16:26:05 -04:00
|
|
|
|
2021-04-13 14:54:44 -04:00
|
|
|
// IsSeparator Is the character a general token separator type?
|
2021-04-07 16:26:05 -04:00
|
|
|
func IsSeparator(char rune) bool {
|
|
|
|
return unicode.IsPunct(char) || unicode.IsSpace(char)
|
2021-04-16 11:46:16 -04:00
|
|
|
}
|