Add modules
This commit is contained in:
parent
1b94f7fa94
commit
0b05522b05
1
internal/editor/editor.go
Normal file
1
internal/editor/editor.go
Normal file
@ -0,0 +1 @@
|
||||
package editor
|
29
internal/rune/rune.go
Normal file
29
internal/rune/rune.go
Normal file
@ -0,0 +1,29 @@
|
||||
package rune
|
||||
|
||||
func isAscii(char rune) bool {
|
||||
ord := int(char)
|
||||
|
||||
return ord < 0x80
|
||||
}
|
||||
|
||||
func IsCtrl(char rune) bool {
|
||||
if !isAscii(char) {
|
||||
return false
|
||||
}
|
||||
|
||||
ord := int(char)
|
||||
|
||||
return ord == 0x7f || ord < 0x20
|
||||
}
|
||||
|
||||
// Return the input code of a Ctrl-key chord.
|
||||
func Ctrl(char rune) rune {
|
||||
ord := int(char)
|
||||
raw := ord & 0x1f
|
||||
|
||||
if !IsCtrl(rune(raw)) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return rune(raw)
|
||||
}
|
32
internal/terminal/terminal.go
Normal file
32
internal/terminal/terminal.go
Normal file
@ -0,0 +1,32 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang.org/x/term"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Put the terminal in raw mode
|
||||
func RawOn() *term.State {
|
||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return oldState
|
||||
}
|
||||
|
||||
// Restore the terminal to canonical mode
|
||||
func RawOff(oldState *term.State) {
|
||||
err := term.Restore(int(os.Stdin.Fd()), oldState)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Print a formatted string to stdout, with CRLF line endings for proper terminal formatting
|
||||
func OutLn(format string, a ...interface{}) {
|
||||
formatted := fmt.Sprintf(format, a...)
|
||||
|
||||
fmt.Printf("%s\r\n", formatted)
|
||||
}
|
Loading…
Reference in New Issue
Block a user