| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 07361e6 commit def85da
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,8 +97,8 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) { | |||
| 97 | 97 | const child = spawn(process.execPath, args); | |
| 98 | 98 | child.stdout.setEncoding('utf8'); | |
| 99 | 99 | child.stderr.setEncoding('utf8'); | |
| 100 | - child.stdout.on('data', childPrint); | ||
| 101 | - child.stderr.on('data', childPrint); | ||
| 100 | + child.stdout.on('data', (chunk) => childPrint(chunk, 'stdout')); | ||
| 101 | + child.stderr.on('data', (chunk) => childPrint(chunk, 'stderr')); | ||
| 102 | 102 | ||
| 103 | 103 | let output = ''; | |
| 104 | 104 | function waitForListenHint(text) { | |
@@ -231,7 +231,7 @@ class NodeInspector { | |||
| 231 | 231 | return this.client.connect(port, host) | |
| 232 | 232 | .then(() => { | |
| 233 | 233 | debuglog('connection established'); | |
| 234 | - this.stdout.write(' ok'); | ||
| 234 | + this.stdout.write(' ok\n'); | ||
| 235 | 235 | }, (error) => { | |
| 236 | 236 | debuglog('connect failed', error); | |
| 237 | 237 | // If it's failed to connect 10 times then print failed message | |
@@ -245,7 +245,7 @@ class NodeInspector { | |||
| 245 | 245 | }); | |
| 246 | 246 | }; | |
| 247 | 247 | ||
| 248 | - this.print(`connecting to ${host}:${port} ..`, true); | ||
| 248 | + this.print(`connecting to ${host}:${port} ..`, false); | ||
| 249 | 249 | return attemptConnect(); | |
| 250 | 250 | }); | |
| 251 | 251 | } | |
@@ -259,23 +259,32 @@ class NodeInspector { | |||
| 259 | 259 | } | |
| 260 | 260 | } | |
| 261 | 261 | ||
| 262 | - print(text, oneline = false) { | ||
| 262 | + print(text, appendNewline = false) { | ||
| 263 | 263 | this.clearLine(); | |
| 264 | - this.stdout.write(oneline ? text : `${text}\n`); | ||
| 264 | + this.stdout.write(appendNewline ? `${text}\n` : text); | ||
| 265 | 265 | } | |
| 266 | 266 | ||
| 267 | - childPrint(text) { | ||
| 268 | - this.print( | ||
| 269 | - text.toString() | ||
| 270 | - .split(/\r\n|\r|\n/g) | ||
| 271 | - .filter((chunk) => !!chunk) | ||
| 272 | - .map((chunk) => `< ${chunk}`) | ||
| 273 | - .join('\n') | ||
| 274 | - ); | ||
| 275 | - if (!this.paused) { | ||
| 276 | - this.repl.displayPrompt(true); | ||
| 267 | + #stdioBuffers = {stdout: '', stderr: ''}; | ||
| 268 | + childPrint(text, which) { | ||
| 269 | + const lines = (this.#stdioBuffers[which] + text) | ||
| 270 | + .split(/\r\n|\r|\n/g); | ||
| 271 | + | ||
| 272 | + this.#stdioBuffers[which] = ''; | ||
| 273 | + | ||
| 274 | + if (lines[lines.length - 1] !== '') { | ||
| 275 | + this.#stdioBuffers[which] = lines.pop(); | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + const textToPrint = lines.map((chunk) => `< ${chunk}`).join('\n'); | ||
| 279 | + | ||
| 280 | + if (lines.length) { | ||
| 281 | + this.print(textToPrint, true); | ||
| 282 | + if (!this.paused) { | ||
| 283 | + this.repl.displayPrompt(true); | ||
| 284 | + } | ||
| 277 | 285 | } | |
| 278 | - if (/Waiting for the debugger to disconnect\.\.\.\n$/.test(text)) { | ||
| 286 | + | ||
| 287 | + if (textToPrint.endsWith('Waiting for the debugger to disconnect...\n')) { | ||
| 279 | 288 | this.killChild(); | |
| 280 | 289 | } | |
| 281 | 290 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,9 +320,9 @@ function createRepl(inspector) { | |||
| 320 | 320 | return util.inspect(value, INSPECT_OPTIONS); | |
| 321 | 321 | } | |
| 322 | 322 | ||
| 323 | - function print(value, oneline = false) { | ||
| 323 | + function print(value, addNewline = true) { | ||
| 324 | 324 | const text = typeof value === 'string' ? value : inspect(value); | |
| 325 | - return inspector.print(text, oneline); | ||
| 325 | + return inspector.print(text, addNewline); | ||
| 326 | 326 | } | |
| 327 | 327 | ||
| 328 | 328 | function getCurrentLocation() { | |
@@ -928,13 +928,13 @@ function createRepl(inspector) { | |||
| 928 | 928 | if (finished) { | |
| 929 | 929 | print('Heap snaphost prepared.'); | |
| 930 | 930 | } else { | |
| 931 | - print(`Heap snapshot: ${done}/${total}`, true); | ||
| 931 | + print(`Heap snapshot: ${done}/${total}`, false); | ||
| 932 | 932 | } | |
| 933 | 933 | } | |
| 934 | 934 | function onChunk({ chunk }) { | |
| 935 | 935 | sizeWritten += chunk.length; | |
| 936 | 936 | writer.write(chunk); | |
| 937 | - print(`Writing snapshot: ${sizeWritten}`, true); | ||
| 937 | + print(`Writing snapshot: ${sizeWritten}`, false); | ||
| 938 | 938 | } | |
| 939 | 939 | function onResolve() { | |
| 940 | 940 | writer.end(() => { | |
@@ -956,7 +956,7 @@ function createRepl(inspector) { | |||
| 956 | 956 | HeapProfiler.on('reportHeapSnapshotProgress', onProgress); | |
| 957 | 957 | HeapProfiler.on('addHeapSnapshotChunk', onChunk); | |
| 958 | 958 | ||
| 959 | - print('Heap snapshot: 0/0', true); | ||
| 959 | + print('Heap snapshot: 0/0', false); | ||
| 960 | 960 | HeapProfiler.takeHeapSnapshot({ reportProgress: true }) | |
| 961 | 961 | .then(onResolve, onReject); | |
| 962 | 962 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments