1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-07 08:15:48 +02:00

Reply to a DSR(5) request for ready status.

When TM Terminal sees this:

   ESC [ 5 n

It replies indicating that the terminal is OK:

   ESC [ 0 n

This escape sequence is documented here:

   8.3.35 DSR - DEVICE STATUS REPORT.  Page 40.
   http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

Motivation: I'd like to switch winpty from using DSR(6) to DSR(5) as its
ESC flushing command.  When winpty sees a bare ESC, it can either
synthesize a VK_ESCAPE keypress or wait to see if the ESC was part of some
other escape sequence.  It tries to deal with this by generating a DSR(6),
which should flush out the remaining bytes of the sequence, if there are
any.  DSR(6) is suboptimal, though, because the reply collides with the
sequence some terminals use for F3 with a modifier:

    ESC [ nn ; nn R

DSR(5) generates a DSR(0) reply, which does not have the same problem.

DSR(5) is supported by all the terminal emulators I tested, including
xterm, rxvt, rxvt-unicode, gnome-terminal, konsole, putty, mintty,
OS X's Terminal.app, and IntelliJ/jediterm.

Signed-off-by: Ryan Prichard <ryan.prichard@gmail.com>
This commit is contained in:
Ryan Prichard 2015-11-30 20:31:00 -06:00
parent cd6c2f0219
commit 44f0083f72

View file

@ -974,23 +974,29 @@ public class VT100Emulator implements ControlListener {
/**
* This method responds to an ANSI Device Status Report (DSR) command from
* the remote endpoint requesting the cursor position. Requests for other
* kinds of status are ignored.
* the remote endpoint requesting the ready status or the cursor position.
* Requests for other kinds of status are ignored.
*/
private void processAnsiCommand_n() {
// Do nothing if the numeric parameter was not 6 (which means report cursor
// position).
String reply;
if (getAnsiParameter(0) != 6)
if (getAnsiParameter(0) == 5) {
// Report that the terminal is ready and has no malfunctions.
reply = "\u001b[0n"; //$NON-NLS-1$
} else if (getAnsiParameter(0) == 6) {
// Send the ANSI cursor position (which is 1-based) to the remote
// endpoint.
reply = "\u001b[" + (relativeCursorLine() + 1) + ";" + //$NON-NLS-1$ //$NON-NLS-2$
(getCursorColumn() + 1) + "R"; //$NON-NLS-1$
} else {
// Do nothing if the numeric parameter was not 5 or 6.
return;
// Send the ANSI cursor position (which is 1-based) to the remote endpoint.
String positionReport = "\u001b[" + (relativeCursorLine() + 1) + ";" + //$NON-NLS-1$ //$NON-NLS-2$
(getCursorColumn() + 1) + "R"; //$NON-NLS-1$
}
try {
terminal.getOutputStream().write(positionReport.getBytes("ISO-8859-1")); //$NON-NLS-1$
terminal.getOutputStream().write(reply.getBytes("ISO-8859-1")); //$NON-NLS-1$
terminal.getOutputStream().flush();
} catch (IOException ex) {
Logger.log("Caught IOException!"); //$NON-NLS-1$