[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read a reply from the terminal
From: |
Dan Nicolaescu |
Subject: |
Re: read a reply from the terminal |
Date: |
Sat, 14 Jul 2007 17:34:34 -0700 |
Stefan Monnier <address@hidden> writes:
> > I trying to do: (send-string-to-terminal "\e[>0c") and read the string
> > that the terminal sends back. Can this be done reliably in elisp?
>
> Something like
>
> (let ((coding-system-for-read 'binary))
> (read-event ...))
>
> should give you what you want,
Thanks, that seems to do it.
Here's a patch. It works for me correctly for all the terminals that I
tried it on.
Any objection to putting this in?
*** xterm.el 13 Jun 2007 16:19:48 -0700 1.39
--- xterm.el 14 Jul 2007 17:06:05 -0700
***************
*** 400,406 ****
;; Do it!
(xterm-register-default-colors)
;; This recomputes all the default faces given the colors we've just set
up.
! (tty-set-up-initial-frame-faces)))
;; Set up colors, for those versions of xterm that support it.
(defvar xterm-standard-colors
--- 400,436 ----
;; Do it!
(xterm-register-default-colors)
;; This recomputes all the default faces given the colors we've just set
up.
! (tty-set-up-initial-frame-faces)
!
! ;; Try to turn on the modifyOtherKeys feature on modern xterms.
! ;; When it is turned on much more key bindings work: things like
! ;; C-. C-, etc.
! ;; To do that we need to find out if the current terminal supports
! ;; modifyOtherKeys. At this time only xterm does.
! (let ((coding-system-for-read 'binary)
! (chr nil)
! (str nil))
! ;; Try to find out the type of terminal by sending a "Secondary
! ;; Device Attributes (DA)" query.
! (send-string-to-terminal "\e[>0c")
!
! ;; The reply should be of the form: \e [ > NUMBER1 ; NUMBER2 ; NUMBER3 c
! (when (equal (read-event) ?\e)
! (when (equal (read-event) 91)
! (while (not (equal (setq chr (read-event)) ?c))
! (setq str (concat str (string chr))))
! (when (string-match ">[0-9]+;\\([0-9]+\\);[0-9]+" str)
! ;; NUMBER2 is the xterm version number, look for something
! ;; greater than 216, the version when modifyOtherKeys was
! ;; introduced.
! (when (>= (string-to-number
! (substring str (match-beginning 1) (match-end 1))) 216)
! ;; Make sure that the modifyOtherKeys state is restored when
! ;; suspending, resuming and exiting.
! (add-hook 'suspend-hook 'xterm-turn-off-modifyOtherKeys)
! (add-hook 'suspend-resume-hook 'xterm-turn-on-modifyOtherKeys)
! (add-hook 'kill-emacs-hook 'xterm-turn-off-modifyOtherKeys)
! (xterm-turn-on-modifyOtherKeys))))))))
;; Set up colors, for those versions of xterm that support it.
(defvar xterm-standard-colors
***************
*** 518,522 ****
--- 548,560 ----
;; right colors, so clear them.
(clear-face-cache)))
+ (defun xterm-turn-on-modifyOtherKeys ()
+ "Turn on the modifyOtherKeys feature of xterm."
+ (send-string-to-terminal "\e[>4;1m"))
+
+ (defun xterm-turn-off-modifyOtherKeys ()
+ "Turn off the modifyOtherKeys feature of xterm."
+ (send-string-to-terminal "\e[>4m"))
+
;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a
;;; xterm.el ends here
- read a reply from the terminal, Dan Nicolaescu, 2007/07/13
- Re: read a reply from the terminal, Eli Zaretskii, 2007/07/14
- Re: read a reply from the terminal, Stefan Monnier, 2007/07/14
- Re: read a reply from the terminal,
Dan Nicolaescu <=
- Re: read a reply from the terminal, Stefan Monnier, 2007/07/14
- Re: read a reply from the terminal, Andreas Schwab, 2007/07/15
- Re: read a reply from the terminal, Dan Nicolaescu, 2007/07/15
- Re: read a reply from the terminal, Eli Zaretskii, 2007/07/15
- Re: read a reply from the terminal, Dan Nicolaescu, 2007/07/15
- Re: read a reply from the terminal, Richard Stallman, 2007/07/15
- Re: read a reply from the terminal, Dan Nicolaescu, 2007/07/15
- Re: read a reply from the terminal, Johan Bockgård, 2007/07/14