Skip to content

Commit

Permalink
feat: AIX support
Browse files Browse the repository at this point in the history
  • Loading branch information
secDre4mer committed Dec 12, 2024
1 parent d0803d4 commit 4d7e5a0
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions v3/termutil/term_aix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build aix

package termutil

import (
"os"
"syscall"

"golang.org/x/sys/unix"
)

var (
tty *os.File

unlockSignals = []os.Signal{
os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL,
}
)

func init() {
var err error
tty, err = os.Open("/dev/tty")
if err != nil {
tty = os.Stdin
}
}

// TerminalWidth returns width of the terminal.
func TerminalWidth() (int, error) {
_, width, err := TerminalSize()
return width, err
}

// TerminalSize returns size of the terminal.
func TerminalSize() (int, int, error) {
w, err := unix.IoctlGetWinsize(int(tty.Fd()), syscall.TIOCGWINSZ)
if err != nil {
return 0, 0, err
}
return int(w.Row), int(w.Col), nil
}

var oldState unix.Termios

func lockEcho() error {
fd := int(tty.Fd())
currentState, err := unix.IoctlGetTermios(fd, unix.TCGETS)
if err != nil {
return err
}

oldState = *currentState
newState := oldState
newState.Lflag &^= syscall.ECHO
newState.Lflag |= syscall.ICANON | syscall.ISIG
newState.Iflag |= syscall.ICRNL
if err := unix.IoctlSetTermios(fd, unix.TCSETS, &newState); err != nil {
return err
}
return nil
}

func unlockEcho() (err error) {
fd := int(tty.Fd())
if err := unix.IoctlSetTermios(fd, unix.TCSETS, &oldState); err != nil {
return err
}
return
}

0 comments on commit 4d7e5a0

Please sign in to comment.