@@ -204,6 +204,7 @@ const byteLen = reactive({
204
204
})
205
205
const showInputLine = ref <boolean >(true )
206
206
const terminalLog = ref <MessageGroup []>([])
207
+ const logSize = ref <number >(0 )
207
208
const searchCmdResult = reactive ({
208
209
// 避免默认提示板与输入框遮挡,某些情况下需要隐藏提示板
209
210
show: false ,
@@ -595,6 +596,7 @@ const _clearLog = (clearHistory: boolean) => {
595
596
store .clear (getName ())
596
597
} else {
597
598
terminalLog .value = [];
599
+ logSize .value = 0 ;
598
600
}
599
601
}
600
602
@@ -949,8 +951,10 @@ const _pushMessage = (message: Message | Array<Message> | string) => {
949
951
if (! message ) return
950
952
if (message instanceof Array ) {
951
953
for (let m of message ) {
952
- _pushMessage0 (m )
954
+ _pushMessage0 (m , false )
953
955
}
956
+ _checkLogSize ()
957
+ _jumpToBottom ()
954
958
return ;
955
959
}
956
960
@@ -967,6 +971,7 @@ const _pushMessage = (message: Message | Array<Message> | string) => {
967
971
}
968
972
969
973
_pushMessage0 (message )
974
+ _jumpToBottom ()
970
975
971
976
if (message .type === ' json' ) {
972
977
setTimeout (() => {
@@ -975,7 +980,7 @@ const _pushMessage = (message: Message | Array<Message> | string) => {
975
980
}
976
981
}
977
982
978
- const _pushMessage0 = (message : Message ) => {
983
+ const _pushMessage0 = (message : Message , checkSize : boolean = false ) => {
979
984
_filterMessageType (message )
980
985
if (message .type !== ' cmdLine' && props .pushMessageBefore ) {
981
986
props .pushMessageBefore (message , getName ())
@@ -988,15 +993,36 @@ const _pushMessage0 = (message: Message) => {
988
993
terminalLogLength = terminalLog .value .length
989
994
let logGroup = terminalLog .value [terminalLogLength - 1 ]
990
995
logGroup .logs .push (message )
996
+ logSize .value ++
991
997
992
- // 留 10% 的缓冲
993
- let limit = Math .floor (props .logSizeLimit * 1.1 )
994
- if (limit > 0 && terminalLogLength > limit ) {
995
- let left = terminalLogLength - props .logSizeLimit
996
- terminalLog .value .splice (0 , left )
998
+ if (checkSize ) {
999
+ _checkLogSize ()
997
1000
}
1001
+ }
998
1002
999
- _jumpToBottom ()
1003
+ const _checkLogSize = () => {
1004
+ if (props .logSizeLimit <= 0 ) {
1005
+ console .warn (" Invalid attribute 'log-size-limit':" , props .logSizeLimit )
1006
+ return ;
1007
+ }
1008
+
1009
+ // 留10%的缓冲
1010
+ let limit = Math .floor (props .logSizeLimit * 1.1 )
1011
+
1012
+ let count = logSize .value - limit ;
1013
+ while (count > 0 ) {
1014
+ let group = terminalLog .value [0 ]
1015
+ let leftCount = count - group .logs .length
1016
+ if (leftCount >= 0 ) {
1017
+ terminalLog .value .splice (0 , 1 )
1018
+ logSize .value -= group .logs .length
1019
+ } else {
1020
+ group .logs .splice (0 , count );
1021
+ group .fold = false
1022
+ logSize .value -= count
1023
+ }
1024
+ count = leftCount ;
1025
+ }
1000
1026
}
1001
1027
1002
1028
/**
0 commit comments