Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kbhit() #438

Merged
merged 1 commit into from
Sep 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions irteus/irtutil.l
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,38 @@ t
)
,flag))))


;;; from termbits.h
(defcstruct termios
(c_iflag :integer)
(c_oflag :integer)
(c_cflag :integer)
(c_lflag :integer)
(c_line :char)
(c_cc :char 19)
(c_ispeed :integer)
(c_ospeed :integer))

(defconstant TCSANOW 0)
(defconstant TCSADRAIN 1)
(defconstant TCSAFLUSH 2)
(defconstant ICANON #0x0002)
(defun kbhit ()
"Checks the console for a keystroke. retuns keycode value if a key has been pressed, otherwise it returns nil. Note that this does not work well on Emacs Shell mode, run EusLisp program from terminal shell."
(let ((attr-orig (unix::tcgetattr 0))
(buf "0")
attr ret)
(setq attr (copy-list attr-orig))
;; 1000 1010 0011 1011
(setf (termios-c_lflag attr) (logand (termios-c_lflag attr) (lognot ICANON)))
(unix::tcsetattr 0 TCSANOW attr)
(when (= (unix::select-read-fd 1 0.001) 1)
(unix::uread 0 buf 1)
(setq ret (elt buf 0)))
(unix::tcsetattr 0 TCSANOW attr-orig)
ret))
;;

;; piped fork returning result as list
(defun piped-fork-returns-list (cmd &optional args)
"piped fork returning result as list"
Expand Down