MCPcopy
hub / github.com/coder/code-server / onLine

Function onLine

src/node/util.ts:30–50  ·  view source on GitHub ↗
(proc: cp.ChildProcess, callback: OnLineCallback)

Source from the content-addressed store, hash-verified

28 * Split stdout on newlines and strip ANSI codes.
29 */
30export const onLine = (proc: cp.ChildProcess, callback: OnLineCallback): void => {
31 let buffer = ""
32 if (!proc.stdout) {
33 throw new Error("no stdout")
34 }
35 proc.stdout.setEncoding("utf8")
36 proc.stdout.on("data", (d) => {
37 const data = buffer + d
38 const split = data.split("\n")
39 const last = split.length - 1
40
41 for (let i = 0; i < last; ++i) {
42 callback(split[i].replace(re, ""), split[i])
43 }
44
45 // The last item will either be an empty string (the data ended with a
46 // newline) or a partial line (did not end with a newline) and we must
47 // wait to parse it until we get a full line.
48 buffer = split[last]
49 })
50}
51
52export const paths = getEnvPaths()
53

Callers 3

spawnMethod · 0.90
WatcherClass · 0.90
initializeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected