18 BRKINT = tcflag_t (0000002);
19 ICRNL = tcflag_t (0000400);
20 INPCK = tcflag_t (0000020);
21 ISTRIP = tcflag_t (0000040);
22 IXON = tcflag_t (0002000);
23 OPOST = tcflag_t (0000001);
24 CS8 = tcflag_t (0000060);
25 ECHO = tcflag_t (0000010);
26 ICANON = tcflag_t (0000002);
27 IEXTEN = tcflag_t (0100000);
28 ISIG = tcflag_t (0000001);
35 c_iflag, c_oflag, c_cflag, c_lflag tcflag_t;
38 c_ispeed, c_ospeed speed_t
49 ttyfd uintptr = 0 // STDIN_FILENO
52 func Ttyfd(fd uintptr) {
56 func getTermios (dst *termios) error {
57 r1, _, errno := syscall.Syscall (syscall.SYS_IOCTL,
58 uintptr (ttyfd), uintptr (TCGETS),
59 uintptr (unsafe.Pointer (dst)));
61 if err := os.NewSyscallError ("SYS_IOCTL", errno); errno!=0 && err != nil {
66 // return errors.New("Error")
72 func setTermios (src *termios) error {
73 r1, _, errno := syscall.Syscall (syscall.SYS_IOCTL,
74 uintptr (ttyfd), uintptr (TCSETS),
75 uintptr (unsafe.Pointer (src)));
77 if err := os.NewSyscallError ("SYS_IOCTL", errno); errno!=0 &&err != nil {
82 return errors.New ("Error")
88 func tty_raw () error {
91 raw.c_iflag &= ^(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
92 raw.c_oflag &= ^(OPOST);
94 raw.c_lflag &= ^(ECHO | ICANON | IEXTEN | ISIG);
99 if err := setTermios (&raw); err != nil { return err }
110 if err != nil { fmt.Printf ("SetRaw Error: %v\n",err) }
113 if err = getTermios (&orig_termios); err != nil { return }
116 // err = setTermios (&orig_termios)
119 if err = tty_raw (); err != nil { return }
120 //if err = screenio (); err != nil { return }