mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-06 07:01:52 +09:00
feat(logs): full-bleed Terminal/Logs with follow-tail + LIVE badge
Terminal/Logs now fills the viewport like the Servers ops view (full-bleed flex layout through the Radix tab panel). LogContent sticks to the newest line on new content/selection (respecting manual scroll-up) and shows a floating LIVE badge while a log auto-follows its tail. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
cb83d24f7c
commit
ad4d7eb8bf
3 files changed
+163
-31
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { forwardRef, useMemo } from 'react';
|
||||
import { forwardRef, useMemo, useRef, useCallback, useLayoutEffect } from 'react';
|
||||
import { severityOf, splitOnMatch } from './logHelpers';
|
||||
|
||||
const LogContent = forwardRef(function LogContent({
|
||||
@@ -8,10 +8,44 @@ const LogContent = forwardRef(function LogContent({
|
||||
showLineNumbers,
|
||||
wrapLines,
|
||||
searchPattern,
|
||||
live = false,
|
||||
scrollKey,
|
||||
}, ref) {
|
||||
const lines = useMemo(() => {
|
||||
if (!content) return [];
|
||||
return content.split('\n');
|
||||
const innerRef = useRef(null);
|
||||
// Whether the viewer is parked at the bottom (following the tail). Starts
|
||||
// true so a freshly opened log lands on its newest line.
|
||||
const followRef = useRef(true);
|
||||
|
||||
// Merge our internal ref with the forwarded ref so the parent keeps its
|
||||
// direct scroll access (jump-to-end button, etc.) while we manage tailing.
|
||||
const setRefs = useCallback((node) => {
|
||||
innerRef.current = node;
|
||||
if (typeof ref === 'function') ref(node);
|
||||
else if (ref) ref.current = node;
|
||||
}, [ref]);
|
||||
|
||||
const lines = useMemo(() => (content ? content.split('\n') : []), [content]);
|
||||
|
||||
// Stop following once the user scrolls up; resume when they return to the
|
||||
// bottom — so live updates don't yank them away while reading history.
|
||||
const handleScroll = useCallback(() => {
|
||||
const el = innerRef.current;
|
||||
if (!el) return;
|
||||
followRef.current = el.scrollHeight - el.scrollTop - el.clientHeight < 48;
|
||||
}, []);
|
||||
|
||||
// New selection (different file / unit / service): jump to the newest line
|
||||
// and re-arm follow.
|
||||
useLayoutEffect(() => {
|
||||
followRef.current = true;
|
||||
const el = innerRef.current;
|
||||
if (el) el.scrollTop = el.scrollHeight;
|
||||
}, [scrollKey]);
|
||||
|
||||
// New content while following: stick to the last record.
|
||||
useLayoutEffect(() => {
|
||||
const el = innerRef.current;
|
||||
if (el && followRef.current) el.scrollTop = el.scrollHeight;
|
||||
}, [content]);
|
||||
|
||||
if (loading) {
|
||||
@@ -27,33 +61,42 @@ const LogContent = forwardRef(function LogContent({
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className={`lv-content ${wrapLines ? 'wrap' : 'nowrap'} ${showLineNumbers ? 'with-line-numbers' : ''}`}
|
||||
>
|
||||
<div className="lv-lines" role="presentation">
|
||||
{lines.map((line, idx) => {
|
||||
const sev = severityOf(line);
|
||||
const segments = searchPattern ? splitOnMatch(line, searchPattern) : null;
|
||||
return (
|
||||
<div key={idx} className={`lv-line ${sev ? `sev-${sev}` : ''}`}>
|
||||
{showLineNumbers && (
|
||||
<span className="lv-line-no">{idx + 1}</span>
|
||||
)}
|
||||
<span className="lv-line-text">
|
||||
{segments
|
||||
? segments.map((seg, i) =>
|
||||
seg.match ? (
|
||||
<mark key={i} className="lv-match">{seg.text}</mark>
|
||||
) : (
|
||||
<span key={i}>{seg.text}</span>
|
||||
<div className="lv-content-wrap">
|
||||
{live && (
|
||||
<span className="lv-live-badge" title="Following the live tail">
|
||||
<span className="lv-live-dot" />
|
||||
LIVE
|
||||
</span>
|
||||
)}
|
||||
<div
|
||||
ref={setRefs}
|
||||
onScroll={handleScroll}
|
||||
className={`lv-content ${wrapLines ? 'wrap' : 'nowrap'} ${showLineNumbers ? 'with-line-numbers' : ''}`}
|
||||
>
|
||||
<div className="lv-lines" role="presentation">
|
||||
{lines.map((line, idx) => {
|
||||
const sev = severityOf(line);
|
||||
const segments = searchPattern ? splitOnMatch(line, searchPattern) : null;
|
||||
return (
|
||||
<div key={idx} className={`lv-line ${sev ? `sev-${sev}` : ''}`}>
|
||||
{showLineNumbers && (
|
||||
<span className="lv-line-no">{idx + 1}</span>
|
||||
)}
|
||||
<span className="lv-line-text">
|
||||
{segments
|
||||
? segments.map((seg, i) =>
|
||||
seg.match ? (
|
||||
<mark key={i} className="lv-match">{seg.text}</mark>
|
||||
) : (
|
||||
<span key={i}>{seg.text}</span>
|
||||
)
|
||||
)
|
||||
)
|
||||
: (line || ' ')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
: (line || ' ')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user