@steve02081504/virtual-console 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.mjs +16 -3
- package/package.json +1 -1
package/main.mjs
CHANGED
|
@@ -6,6 +6,10 @@ import supportsAnsi from 'supports-ansi'
|
|
|
6
6
|
import { FullProxy } from 'full-proxy'
|
|
7
7
|
|
|
8
8
|
export const consoleAsyncStorage = new AsyncLocalStorage()
|
|
9
|
+
const cleanupRegistry = new FinalizationRegistry(cleanupToken => {
|
|
10
|
+
const { stream, listener } = cleanupToken
|
|
11
|
+
stream.off?.('resize', listener)
|
|
12
|
+
})
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* 创建一个虚拟控制台,用于捕获输出,同时可以选择性地将输出传递给真实的控制台。
|
|
@@ -100,9 +104,18 @@ export class VirtualConsole extends Console {
|
|
|
100
104
|
hasColors: { get: () => targetStream.hasColors.bind(targetStream), configurable: true, enumerable: true },
|
|
101
105
|
})
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
const virtualStreamRef = new WeakRef(virtualStream)
|
|
108
|
+
|
|
109
|
+
const resizeListener = () => {
|
|
110
|
+
virtualStreamRef.deref()?.emit('resize')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
targetStream.on?.('resize', resizeListener)
|
|
114
|
+
|
|
115
|
+
cleanupRegistry.register(this, {
|
|
116
|
+
stream: targetStream,
|
|
117
|
+
listener: resizeListener,
|
|
118
|
+
}, this)
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
return virtualStream
|