import { Row, Col, Tooltip } from 'antd'; import { Delete, Enter } from '@ant-design/icons'; import { Terminal } from 'xterm'; import React, { useRef, useState, useEffect } from 'react'; import { useTerminal, usePrevious } from '../../hooks'; import styles from './index.module.less'; import { IUiApi } from 'umi-types'; export interface IProps { api: IUiApi; terminal: Terminal; log?: string; onClear?: any; size?: any; } const TerminalComponent: React.FC = ({ terminal, log, onClear, size = {}, api }) => { const { intl } = api; const domContainer = useRef(); const [, setInit] = useState(false); useEffect(() => { setInit(true); }, []); useTerminal({ terminal, ref: domContainer.current }); useEffect( () => { if (log) { terminal.write(log.replace(/\n/g, '\r\n')); } }, [log], ); // mount or updated const prevSize = usePrevious(size); useEffect( () => { if (prevSize) { if (prevSize.width !== size.width || prevSize.height !== size.height) { terminal.fit(); } } }, [size.width, size.height], ); const clear = () => { terminal.clear(); onClear && onClear(); }; const toBottom = () => { terminal.scrollToBottom(); }; return (
{intl({ id: 'org.umi.ui.tasks.log.title' })}
); }; export default TerminalComponent;