chore: auto scroll
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ const isProduction = env === 'production';
|
|||||||
const t = Date.now();
|
const t = Date.now();
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
proxy: {
|
proxy: {
|
||||||
...proxy()
|
...proxy('http://192.168.50.166:8080')
|
||||||
},
|
},
|
||||||
history: {
|
history: {
|
||||||
type: 'hash'
|
type: 'hash'
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Terminal } from '@xterm/xterm';
|
|||||||
import '@xterm/xterm/css/xterm.css';
|
import '@xterm/xterm/css/xterm.css';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { memo, useCallback, useEffect, useRef } from 'react';
|
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import useSize from './use-size';
|
import useSize from './use-size';
|
||||||
|
|
||||||
@@ -23,8 +23,13 @@ const LogsViewer: React.FC<LogsViewerProps> = (props) => {
|
|||||||
const termwrapRef = useRef<any>({});
|
const termwrapRef = useRef<any>({});
|
||||||
const fitAddonRef = useRef<any>({});
|
const fitAddonRef = useRef<any>({});
|
||||||
const cacheDataRef = useRef<any>(null);
|
const cacheDataRef = useRef<any>(null);
|
||||||
|
const [logs, setLogs] = useState('');
|
||||||
const size = useSize(scroller);
|
const size = useSize(scroller);
|
||||||
|
|
||||||
|
const throttleScroll = _.debounce(() => {
|
||||||
|
termRef.current?.scrollToBottom?.();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
const updateContent = useCallback(
|
const updateContent = useCallback(
|
||||||
_.throttle((data: string) => {
|
_.throttle((data: string) => {
|
||||||
cacheDataRef.current = '';
|
cacheDataRef.current = '';
|
||||||
@@ -73,10 +78,9 @@ const LogsViewer: React.FC<LogsViewerProps> = (props) => {
|
|||||||
termRef.current.open(termwrapRef.current);
|
termRef.current.open(termwrapRef.current);
|
||||||
|
|
||||||
// add event
|
// add event
|
||||||
|
termRef.current.onLineFeed((e: any) => {
|
||||||
termRef.current.onWriteParsed((e: any) => {
|
|
||||||
if (cacheDataRef.current) {
|
if (cacheDataRef.current) {
|
||||||
termRef.current?.scrollToBottom();
|
throttleScroll();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user