[terminal] IJPL-156116 Support PowerShell on Unix

GitOrigin-RevId: f4db8b4213e2d379eece73a2f23504bc5750c60f
This commit is contained in:
Vladimir Shefer
2024-06-04 16:36:55 +02:00
committed by intellij-monorepo-bot
parent b9ff335cec
commit 11b51897da
5 changed files with 22 additions and 7 deletions

View File

@@ -28,6 +28,8 @@
description="Enable new terminal for PowerShell on Windows 11"/>
<registryKey key="terminal.new.ui.powershell.win10" defaultValue="true"
description="Enable new terminal for PowerShell on Windows 10"/>
<registryKey key="terminal.new.ui.powershell.unix" defaultValue="false"
description="Enable new terminal for PowerShell on Unix"/>
<registryKey key="terminal.new.ui.show.promotion" defaultValue="true"
description="Whether to show the GotIt tooltip with a proposal to try the New Terminal"/>
<registryKey key="terminal.new.ui.inline.completion" defaultValue="false"

View File

@@ -43,6 +43,7 @@ open class LocalBlockTerminalRunner(project: Project) : LocalTerminalDirectRunne
const val BLOCK_TERMINAL_FISH_REGISTRY: String = "terminal.new.ui.fish"
const val BLOCK_TERMINAL_POWERSHELL_WIN11_REGISTRY: String = "terminal.new.ui.powershell.win11"
const val BLOCK_TERMINAL_POWERSHELL_WIN10_REGISTRY: String = "terminal.new.ui.powershell.win10"
const val BLOCK_TERMINAL_POWERSHELL_UNIX_REGISTRY: String = "terminal.new.ui.powershell.unix"
private const val BLOCK_TERMINAL_SHOW_PROMOTION: String = "terminal.new.ui.show.promotion"
}
}
}

View File

@@ -530,7 +530,8 @@ public class LocalTerminalDirectRunner extends AbstractTerminalRunner<PtyProcess
public static boolean isBlockTerminalSupported(@NotNull String shellName) {
if (isPowerShell(shellName)) {
return SystemInfo.isWin11OrNewer && Registry.is(BLOCK_TERMINAL_POWERSHELL_WIN11_REGISTRY, false) ||
SystemInfo.isWin10OrNewer && !SystemInfo.isWin11OrNewer && Registry.is(BLOCK_TERMINAL_POWERSHELL_WIN10_REGISTRY, false);
SystemInfo.isWin10OrNewer && !SystemInfo.isWin11OrNewer && Registry.is(BLOCK_TERMINAL_POWERSHELL_WIN10_REGISTRY, false) ||
SystemInfo.isUnix && Registry.is(BLOCK_TERMINAL_POWERSHELL_UNIX_REGISTRY, false);
}
return shellName.equals(BASH_NAME)
|| SystemInfo.isMac && shellName.equals(SH_NAME)

View File

@@ -2,6 +2,7 @@
package org.jetbrains.plugins.terminal.exp
import com.intellij.openapi.Disposable
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.text.StringUtil
import com.intellij.terminal.completion.spec.ShellCommandResult
import com.intellij.util.containers.nullize
@@ -265,14 +266,22 @@ internal class ShellCommandExecutionManager(private val session: BlockTerminalSe
}
private fun createClearPromptShortcut(terminal: Terminal): String {
return when (session.shellIntegration.shellType) {
return when (session.shellIntegration.shellType) {
ShellType.POWERSHELL -> {
// Simulate pressing Ctrl+Home to delete all the characters from
// the cursor's position to the beginning of a line.
terminal.getCodeForKey(VK_HOME, CTRL_MASK)!!.toString(Charsets.UTF_8)
// TODO SystemInfo will not work for SSH and WSL sessions.
when {
SystemInfo.isUnix -> {
SHORTCUT_CTRL_U
}
else -> {
// Simulate pressing Ctrl+Home to delete all the characters from
// the cursor's position to the beginning of a line.
terminal.getCodeForKey(VK_HOME, CTRL_MASK)!!.toString(Charsets.UTF_8)
}
}
}
// Simulate pressing Ctrl+U in the terminal to clear all typings in the prompt (IDEA-337692)
else -> "\u0015"
else -> SHORTCUT_CTRL_U
}
}
@@ -331,6 +340,7 @@ internal class ShellCommandExecutionManager(private val session: BlockTerminalSe
companion object {
private val NEXT_REQUEST_ID = AtomicInteger(0)
private const val GENERATOR_COMMAND = "__jetbrains_intellij_run_generator"
private const val SHORTCUT_CTRL_U = "\u0015"
@Suppress("SpellCheckingInspection")
private val pwshCharsToEscape: Map<Char, String> = mapOf(

View File

@@ -39,6 +39,7 @@ internal object TerminalSessionTestUtil {
Registry.get(LocalBlockTerminalRunner.BLOCK_TERMINAL_FISH_REGISTRY).setValue(true, parentDisposable)
Registry.get(LocalBlockTerminalRunner.BLOCK_TERMINAL_POWERSHELL_WIN11_REGISTRY).setValue(true, parentDisposable)
Registry.get(LocalBlockTerminalRunner.BLOCK_TERMINAL_POWERSHELL_WIN10_REGISTRY).setValue(true, parentDisposable)
Registry.get(LocalBlockTerminalRunner.BLOCK_TERMINAL_POWERSHELL_UNIX_REGISTRY).setValue(true, parentDisposable)
val runner = LocalBlockTerminalRunner(project)
val baseOptions = ShellStartupOptions.Builder().shellCommand(listOf(shellPath)).initialTermSize(initialTermSize)
.envVariables(mapOf(EnvironmentUtil.DISABLE_OMZ_AUTO_UPDATE to "true"))