@@ -2,7 +2,8 @@ import React from 'react'
22
33import { mergeStyleSets , useTheme } from '@fluentui/react'
44import type { StatusState } from '~/store'
5- import { OutputLine } from './OutputLine'
5+ import { EvalEventKind } from '~/services/api'
6+ import { splitImageAndText } from './utils'
67
78interface Props {
89 status ?: StatusState
@@ -16,11 +17,27 @@ interface Props {
1617export const FallbackOutput : React . FC < Props > = ( { fontFamily, fontSize, status } ) => {
1718 const theme = useTheme ( )
1819 const styles = mergeStyleSets ( {
19- container : {
20+ root : {
2021 flex : '1 1 auto' ,
2122 boxSizing : 'border-box' ,
2223 padding : '0, 15px' ,
2324 } ,
25+ content : {
26+ whiteSpace : 'pre-wrap' ,
27+ display : 'table' ,
28+ width : '100%' ,
29+
30+ font : 'inherit' ,
31+ border : 'none' ,
32+ margin : 0 ,
33+ float : 'left' ,
34+ } ,
35+ stderr : {
36+ color : theme . palette . red ,
37+ } ,
38+ image : {
39+ display : 'block' ,
40+ } ,
2441 programExitMsg : {
2542 marginTop : '1rem' ,
2643 display : 'inline-block' ,
@@ -29,8 +46,29 @@ export const FallbackOutput: React.FC<Props> = ({ fontFamily, fontSize, status }
2946 } )
3047
3148 return (
32- < div className = { styles . container } style = { { fontFamily, fontSize : `${ fontSize } px` } } >
33- { status ?. events ?. map ( ( event , i ) => < OutputLine key = { i } event = { event } /> ) }
49+ < div className = { styles . root } style = { { fontFamily, fontSize : `${ fontSize } px` } } >
50+ < div className = { styles . content } >
51+ { status ?. events ?. map ( ( { Kind : kind , Message : msg } , i ) => {
52+ if ( kind === EvalEventKind . Stderr ) {
53+ return (
54+ < span key = { i } className = { styles . stderr } >
55+ { msg }
56+ </ span >
57+ )
58+ }
59+
60+ // Image content and text can come mixed due to output buffering
61+ return splitImageAndText ( msg ) . map ( ( { isImage, data } , j ) => (
62+ < React . Fragment key = { `${ i } .${ j } ` } >
63+ { isImage ? (
64+ < img className = { styles . image } key = { i } src = { `data:image;base64,${ data } ` } alt = "Image output" />
65+ ) : (
66+ data
67+ ) }
68+ </ React . Fragment >
69+ ) )
70+ } ) }
71+ </ div >
3472 { ! status ?. running && < span className = { styles . programExitMsg } > Program exited.</ span > }
3573 </ div >
3674 )
0 commit comments