11<script setup>
22import { useCommonStore } from " @/stores/common" ;
33import { logApi } from " @/api/v1" ;
4+ import { useModuleI18n } from " @/i18n/composables" ;
5+ import { normalizeTextInput } from " @/utils/inputValue" ;
46import { EventSourcePolyfill } from " event-source-polyfill" ;
7+
8+ const { tm } = useModuleI18n (" features/console" );
59 </script >
610
711<template >
@@ -10,8 +14,9 @@ import { EventSourcePolyfill } from "event-source-polyfill";
1014 class =" console-displayer-wrapper"
1115 :class =" { 'console-displayer-wrapper--workspace': workspaceMode }"
1216 >
13- <div class =" filter-controls mb-2" v-if =" showLevelBtns" >
17+ <div class =" filter-controls mb-2" v-if =" showLevelBtns || showSearch " >
1418 <v-chip-group
19+ v-if =" showLevelBtns"
1520 v-model =" selectedLevels"
1621 class =" log-level-filters"
1722 column
@@ -32,6 +37,21 @@ import { EventSourcePolyfill } from "event-source-polyfill";
3237 {{ level }}
3338 </v-chip >
3439 </v-chip-group >
40+ <v-text-field
41+ v-if =" showSearch"
42+ :model-value =" searchInput"
43+ @update:model-value =" searchInput = normalizeTextInput($event)"
44+ class =" log-search-field"
45+ density =" compact"
46+ variant =" solo-filled"
47+ flat
48+ hide-details
49+ single-line
50+ clearable
51+ prepend-inner-icon =" mdi-magnify"
52+ :aria-label =" tm('search.label')"
53+ :placeholder =" tm('search.placeholder')"
54+ ></v-text-field >
3555 <v-spacer ></v-spacer >
3656 <slot name =" header-actions" ></slot >
3757 <v-btn
@@ -73,6 +93,10 @@ export default {
7393 CRITICAL : " purple" ,
7494 },
7595 localLogCache: [],
96+ searchInput: " " ,
97+ // Trimmed keyword; an empty string disables filtering.
98+ searchKeyword: " " ,
99+ searchTimer: null ,
76100 eventSource: null ,
77101 retryTimer: null ,
78102 retryAttempts: 0 ,
@@ -99,6 +123,10 @@ export default {
99123 type: Boolean ,
100124 default: false ,
101125 },
126+ showSearch: {
127+ type: Boolean ,
128+ default: false ,
129+ },
102130 autoScroll: {
103131 type: Boolean ,
104132 default: true ,
@@ -118,6 +146,22 @@ export default {
118146 hideUserChat () {
119147 this .refreshDisplay ();
120148 },
149+ searchInput: {
150+ handler (value ) {
151+ if (this .searchTimer ) {
152+ clearTimeout (this .searchTimer );
153+ }
154+ this .searchTimer = setTimeout (() => {
155+ this .searchTimer = null ;
156+ const keyword = (value || " " ).trim ();
157+ if (keyword === this .searchKeyword ) {
158+ return ;
159+ }
160+ this .searchKeyword = keyword;
161+ this .refreshDisplay ();
162+ }, 250 );
163+ },
164+ },
121165 },
122166 async mounted () {
123167 await this .fetchLogHistory ();
@@ -137,6 +181,10 @@ export default {
137181 clearTimeout (this .retryTimer );
138182 this .retryTimer = null ;
139183 }
184+ if (this .searchTimer ) {
185+ clearTimeout (this .searchTimer );
186+ this .searchTimer = null ;
187+ }
140188 this .retryAttempts = 0 ;
141189 },
142190 methods: {
@@ -246,7 +294,8 @@ export default {
246294
247295 if (
248296 this .isLevelSelected (log .level ) &&
249- ! this .isHiddenByCategory (log)
297+ ! this .isHiddenByCategory (log) &&
298+ this .matchesKeyword (log)
250299 ) {
251300 if (fragment) {
252301 fragment .appendChild (this .buildLogElement (log .data ));
@@ -301,6 +350,52 @@ export default {
301350 return this .hideUserChat && log && log .category === " user_chat" ;
302351 },
303352
353+ matchesKeyword (log ) {
354+ if (! this .searchKeyword ) {
355+ return true ;
356+ }
357+ const text = (log .data || " " )
358+ .replace (/ \u001b \[ [0-9 ;] * m/ g , " " )
359+ .toLowerCase ();
360+ return text .includes (this .searchKeyword .toLowerCase ());
361+ },
362+
363+ // Appends `text` to `element`, wrapping keyword matches in a highlight span.
364+ appendHighlightedText (element , text ) {
365+ const keyword = this .searchKeyword ;
366+ if (! keyword || ! text) {
367+ element .textContent = text || " " ;
368+ return ;
369+ }
370+
371+ // Strip ANSI escape sequences first so highlight offsets line up with
372+ // the same stripped text used by `matchesKeyword`, and so no control
373+ // codes are rendered.
374+ const cleanText = text .replace (/ \u001b \[ [0-9 ;] * m/ g , " " );
375+ const lowerText = cleanText .toLowerCase ();
376+ const lowerKeyword = keyword .toLowerCase ();
377+ let cursor = 0 ;
378+ let index = lowerText .indexOf (lowerKeyword);
379+
380+ while (index !== - 1 ) {
381+ if (index > cursor) {
382+ element .appendChild (
383+ document .createTextNode (cleanText .slice (cursor, index)),
384+ );
385+ }
386+ const highlight = document .createElement (" span" );
387+ highlight .className = " console-log-highlight" ;
388+ highlight .textContent = cleanText .slice (index, index + keyword .length );
389+ element .appendChild (highlight);
390+ cursor = index + keyword .length ;
391+ index = lowerText .indexOf (lowerKeyword, cursor);
392+ }
393+
394+ if (cursor < cleanText .length ) {
395+ element .appendChild (document .createTextNode (cleanText .slice (cursor)));
396+ }
397+ },
398+
304399 refreshDisplay () {
305400 const termElement = document .getElementById (" term" );
306401 if (! termElement) return ;
@@ -312,7 +407,8 @@ export default {
312407 this .localLogCache .forEach ((logItem ) => {
313408 if (
314409 this .isLevelSelected (logItem .level ) &&
315- ! this .isHiddenByCategory (logItem)
410+ ! this .isHiddenByCategory (logItem) &&
411+ this .matchesKeyword (logItem)
316412 ) {
317413 fragment .appendChild (this .buildLogElement (logItem .data ));
318414 }
@@ -345,7 +441,7 @@ export default {
345441 / \[ (DEBG| INFO| WARN| ERRO| CRIT| DEBUG| WARNING| ERROR| CRITICAL)\] / ,
346442 );
347443 if (! levelMatch) {
348- element . textContent = ` ${ log} ` ;
444+ this . appendHighlightedText (element, log) ;
349445 return ;
350446 }
351447
@@ -356,15 +452,15 @@ export default {
356452
357453 const prefixSpan = document .createElement (" span" );
358454 prefixSpan .className = " console-log-prefix" ;
359- prefixSpan . textContent = prefix;
455+ this . appendHighlightedText (prefixSpan, prefix) ;
360456
361457 const levelSpan = document .createElement (" span" );
362458 levelSpan .className = " console-log-level" ;
363- levelSpan . textContent = levelMatch[0 ];
459+ this . appendHighlightedText (levelSpan, levelMatch[0 ]) ;
364460
365461 const messageSpan = document .createElement (" span" );
366462 messageSpan .className = " console-log-message" ;
367- messageSpan . textContent = message;
463+ this . appendHighlightedText (messageSpan, message) ;
368464
369465 element .classList .add (" console-log-line--structured" );
370466 element .appendChild (prefixSpan);
@@ -426,6 +522,12 @@ export default {
426522 margin-bottom : 8px ;
427523}
428524
525+ .log-search-field {
526+ flex : 0 1 260px ;
527+ max-width : 260px ;
528+ min-width : 160px ;
529+ }
530+
429531.console-term {
430532 background-color : #1e1e1e ;
431533 border-radius : 8px ;
@@ -520,6 +622,11 @@ export default {
520622 overflow-wrap : anywhere;
521623}
522624
625+ :deep(.console-log-highlight ) {
626+ background : rgba (255 , 213 , 79 , 0.35 );
627+ border-radius : 2px ;
628+ }
629+
523630@media (max-width : 768px ) {
524631 .console-displayer-wrapper--workspace {
525632 border-radius : 14px ;
@@ -541,11 +648,17 @@ export default {
541648 order : 1 ;
542649 }
543650
544- .console-displayer-wrapper--workspace :deep( .console-header-actions ) {
651+ .console-displayer-wrapper--workspace .log-search-field {
545652 flex : 1 1 100% ;
653+ max-width : none ;
546654 order : 3 ;
547655 }
548656
657+ .console-displayer-wrapper--workspace :deep(.console-header-actions ) {
658+ flex : 1 1 100% ;
659+ order : 4 ;
660+ }
661+
549662 .console-displayer-wrapper--workspace .fullscreen-btn {
550663 order : 2 ;
551664 }
0 commit comments