From 1d8ec5e529b4e0a9c8161b91e947eb380ccbe45e Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Thu, 15 Jan 2026 00:43:29 +0100 Subject: [PATCH] [eel, terminal] IJPL-224593 do not set `TERM` environment variable on Windows `TERM` is specific to Unix-like systems (https://www.gnu.org/software/gettext/manual/html_node/The-TERM-variable.html). `TERM` is not used on Windows; instead, Windows apps use Windows APIs to detect console capabilities. Therefore, Windows Terminal and Command Prompt do not set it, as expected. Setting `TERM` on Windows can make some cross-platform tools wrongly assume specific console capabilities and start emitting ANSI escape sequences. Although modern Windows consoles handle these sequences correctly, this leads to behavioral differences compared to Windows Terminal (see IJPL-224593). To align with native Windows Terminal behavior, let's avoid setting `TERM` on Windows. Space-RevId: d1162b704d433e29c59783c8f6c994715727d2da GitOrigin-RevId: a01f4bd8b6f9a2e364a60ef8b553fd4baf3cc07d --- .../intellij/platform/eel/impl/local/EelLocalExecApi.kt | 5 +++-- .../com/intellij/execution/eel/EelLocalExecApiTest.kt | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/platform/eel-impl/src/com/intellij/platform/eel/impl/local/EelLocalExecApi.kt b/platform/eel-impl/src/com/intellij/platform/eel/impl/local/EelLocalExecApi.kt index 49da0760f336..0bb8b187aebc 100644 --- a/platform/eel-impl/src/com/intellij/platform/eel/impl/local/EelLocalExecApi.kt +++ b/platform/eel-impl/src/com/intellij/platform/eel/impl/local/EelLocalExecApi.kt @@ -295,10 +295,11 @@ private fun executeImpl(builder: EelExecApi.ExecuteProcessOptions): Process { // Inherit env vars because lack of `PATH` might break things val environment = System.getenv().toMutableMap() environment.putAll(builder.env) - val escapedCommandLine = CommandLineUtil.toCommandLine(builder.exe, builder.args, Platform.current()) + val platform = Platform.current() + val escapedCommandLine = CommandLineUtil.toCommandLine(builder.exe, builder.args, platform) return when (val p = pty) { is EelExecApi.Pty -> { - if ("TERM" !in environment) { + if (platform == Platform.UNIX && "TERM" !in environment) { environment.getOrPut("TERM") { "xterm" } } LocalProcessService.getInstance().startPtyProcess( diff --git a/platform/platform-tests/testSrc/com/intellij/execution/eel/EelLocalExecApiTest.kt b/platform/platform-tests/testSrc/com/intellij/execution/eel/EelLocalExecApiTest.kt index c6a980029ea0..bff68d694c9b 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/eel/EelLocalExecApiTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/execution/eel/EelLocalExecApiTest.kt @@ -13,6 +13,7 @@ import com.intellij.openapi.util.SystemInfoRt import com.intellij.platform.eel.* import com.intellij.platform.eel.EelExecApi.Pty import com.intellij.platform.eel.impl.local.getShellFromPasswdRecords +import com.intellij.platform.eel.provider.LocalEelDescriptor import com.intellij.platform.eel.provider.localEel import com.intellij.platform.eel.provider.utils.sendWholeText import com.intellij.platform.tests.eelHelpers.EelHelper @@ -179,8 +180,10 @@ class EelLocalExecApiTest { PTY_SIZE_FROM_START, PTY_RESIZE_LATER -> { Assertions.assertNotNull(ttyState.size) Assertions.assertEquals(Size(PTY_COLS, PTY_ROWS), ttyState.size, "size must be set for tty") - val expectedTerm = System.getenv("TERM") ?: "xterm" - Assertions.assertEquals(expectedTerm, ttyState.termName, "Wrong term type") + if (LocalEelDescriptor.osFamily.isPosix) { + val expectedTerm = System.getenv("TERM") ?: "xterm" + Assertions.assertEquals(expectedTerm, ttyState.termName, "Wrong term type") + } } NO_PTY -> { Assertions.assertNull(ttyState.size, "size must not be set if no tty")