diff --git a/src/components/logs-viewer/index.tsx b/src/components/logs-viewer/index.tsx index c69c050f..0c7ff197 100644 --- a/src/components/logs-viewer/index.tsx +++ b/src/components/logs-viewer/index.tsx @@ -4,7 +4,7 @@ import { Terminal } from '@xterm/xterm'; import '@xterm/xterm/css/xterm.css'; import classNames from 'classnames'; import _ from 'lodash'; -import { memo, useCallback, useEffect, useRef, useState } from 'react'; +import { memo, useCallback, useEffect, useRef } from 'react'; import './index.less'; import useSize from './use-size'; @@ -16,12 +16,11 @@ interface LogsViewerProps { } const LogsViewer: React.FC = (props) => { const { height, content, url } = props; - const [nowrap, setNowrap] = useState(false); const { setChunkRequest } = useSetChunkRequest(); const chunkRequedtRef = useRef(null); const scroller = useRef(null); const termRef = useRef(null); - const termInsRef = useRef(null); + const termwrapRef = useRef(null); const fitAddonRef = useRef(null); const cacheDatARef = useRef(null); const size = useSize(scroller); @@ -29,9 +28,9 @@ const LogsViewer: React.FC = (props) => { const updateContent = useCallback( _.throttle((data: string) => { cacheDatARef.current = data; - termRef.current?.reset(); + termRef.current?.clear?.(); termRef.current?.write?.(data); - }, 600), + }, 100), [] ); @@ -65,15 +64,10 @@ const LogsViewer: React.FC = (props) => { foreground: 'rgba(255,255,255,0.8)' }, cursorInactiveStyle: 'none' - // windowOptions: { - // setWinPosition: true, - // setWinSizePixels: true, - // refreshWin: true - // } }); fitAddonRef.current = new FitAddon(); termRef.current.loadAddon(fitAddonRef.current); - termRef.current.open(termInsRef.current); + termRef.current.open(termwrapRef.current); fitAddonRef.current?.fit(); }; @@ -89,10 +83,10 @@ const LogsViewer: React.FC = (props) => { }, [url, props.params]); useEffect(() => { - if (termInsRef.current) { + if (termwrapRef.current) { initTerm(); } - }, [termInsRef.current]); + }, [termwrapRef.current]); useEffect(() => { handleResize(); @@ -101,8 +95,8 @@ const LogsViewer: React.FC = (props) => { return (
-
-
+
+