initrd/tty.go

36 lines
591 B
Go
Raw Permalink Normal View History

package main
import (
"golang.org/x/sys/unix"
)
type tty struct {
fd int
termios *unix.Termios
}
2024-01-21 14:26:00 +00:00
func newTTY(fd uintptr) *tty {
termios, _ := unix.IoctlGetTermios(int(fd), unix.TCGETS)
return &tty{int(fd), termios}
}
func (t *tty) EchoOff() {
2024-01-21 14:26:00 +00:00
if t.termios == nil {
return
}
2024-01-21 14:26:00 +00:00
newState := *t.termios
newState.Lflag &^= unix.ECHO
newState.Lflag |= unix.ICANON | unix.ISIG
newState.Iflag |= unix.ICRNL
unix.IoctlSetTermios(t.fd, unix.TCSETS, &newState)
}
func (t *tty) Restore() {
2024-01-21 14:26:00 +00:00
if t.termios == nil {
return
}
2024-01-21 14:26:00 +00:00
unix.IoctlSetTermios(t.fd, unix.TCSETS, t.termios)
}