From 44f0083f7205961d7cd4af7328ab25b6dd4688bd Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 30 Nov 2015 20:31:00 -0600 Subject: [PATCH] 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 --- .../terminal/emulator/VT100Emulator.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java index 7c201c7e8a2..5e6817a0979 100644 --- a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java +++ b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java @@ -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$