@@ -8,7 +8,7 @@ import {ITheme, IWindowsPty, Terminal as XTerminal} from '@xterm/xterm';
8
8
import { message } from 'antd' ;
9
9
import FontFaceObserver from 'fontfaceobserver' ;
10
10
import { isEmpty } from 'lodash' ;
11
- import { useCallback , useEffect , useRef , useState } from 'react' ;
11
+ import { Dispatch , SetStateAction , useCallback , useEffect , useRef , useState } from 'react' ;
12
12
import { useHotkeys } from 'react-hotkeys-hook' ;
13
13
import { useDispatch } from 'react-redux' ;
14
14
@@ -28,8 +28,8 @@ let resizeTimeout: any;
28
28
29
29
const FONT_FAMILY = 'JetBrainsMono' ;
30
30
31
- type Props = { runningCard : RunningCard } ;
32
- export default function Terminal ( { runningCard} : Props ) {
31
+ type Props = { runningCard : RunningCard ; setTerminalContent : Dispatch < SetStateAction < string > > } ;
32
+ export default function Terminal ( { runningCard, setTerminalContent } : Props ) {
33
33
const activeTab = useTabsState ( 'activeTab' ) ;
34
34
const allCards = useAllCards ( ) ;
35
35
@@ -104,6 +104,9 @@ export default function Terminal({runningCard}: Props) {
104
104
105
105
const writeData = useCallback (
106
106
( data : string ) => {
107
+ const xTerminal = terminal . current ;
108
+ if ( ! xTerminal ) return ;
109
+
107
110
if ( isEmpty ( webUIAddress ) && browserBehavior !== 'doNothing' ) {
108
111
const catchAddress = getCardMethod ( allCards , id , 'catchAddress' ) ;
109
112
const url = catchAddress ?.( data ) || '' ;
@@ -118,9 +121,20 @@ export default function Terminal({runningCard}: Props) {
118
121
}
119
122
}
120
123
}
121
- terminal . current ?. write ( outputColor ? parseTerminalColors ( data ) : data ) ;
124
+ xTerminal . write ( outputColor ? parseTerminalColors ( data ) : data ) ;
125
+
126
+ let fullText = '' ;
127
+ const buffer = xTerminal . buffer . active ;
128
+ for ( let i = 0 ; i < buffer . length ; i ++ ) {
129
+ const line = buffer . getLine ( i ) ?. translateToString ( true ) ;
130
+ if ( line ) {
131
+ fullText += line + '\n' ;
132
+ }
133
+ }
134
+
135
+ setTerminalContent ( fullText ) ;
122
136
} ,
123
- [ webUIAddress , id , browserBehavior , outputColor , dispatch , allCards , activeTab ] ,
137
+ [ webUIAddress , id , terminal , browserBehavior , outputColor , dispatch , allCards , activeTab ] ,
124
138
) ;
125
139
126
140
const onRightClickRef = useRef < ( ( e : MouseEvent ) => void ) | null > ( null ) ;
0 commit comments