@@ -58,25 +58,17 @@ type CompassShellProps = {
5858 onHistoryChange : ( history : string [ ] ) => void ;
5959 initialEvaluate ?: string | string [ ] ;
6060 initialInput ?: string ;
61+ isOperationInProgress : boolean ;
62+ onOperationStarted : ( ) => void ;
63+ onOperationEnd : ( ) => void ;
6164} ;
6265
63- function useInitialEval ( initialEvaluate ?: string | string [ ] ) {
64- const [ initialEvalApplied , setInitialEvalApplied ] = useTabState (
65- 'initialEvalApplied' ,
66- false
67- ) ;
68- useEffect ( ( ) => {
69- setInitialEvalApplied ( true ) ;
70- } , [ setInitialEvalApplied ] ) ;
71- return initialEvalApplied ? undefined : initialEvaluate ;
72- }
73-
7466const Shell = React . forwardRef < ShellType , ShellProps > ( function Shell (
75- { initialEvaluate : _initialEvaluate , ...props } ,
67+ { ...props } ,
7668 ref
7769) {
7870 const shellRef = useRef < ShellType | null > ( null ) ;
79- const initialEvaluate = useInitialEval ( _initialEvaluate ) ;
71+
8072 const mergeRef = useCallback (
8173 ( shell : ShellType | null ) => {
8274 shellRef . current = shell ;
@@ -93,26 +85,55 @@ const Shell = React.forwardRef<ShellType, ShellProps>(function Shell(
9385 shellRef . current ?. focusEditor ( ) ;
9486 } ) ;
9587 } , [ ] ) ;
88+
89+ return < _Shell ref = { mergeRef } { ...props } > </ _Shell > ;
90+ } ) ;
91+
92+ function useInitialEval ( initialEvaluate ?: string | string [ ] ) {
93+ const [ initialEvalApplied , setInitialEvalApplied ] = useTabState (
94+ 'initialEvalApplied' ,
95+ false
96+ ) ;
97+ useEffect ( ( ) => {
98+ setInitialEvalApplied ( true ) ;
99+ } , [ setInitialEvalApplied ] ) ;
100+ return initialEvalApplied ? undefined : initialEvaluate ;
101+ }
102+
103+ const normalizeInitialEvaluate = ( initialEvaluate : string | string [ ] ) => {
96104 return (
97- < _Shell
98- ref = { mergeRef }
99- initialEvaluate = { initialEvaluate }
100- { ...props }
101- > </ _Shell >
105+ Array . isArray ( initialEvaluate ) ? initialEvaluate : [ initialEvaluate ]
106+ ) . filter ( ( line ) => {
107+ // Filter out empty lines if passed by accident
108+ return ! ! line ;
109+ } ) ;
110+ } ;
111+
112+ const isInitialEvaluateEmpty = (
113+ initialEvaluate ?: string | string [ ] | undefined
114+ ) => {
115+ return (
116+ ! initialEvaluate || normalizeInitialEvaluate ( initialEvaluate ) . length === 0
102117 ) ;
103- } ) ;
118+ } ;
104119
105120const CompassShell : React . FC < CompassShellProps > = ( {
106121 runtime,
107122 initialHistory,
108123 onHistoryChange,
109- initialEvaluate,
124+ initialEvaluate : _initialEvaluate ,
110125 initialInput,
111126} ) => {
127+ const initialEvaluate = useInitialEval ( _initialEvaluate ) ;
128+
129+ const [ isOperationInProgress , setIsOperationInProgress ] = useTabState (
130+ 'isOperationInProgress' ,
131+ ! isInitialEvaluateEmpty ( initialEvaluate )
132+ ) ;
133+
112134 const enableShell = usePreference ( 'enableShell' ) ;
113135 const shellRef : ShellRef = useRef ( null ) ;
114136 const [ infoModalVisible , setInfoModalVisible ] = useState ( false ) ;
115- const [ isOperationInProgress , setIsOperationInProgress ] = useState ( false ) ;
116137 const [ shellOutput , setShellOutput ] = useTabState <
117138 readonly ShellOutputEntry [ ]
118139 > ( 'shellOutput' , [ ] ) ;
@@ -148,13 +169,13 @@ const CompassShell: React.FC<CompassShellProps> = ({
148169 [ setShellOutput ]
149170 ) ;
150171
151- const notifyOperationStarted = useCallback ( ( ) => {
172+ const onOperationStarted = useCallback ( ( ) => {
152173 setIsOperationInProgress ( true ) ;
153- } , [ ] ) ;
174+ } , [ setIsOperationInProgress ] ) ;
154175
155- const notifyOperationEnd = useCallback ( ( ) => {
176+ const onOperationEnd = useCallback ( ( ) => {
156177 setIsOperationInProgress ( false ) ;
157- } , [ ] ) ;
178+ } , [ setIsOperationInProgress ] ) ;
158179
159180 const canRenderShell = enableShell && initialHistory && runtime ;
160181
@@ -212,8 +233,9 @@ const CompassShell: React.FC<CompassShellProps> = ({
212233 onHistoryChanged = { ( history ) => {
213234 onHistoryChange ( [ ...history ] ) ;
214235 } }
215- onOperationStarted = { notifyOperationStarted }
216- onOperationEnd = { notifyOperationEnd }
236+ onOperationStarted = { onOperationStarted }
237+ onOperationEnd = { onOperationEnd }
238+ isOperationInProgress = { isOperationInProgress }
217239 maxOutputLength = { 1000 }
218240 maxHistoryLength = { 1000 }
219241 />
0 commit comments