MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / cleanup

Function cleanup

cli/src/utils/terminal-color-detection.ts:126–166  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124 let dataHandler: ((data: Buffer) => void) | null = null
125
126 const cleanup = () => {
127 if (resolved) return
128 resolved = true
129
130 if (timeoutId) {
131 clearTimeout(timeoutId)
132 timeoutId = null
133 }
134
135 // Remove data handler from stdin
136 if (dataHandler) {
137 process.stdin.removeListener('data', dataHandler)
138 dataHandler = null
139 }
140
141 // Restore raw mode state
142 if (process.stdin.isTTY && process.stdin.setRawMode) {
143 try {
144 process.stdin.setRawMode(wasRawMode)
145 } catch {
146 // Ignore errors restoring raw mode
147 }
148 }
149
150 // Pause stdin so we leave it non-flowing before other listeners attach
151 try {
152 process.stdin.pause()
153 } catch {
154 // Ignore pause errors
155 }
156
157 // Close TTY write fd
158 if (ttyWriteFd !== null) {
159 try {
160 closeSync(ttyWriteFd)
161 } catch {
162 // Ignore close errors
163 }
164 ttyWriteFd = null
165 }
166 }
167
168 const resolveWith = (value: string | null) => {
169 if (resolved) return

Callers 1

resolveWithFunction · 0.70

Calls 1

removeListenerMethod · 0.80

Tested by

no test coverage detected