Skip to content

Commit b020e46

Browse files
author
Eric Wheeler
committed
fix: clear ZSH EOL mark to prevent command output interpretation issues
Added a new configuration option 'terminalZshClearEolMark' (default: true) that sets PROMPT_EOL_MARK='' in the terminal environment. This prevents issues with command output interpretation when the output ends with special characters like '%'. Added translations for all supported languages. Fixes: #2194 Signed-off-by: Eric Wheeler <[email protected]>
1 parent 211e31b commit b020e46

File tree

27 files changed

+136
-5
lines changed

27 files changed

+136
-5
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,23 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
351351
}
352352

353353
// Initialize out-of-scope variables that need to recieve persistent global state values
354-
this.getState().then(({ soundEnabled, terminalShellIntegrationTimeout, terminalCommandDelay }) => {
355-
setSoundEnabled(soundEnabled ?? false)
356-
Terminal.setShellIntegrationTimeout(terminalShellIntegrationTimeout ?? TERMINAL_SHELL_INTEGRATION_TIMEOUT)
357-
Terminal.setCommandDelay(terminalCommandDelay ?? 0)
358-
})
354+
this.getState().then(
355+
({
356+
soundEnabled,
357+
terminalShellIntegrationTimeout,
358+
terminalCommandDelay,
359+
terminalZshClearEolMark,
360+
terminalPowershellCounter,
361+
}) => {
362+
setSoundEnabled(soundEnabled ?? false)
363+
Terminal.setShellIntegrationTimeout(
364+
terminalShellIntegrationTimeout ?? TERMINAL_SHELL_INTEGRATION_TIMEOUT,
365+
)
366+
Terminal.setCommandDelay(terminalCommandDelay ?? 0)
367+
Terminal.setTerminalZshClearEolMark(terminalZshClearEolMark ?? true)
368+
Terminal.setPowershellCounter(terminalPowershellCounter ?? false)
369+
},
370+
)
359371

360372
// Initialize tts enabled state
361373
this.getState().then(({ ttsEnabled }) => {
@@ -1200,6 +1212,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12001212
terminalShellIntegrationTimeout,
12011213
terminalCommandDelay,
12021214
terminalPowershellCounter,
1215+
terminalZshClearEolMark,
12031216
fuzzyMatchThreshold,
12041217
mcpEnabled,
12051218
enableMcpServerCreation,
@@ -1269,6 +1282,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12691282
terminalShellIntegrationTimeout: terminalShellIntegrationTimeout ?? TERMINAL_SHELL_INTEGRATION_TIMEOUT,
12701283
terminalCommandDelay: terminalCommandDelay ?? 0,
12711284
terminalPowershellCounter: terminalPowershellCounter ?? false,
1285+
terminalZshClearEolMark: terminalZshClearEolMark ?? true,
12721286
fuzzyMatchThreshold: fuzzyMatchThreshold ?? 1.0,
12731287
mcpEnabled: mcpEnabled ?? true,
12741288
enableMcpServerCreation: enableMcpServerCreation ?? true,
@@ -1357,6 +1371,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13571371
stateValues.terminalShellIntegrationTimeout ?? TERMINAL_SHELL_INTEGRATION_TIMEOUT,
13581372
terminalCommandDelay: stateValues.terminalCommandDelay ?? 0,
13591373
terminalPowershellCounter: stateValues.terminalPowershellCounter ?? false,
1374+
terminalZshClearEolMark: stateValues.terminalZshClearEolMark ?? true,
13601375
mode: stateValues.mode ?? defaultModeSlug,
13611376
language: stateValues.language ?? formatLanguage(vscode.env.language),
13621377
mcpEnabled: stateValues.mcpEnabled ?? true,

src/core/webview/webviewMessageHandler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,13 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
750750
Terminal.setPowershellCounter(message.bool)
751751
}
752752
break
753+
case "terminalZshClearEolMark":
754+
await updateGlobalState("terminalZshClearEolMark", message.bool)
755+
await provider.postStateToWebview()
756+
if (message.bool !== undefined) {
757+
Terminal.setTerminalZshClearEolMark(message.bool)
758+
}
759+
break
753760
case "mode":
754761
await provider.handleModeSwitch(message.text as Mode)
755762
break

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ type GlobalSettings = {
268268
terminalShellIntegrationTimeout?: number | undefined
269269
terminalCommandDelay?: number | undefined
270270
terminalPowershellCounter?: boolean | undefined
271+
terminalZshClearEolMark?: boolean | undefined
271272
rateLimitSeconds?: number | undefined
272273
diffEnabled?: boolean | undefined
273274
fuzzyMatchThreshold?: number | undefined

src/exports/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ type GlobalSettings = {
271271
terminalShellIntegrationTimeout?: number | undefined
272272
terminalCommandDelay?: number | undefined
273273
terminalPowershellCounter?: boolean | undefined
274+
terminalZshClearEolMark?: boolean | undefined
274275
rateLimitSeconds?: number | undefined
275276
diffEnabled?: boolean | undefined
276277
fuzzyMatchThreshold?: number | undefined

src/integrations/terminal/Terminal.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class Terminal {
99
private static shellIntegrationTimeout: number = TERMINAL_SHELL_INTEGRATION_TIMEOUT
1010
private static commandDelay: number = 0
1111
private static powershellCounter: boolean = false
12+
private static terminalZshClearEolMark: boolean = true
1213

1314
public terminal: vscode.Terminal
1415
public busy: boolean
@@ -294,6 +295,22 @@ export class Terminal {
294295
return Terminal.powershellCounter
295296
}
296297

298+
/**
299+
* Sets whether to clear the ZSH EOL mark
300+
* @param enabled Whether to clear the ZSH EOL mark
301+
*/
302+
public static setTerminalZshClearEolMark(enabled: boolean): void {
303+
Terminal.terminalZshClearEolMark = enabled
304+
}
305+
306+
/**
307+
* Gets whether to clear the ZSH EOL mark
308+
* @returns Whether the ZSH EOL mark clearing is enabled
309+
*/
310+
public static getTerminalZshClearEolMark(): boolean {
311+
return Terminal.terminalZshClearEolMark
312+
}
313+
297314
public static compressTerminalOutput(input: string, lineLimit: number): string {
298315
return truncateOutput(applyRunLengthEncoding(input), lineLimit)
299316
}

src/integrations/terminal/TerminalRegistry.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ export class TerminalRegistry {
125125
env.PROMPT_COMMAND = `sleep ${Terminal.getCommandDelay() / 1000}`
126126
}
127127

128+
// Clear the ZSH EOL mark to prevent issues with command output interpretation
129+
// when output ends with special characters like '%'
130+
if (Terminal.getTerminalZshClearEolMark()) {
131+
env.PROMPT_EOL_MARK = ""
132+
}
133+
128134
const terminal = vscode.window.createTerminal({
129135
cwd,
130136
name: "Roo Code",

src/integrations/terminal/__tests__/TerminalRegistry.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("TerminalRegistry", () => {
3333
env: {
3434
PAGER: "cat",
3535
VTE_VERSION: "0",
36+
PROMPT_EOL_MARK: "",
3637
},
3738
})
3839
})
@@ -53,6 +54,7 @@ describe("TerminalRegistry", () => {
5354
PAGER: "cat",
5455
PROMPT_COMMAND: "sleep 0.05",
5556
VTE_VERSION: "0",
57+
PROMPT_EOL_MARK: "",
5658
},
5759
})
5860
} finally {

src/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ export const globalSettingsSchema = z.object({
534534
terminalShellIntegrationTimeout: z.number().optional(),
535535
terminalCommandDelay: z.number().optional(),
536536
terminalPowershellCounter: z.boolean().optional(),
537+
terminalZshClearEolMark: z.boolean().optional(),
537538

538539
rateLimitSeconds: z.number().optional(),
539540
diffEnabled: z.boolean().optional(),
@@ -606,6 +607,7 @@ const globalSettingsRecord: GlobalSettingsRecord = {
606607
terminalShellIntegrationTimeout: undefined,
607608
terminalCommandDelay: undefined,
608609
terminalPowershellCounter: undefined,
610+
terminalZshClearEolMark: undefined,
609611

610612
rateLimitSeconds: undefined,
611613
diffEnabled: undefined,

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export type ExtensionState = Pick<
155155
| "terminalShellIntegrationTimeout"
156156
| "terminalCommandDelay"
157157
| "terminalPowershellCounter"
158+
| "terminalZshClearEolMark"
158159
| "diffEnabled"
159160
| "fuzzyMatchThreshold"
160161
// | "experiments" // Optional in GlobalSettings, required here.

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface WebviewMessage {
8484
| "terminalShellIntegrationTimeout"
8585
| "terminalCommandDelay"
8686
| "terminalPowershellCounter"
87+
| "terminalZshClearEolMark"
8788
| "mcpEnabled"
8889
| "enableMcpServerCreation"
8990
| "searchCommits"

0 commit comments

Comments
 (0)