console: send \r on Enter key pressed for PTY based processes (GO-9805)
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Wed, 12 Aug 2020 12:24:50 +0000 (15:24 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 12 Aug 2020 12:25:15 +0000 (12:25 +0000)
GitOrigin-RevId: 2be730904ed44bd137d3e9848ef2b79da454faa8

platform/lang-impl/intellij.platform.lang.impl.iml
platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewRunningState.java

index 9ea54984fbe5802b2ecfb49fc32984882060fbd3..ee24b60172a38133295ff2a25d63d5831ad6b9b6 100644 (file)
@@ -49,5 +49,6 @@
     <orderEntry type="library" name="fastutil-min" level="project" />
     <orderEntry type="library" name="Trove4j" level="project" />
     <orderEntry type="library" name="Log4J" level="project" />
+    <orderEntry type="library" name="pty4j" level="project" />
   </component>
 </module>
\ No newline at end of file
index a0c5306a328da9a9ba8ad46a3cc2d65a494750f3..6fcd42a0cc657586f2f330c78786cef8dd1a0c77 100644 (file)
@@ -1,11 +1,14 @@
 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package com.intellij.execution.impl;
 
+import com.google.common.base.Ascii;
 import com.intellij.execution.ExecutionBundle;
 import com.intellij.execution.process.*;
 import com.intellij.execution.ui.ConsoleViewContentType;
 import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.vfs.encoding.EncodingManager;
+import com.pty4j.PtyProcess;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.annotations.TestOnly;
@@ -106,10 +109,23 @@ public class ConsoleViewRunningState extends ConsoleState {
     if (myUserInputWriter == null) {
       throw new IOException(ExecutionBundle.message("no.user.process.input.error.message"));
     }
-    myUserInputWriter.write(input);
+    char enterKeyCode = getEnterKeyCode();
+    String inputToSend = input.replace((char)Ascii.LF, enterKeyCode);
+    myUserInputWriter.write(inputToSend);
     myUserInputWriter.flush();
   }
 
+  private char getEnterKeyCode() {
+    if (SystemInfo.isWindows &&
+        myProcessHandler instanceof OSProcessHandler &&
+        ((OSProcessHandler)myProcessHandler).getProcess() instanceof PtyProcess) {
+      // pty4j expects \r as Enter key code
+      // https://github.com/JetBrains/pty4j/blob/0.9.4/test/com/pty4j/PtyTest.java#L54
+      return Ascii.CR;
+    }
+    return Ascii.LF;
+  }
+
   @NotNull
   @Override
   public ConsoleState attachTo(@NotNull final ConsoleViewImpl console, final @NotNull ProcessHandler processHandler) {