gilo/internal/key/key.go

37 lines
657 B
Go
Raw Normal View History

2021-04-01 16:17:13 -04:00
package key
// ----------------------------------------------------------------------------
// !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 {
2021-04-01 16:17:13 -04:00
return char < 0x80
}
// 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
}