gilo/key/key.go
Timothy Warren f78bbdabb2
Some checks failed
timw4mail/gilo/pipeline/head There was a failure building this commit
Up to step 154 in Kilo tutorial (chapter 7)
2021-04-07 16:26:05 -04:00

43 lines
832 B
Go

package key
import "unicode"
// ----------------------------------------------------------------------------
// !Terminal Input Escape Code Sequences
// ----------------------------------------------------------------------------
const (
Backspace = '\x7f'
Esc = '\x1b'
Enter = '\r'
)
// Is this an ASCII character?
func IsAscii(char rune) bool {
return char <= unicode.MaxASCII
}
// Is this an ASCII ctrl character?
func IsCtrl(char rune) bool {
if !IsAscii(char) {
return false
}
return char == 0x7f || char < 0x20
}
// Return the input code of a Ctrl-key chord.
func Ctrl(char rune) rune {
if !IsAscii(char) {
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)
}