Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -286,7 +286,7 @@ async def wirte_file(websocket, key,project_name, path, content, connected):
|
|
286 |
websockets.broadcast(connected,json.dumps(event))
|
287 |
|
288 |
async def read_process_output(process, websocket):
|
289 |
-
|
290 |
word = b''
|
291 |
while True:
|
292 |
char = await process.stdout.read(1)
|
@@ -321,6 +321,40 @@ async def read_process_output(process, websocket):
|
|
321 |
break
|
322 |
else:
|
323 |
word += char
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
# async for line in process.stdout:
|
325 |
# # print('sending line')
|
326 |
|
|
|
286 |
websockets.broadcast(connected,json.dumps(event))
|
287 |
|
288 |
async def read_process_output(process, websocket):
|
289 |
+
# Read the output and error byte by byte and print word by word
|
290 |
word = b''
|
291 |
while True:
|
292 |
char = await process.stdout.read(1)
|
|
|
321 |
break
|
322 |
else:
|
323 |
word += char
|
324 |
+
|
325 |
+
while True:
|
326 |
+
char = await process.stderr.read(1)
|
327 |
+
if char == b'\n':
|
328 |
+
if word:
|
329 |
+
print(word.decode())
|
330 |
+
word = b''
|
331 |
+
print("line is completed")
|
332 |
+
event = {
|
333 |
+
"type": "terminal-newline",
|
334 |
+
"data": "",
|
335 |
+
}
|
336 |
+
await websocket.send(json.dumps(event))
|
337 |
+
elif char == b' ':
|
338 |
+
if word:
|
339 |
+
print(word.decode())
|
340 |
+
event = {
|
341 |
+
"type": "terminal-data",
|
342 |
+
"data": word.decode(),
|
343 |
+
}
|
344 |
+
await websocket.send(json.dumps(event))
|
345 |
+
word = b''
|
346 |
+
print("space is occurred")
|
347 |
+
event = {
|
348 |
+
"type": "terminal-data",
|
349 |
+
"data": " ",
|
350 |
+
}
|
351 |
+
await websocket.send(json.dumps(event))
|
352 |
+
elif char == b'':
|
353 |
+
if word:
|
354 |
+
print(word.decode())
|
355 |
+
break
|
356 |
+
else:
|
357 |
+
word += char
|
358 |
# async for line in process.stdout:
|
359 |
# # print('sending line')
|
360 |
|