Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -286,23 +286,58 @@ 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 |
-
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
event = {
|
| 293 |
-
"type": "terminal-
|
| 294 |
-
"data":
|
| 295 |
}
|
| 296 |
await websocket.send(json.dumps(event))
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
event = {
|
| 302 |
-
"type": "terminal-
|
| 303 |
-
"data":
|
| 304 |
}
|
| 305 |
await websocket.send(json.dumps(event))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
|
| 307 |
async def handle_user_input(websocket,key, process, connected):
|
| 308 |
while True:
|
|
|
|
| 286 |
websockets.broadcast(connected,json.dumps(event))
|
| 287 |
|
| 288 |
async def read_process_output(process, websocket):
|
| 289 |
+
# Read the output byte by byte and print word by word
|
| 290 |
+
word = b''
|
| 291 |
+
while True:
|
| 292 |
+
char = await process.stdout.read(1)
|
| 293 |
+
if char == b'\n':
|
| 294 |
+
if word:
|
| 295 |
+
print(word.decode())
|
| 296 |
+
word = b''
|
| 297 |
+
print("line is completed")
|
| 298 |
event = {
|
| 299 |
+
"type": "terminal-newline",
|
| 300 |
+
"data": "",
|
| 301 |
}
|
| 302 |
await websocket.send(json.dumps(event))
|
| 303 |
+
elif char == b' ':
|
| 304 |
+
if word:
|
| 305 |
+
print(word.decode())
|
| 306 |
+
event = {
|
| 307 |
+
"type": "terminal-data",
|
| 308 |
+
"data": word.decode(),
|
| 309 |
+
}
|
| 310 |
+
await websocket.send(json.dumps(event))
|
| 311 |
+
word = b''
|
| 312 |
+
print("space is occurred")
|
| 313 |
event = {
|
| 314 |
+
"type": "terminal-data",
|
| 315 |
+
"data": " ",
|
| 316 |
}
|
| 317 |
await websocket.send(json.dumps(event))
|
| 318 |
+
elif char == b'':
|
| 319 |
+
if word:
|
| 320 |
+
print(word.decode())
|
| 321 |
+
break
|
| 322 |
+
else:
|
| 323 |
+
word += char
|
| 324 |
+
# async for line in process.stdout:
|
| 325 |
+
# # print('sending line')
|
| 326 |
+
|
| 327 |
+
# event = {
|
| 328 |
+
# "type": "terminal-data",
|
| 329 |
+
# "data": line.strip().decode('utf-8'),
|
| 330 |
+
# }
|
| 331 |
+
# await websocket.send(json.dumps(event))
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
# async for line in process.stderr:
|
| 335 |
+
# # print(f'error:{line.strip()}')
|
| 336 |
+
# event = {
|
| 337 |
+
# "type": "terminal-error",
|
| 338 |
+
# "data": line.strip().decode('utf-8'),
|
| 339 |
+
# }
|
| 340 |
+
# await websocket.send(json.dumps(event))
|
| 341 |
|
| 342 |
async def handle_user_input(websocket,key, process, connected):
|
| 343 |
while True:
|