Skip to content

Commit b99f7a2

Browse files
committed
Fix process.env enforcement errors
1 parent eae5d62 commit b99f7a2

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

cli/src/types/env.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import type {
1616
* CLI-specific env vars for terminal/IDE detection and editor preferences.
1717
*/
1818
export type CliEnv = BaseEnv & {
19+
// Terminal detection (for tmux/screen passthrough)
20+
TERM?: string
21+
TMUX?: string
22+
STY?: string
23+
1924
// Terminal-specific
2025
KITTY_WINDOW_ID?: string
2126
SIXEL_SUPPORT?: string

cli/src/utils/clipboard.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { closeSync, openSync, writeSync } from 'fs'
22
import { createRequire } from 'module'
33

4+
import { getCliEnv } from './env'
45
import { logger } from './logger'
56

67
const require = createRequire(import.meta.url)
@@ -140,20 +141,21 @@ export function clearClipboardMessage() {
140141
const OSC52_MAX_PAYLOAD = 32_000
141142

142143
function buildOsc52Sequence(text: string): string | null {
143-
if (process.env.TERM === 'dumb') return null
144+
const env = getCliEnv()
145+
if (env.TERM === 'dumb') return null
144146

145147
const base64 = Buffer.from(text, 'utf8').toString('base64')
146148
if (base64.length > OSC52_MAX_PAYLOAD) return null
147149

148150
const osc = `\x1b]52;c;${base64}\x07`
149151

150152
// tmux: wrap in DCS passthrough with doubled ESC
151-
if (process.env.TMUX) {
153+
if (env.TMUX) {
152154
return `\x1bPtmux;${osc.replace(/\x1b/g, '\x1b\x1b')}\x1b\\`
153155
}
154156

155157
// GNU screen: wrap in DCS passthrough
156-
if (process.env.STY) {
158+
if (env.STY) {
157159
return `\x1bP${osc}\x1b\\`
158160
}
159161

cli/src/utils/env.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import type { CliEnv } from '../types/env'
1616
export const getCliEnv = (): CliEnv => ({
1717
...getBaseEnv(),
1818

19+
// Terminal detection (for tmux/screen passthrough)
20+
TERM: process.env.TERM,
21+
TMUX: process.env.TMUX,
22+
STY: process.env.STY,
23+
1924
// Terminal detection
2025
KITTY_WINDOW_ID: process.env.KITTY_WINDOW_ID,
2126
SIXEL_SUPPORT: process.env.SIXEL_SUPPORT,

cli/src/utils/terminal-title.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,36 @@
1111

1212
import { closeSync, constants, openSync, writeSync } from 'fs'
1313

14+
import { getCliEnv } from './env'
15+
1416
const MAX_TITLE_LENGTH = 60
1517
const TITLE_PREFIX = 'Codebuff: '
1618
const OSC_TERMINATOR = '\x07' // BEL
1719

18-
function isInTmux(): boolean {
19-
return Boolean(process.env.TMUX)
20+
function isInTmux(env: ReturnType<typeof getCliEnv>): boolean {
21+
return Boolean(env.TMUX)
2022
}
2123

22-
function isInScreen(): boolean {
23-
if (process.env.STY) return true
24-
const term = process.env.TERM ?? ''
25-
return term.startsWith('screen') && !isInTmux()
24+
function isInScreen(env: ReturnType<typeof getCliEnv>): boolean {
25+
if (env.STY) return true
26+
const term = env.TERM ?? ''
27+
return term.startsWith('screen') && !isInTmux(env)
2628
}
2729

2830
/**
2931
* Build the OSC title sequence with tmux/screen passthrough if needed
3032
*/
31-
function buildTitleSequence(title: string): string {
33+
function buildTitleSequence(title: string, env: ReturnType<typeof getCliEnv>): string {
3234
const osc = `\x1b]0;${title}${OSC_TERMINATOR}`
3335

3436
// tmux passthrough: wrap in DCS and double ESC characters
35-
if (isInTmux()) {
37+
if (isInTmux(env)) {
3638
const escaped = osc.replace(/\x1b/g, '\x1b\x1b')
3739
return `\x1bPtmux;${escaped}\x1b\\`
3840
}
3941

4042
// GNU screen passthrough: wrap in DCS
41-
if (isInScreen()) {
43+
if (isInScreen(env)) {
4244
return `\x1bP${osc}\x1b\\`
4345
}
4446

@@ -89,7 +91,8 @@ export function setTerminalTitle(title: string): void {
8991
: sanitized
9092

9193
const fullTitle = `${TITLE_PREFIX}${truncated}`
92-
const sequence = buildTitleSequence(fullTitle)
94+
const env = getCliEnv()
95+
const sequence = buildTitleSequence(fullTitle, env)
9396

9497
writeToTty(sequence)
9598
}
@@ -100,6 +103,7 @@ export function setTerminalTitle(title: string): void {
100103
*/
101104
export function resetTerminalTitle(): void {
102105
// Empty title resets to terminal's default behavior
103-
const sequence = buildTitleSequence('')
106+
const env = getCliEnv()
107+
const sequence = buildTitleSequence('', env)
104108
writeToTty(sequence)
105109
}

0 commit comments

Comments
 (0)