Просмотр исходного кода

Extract OutputStream type for python runner streams

GitOrigin-RevId: 9a26c847ec7daa4cd446e9fec0407e64e6f40916
Domagoj Kriskovic 3 месяцев назад
Родитель
Сommit
3a232c44eb

+ 2 - 1
services/web/frontend/js/features/ide-react/components/editor/python/pyodide-worker-client.ts

@@ -1,11 +1,12 @@
 import type {
+  OutputStream,
   ProjectFileData,
   PyodideWorkerRequest,
   PyodideWorkerResponse,
 } from './pyodide-worker-messages'
 
 export type OutputCallback = (
-  stream: 'stdout' | 'stderr' | 'info',
+  stream: OutputStream,
   line: string,
   fileId: string,
   executionId: string

+ 3 - 1
services/web/frontend/js/features/ide-react/components/editor/python/pyodide-worker-messages.ts

@@ -1,3 +1,5 @@
+export type OutputStream = 'stdout' | 'stderr' | 'info'
+
 export type ProjectFileData = {
   relativePath: string
   content: string
@@ -28,7 +30,7 @@ export type LoadingFailedEvent = { type: 'loading-failed'; error: string }
 
 export type OutputLineEvent = {
   type: 'output-line'
-  stream: 'stdout' | 'stderr' | 'info'
+  stream: OutputStream
   line: string
   fileId: string
   executionId: string

+ 3 - 5
services/web/frontend/js/features/ide-react/components/editor/python/python-runner.ts

@@ -4,6 +4,7 @@
 import { v4 as uuid } from 'uuid'
 import { debugConsole } from '@/utils/debugging'
 import { PyodideWorkerClient } from './pyodide-worker-client'
+import type { OutputStream } from './pyodide-worker-messages'
 
 const MAX_OUTPUT_LINES = 100
 
@@ -22,7 +23,7 @@ export type ExecutionContext = {
 type Listener = () => void
 
 export type OutputLine = {
-  stream: 'stdout' | 'stderr' | 'info'
+  stream: OutputStream
   line: string
 }
 
@@ -208,10 +209,7 @@ export class PythonRunner {
   }
 }
 
-function appendCapped(
-  existing: OutputLine[],
-  entry: OutputLine
-): OutputLine[] {
+function appendCapped(existing: OutputLine[], entry: OutputLine): OutputLine[] {
   const updated = [...existing, entry]
   return updated.length > MAX_OUTPUT_LINES
     ? updated.slice(-MAX_OUTPUT_LINES)