[terminal] IJPL-156363 Support multiline commands if bracketed mode is supported by shell

Merge-request: IJ-MR-136404
Merged-by: Vladimir Shefer <Vladimir.Shefer@jetbrains.com>

GitOrigin-RevId: eeab47adac254c9316b1b01ad7e924729796f2c7
This commit is contained in:
Vladimir Shefer
2024-06-11 15:32:59 +00:00
committed by intellij-monorepo-bot
parent 08dac98166
commit c99beee36c
2 changed files with 25 additions and 1 deletions

View File

@@ -231,8 +231,12 @@ internal class ShellCommandExecutionManager(private val session: BlockTerminalSe
}
private fun doSendCommandToExecute(shellCommand: String, isGenerator: Boolean) {
var adjustedCommand = shellCommand;
if (session.model.isBracketedPasteMode && (adjustedCommand.contains("\n") || adjustedCommand.contains(System.lineSeparator()))) {
adjustedCommand = bracketed(adjustedCommand)
}
// in the IDE we use '\n' line separator, but Windows requires '\r\n'
val adjustedCommand = shellCommand.replace("\n", System.lineSeparator())
adjustedCommand = adjustedCommand.replace("\n", System.lineSeparator())
session.terminalStarterFuture.thenAccept { starter ->
starter ?: return@thenAccept
val clearPrompt = createClearPromptShortcut(starter.terminal)
@@ -364,6 +368,10 @@ internal class ShellCommandExecutionManager(private val session: BlockTerminalSe
}
}
}
private fun bracketed(command: String): String {
return "\u001b[200~$command\u001b[201~"
}
}
}

View File

@@ -22,6 +22,7 @@ import org.jetbrains.plugins.terminal.exp.*
import org.jetbrains.plugins.terminal.exp.util.TerminalSessionTestUtil
import org.jetbrains.plugins.terminal.exp.util.TerminalSessionTestUtil.toCommandLine
import org.junit.Assert
import org.junit.Assume
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -64,6 +65,21 @@ internal class BlockTerminalCommandExecutionTest(private val shellPath: Path) {
Assert.assertEquals(expected, actual)
}
@Test
fun `multiline commands with bracketed mode`() {
val (session, view) = startSessionAndCreateView()
Assume.assumeTrue(session.model.isBracketedPasteMode)
val expected = listOf(
CommandResult("echo 1\necho 2", "1\n2")
)
expected.forEach {
session.commandExecutionManager.sendCommandToExecute(it.command)
}
awaitBlocksFinalized(view.outputView.controller.outputModel, expected.size)
val actual = view.outputView.controller.outputModel.collectCommandResults()
Assert.assertEquals(expected, actual)
}
@Test
fun `shell integration sends correct events`() {
val actual = mutableListOf<String?>()