Skip to content

Commit c1f8ff4

Browse files
authored
fix(OSC4): tmux 3.6 has native support for OSC4 and should not be wrapped (#373)
#354 fix was only working for tmux<3.6 because it doesn't have native OSC4 support, so OSC4 sequence needed escaping. But, tmux 3.6 has native OSC4 support and wrapping the sequence in a tmux escape prevent OSC4 to work with tmux 3.6. This fixes anomalyco/opencode#3688 for tmux 3.6 (regression was introduced by upgrading to OpenTUI 0.1.51 in anomalyco/opencode@204a31b.
1 parent c38c9b3 commit c1f8ff4

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎packages/core/src/lib/terminal-palette.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ export class TerminalPalette implements TerminalPaletteDetector {
6363
private writeFn: WriteFunction
6464
private activeListeners: Array<{ event: string; handler: (...args: any[]) => void }> = []
6565
private activeTimers: Array<NodeJS.Timeout> = []
66-
private inTmux: boolean
66+
private inLegacyTmux: boolean
6767

68-
constructor(stdin: NodeJS.ReadStream, stdout: NodeJS.WriteStream, writeFn?: WriteFunction, isTmux?: boolean) {
68+
constructor(stdin: NodeJS.ReadStream, stdout: NodeJS.WriteStream, writeFn?: WriteFunction, isLegacyTmux?: boolean) {
6969
this.stdin = stdin
7070
this.stdout = stdout
7171
this.writeFn = writeFn || ((data: string | Buffer) => stdout.write(data))
72-
this.inTmux = isTmux ?? false
72+
this.inLegacyTmux = isLegacyTmux ?? false
7373
}
7474

7575
/**
7676
* Write an OSC sequence, wrapping for tmux if needed
7777
*/
7878
private writeOsc(osc: string): boolean {
79-
const data = this.inTmux ? wrapForTmux(osc) : osc
79+
const data = this.inLegacyTmux ? wrapForTmux(osc) : osc
8080
return this.writeFn(data)
8181
}
8282

@@ -340,7 +340,7 @@ export function createTerminalPalette(
340340
stdin: NodeJS.ReadStream,
341341
stdout: NodeJS.WriteStream,
342342
writeFn?: WriteFunction,
343-
isTmux?: boolean,
343+
isLegacyTmux?: boolean,
344344
): TerminalPaletteDetector {
345-
return new TerminalPalette(stdin, stdout, writeFn, isTmux)
345+
return new TerminalPalette(stdin, stdout, writeFn, isLegacyTmux)
346346
}

‎packages/core/src/renderer.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,8 +1752,10 @@ export class CliRenderer extends EventEmitter implements RenderContext {
17521752
}
17531753

17541754
if (!this._paletteDetector) {
1755-
const isTmux = this.capabilities?.terminal?.name?.toLowerCase()?.includes("tmux")
1756-
this._paletteDetector = createTerminalPalette(this.stdin, this.stdout, this.writeOut.bind(this), isTmux)
1755+
const isLegacyTmux =
1756+
this.capabilities?.terminal?.name?.toLowerCase()?.includes("tmux") &&
1757+
this.capabilities?.terminal?.version?.localeCompare("3.6") < 0
1758+
this._paletteDetector = createTerminalPalette(this.stdin, this.stdout, this.writeOut.bind(this), isLegacyTmux)
17571759
}
17581760

17591761
this._paletteDetectionPromise = this._paletteDetector.detect(options).then((result) => {

0 commit comments

Comments
 (0)