Advertisement
logicmoo

Untitled

Oct 23rd, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.83 KB | None | 0 0
  1. (require :sb-posix)
  2. (import '(sb-posix:termios sb-posix:termios-lflag sb-posix:termios-cc
  3. sb-posix:tcgetattr sb-posix:tcsetattr
  4. sb-posix:tcsadrain
  5. sb-posix:icanon sb-posix:echo sb-posix:echoe sb-posix:echok
  6. sb-posix:echonl sb-posix:vmin sb-posix:vtime))
  7.  
  8. #| What "less" does:
  9. s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
  10. s.c_oflag |= (OPOST|ONLCR|TAB3);
  11. s.c_oflag &= ~(OCRNL|ONOCR|ONLRET);
  12. s.c_cc[VMIN] = 1;
  13. s.c_cc[VTIME] = 0;
  14. |#
  15. (defun read-char-no-echo-cbreak (&optional (stream *query-io*))
  16. (let ((old (tcgetattr 0))
  17. (new (tcgetattr 0))
  18. (bits (logior icanon echo echoe echok echonl)))
  19. (unwind-protect
  20. (progn
  21. (setf (termios-lflag new) (logandc2 (termios-lflag old) bits)
  22. (aref (termios-cc new) vmin) 1
  23. (aref (termios-cc new) vtime) 0)
  24. (tcsetattr 0 tcsadrain new)
  25. (read-char stream))
  26. (tcsetattr 0 tcsadrain old))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement