mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-09 02:12:59 +00:00
7637091e84
* feat(ui): add glassmorphism design tokens and utility classes Introduce glass design system foundation: translucent oklch color variables for both light and dark themes, glass/glass-border/glass-highlight tokens, semantic status colors (success/warning/info), .glass and .glass-strong utility classes with backdrop-filter, reduced shadow values, and standardized spring animation presets in lib/motion.ts. * feat(ui): apply glass treatment to core components Update card, dialog, input, button, popover, sheet, tooltip, dropdown-menu, context-menu, select, alert-dialog, and tabs components with glassmorphism styling: translucent backgrounds via new CSS variables, backdrop-blur layers, glass-border luminous edges, and glass-highlight hover states. * refactor(settings): decompose Settings Modal into section components Extract 10 inline sections from the 1,987-line SettingsModal into dedicated files under components/settings/. Introduce section registry pattern replacing 14 conditional blocks. Add shared types, sidebar navigation grouping with separators, glass treatment on sidebar and nav buttons, and responsive modal height. SettingsModal shell shrinks to ~380 lines. * refactor(ui): unify all tabs to animate-ui TabsHighlight with glass styling Migrate 4 tab instances (EditorLayout, FleetView, ResourcesView, NotificationsSection) from inconsistent patterns (manual layoutId, underline border-b-2, default fade) to the shared TabsHighlight primitive with glass-highlight indicator and springs.snappy transition. Standardize EditorLayout nav highlight spring config, apply glass-highlight to sidebar stack list hover/active states, and update mobile nav styling. * refactor(ui): migrate hardcoded colors to semantic CSS variables Replace hardcoded Tailwind color classes across ~19 component files with semantic CSS variable classes: emerald/green to success, orange/amber to warning, blue to info. Preserves brand/decorative colors (Crown amber, Admiral blue). Enables consistent theming of status indicators across the entire application. * refactor(ui): Linear dark precision aesthetic — solid surfaces, depth cues, text hierarchy Replace glassmorphism with Linear.app-inspired design: solid surface tokens (card #111111, sidebar #0d0d0d, root #0a0a0a), backdrop-blur restricted to floating overlays only (blur(10px) saturate(1.15)), desaturated teal accent, font-weight 500 everywhere, monochrome chart palette, and three depth cues: root ambient glow, luminous card top-edge, steep text brightness ramp. * refactor(ui): precision polish — fix muddy dark, snowblind light, add design anchors - Replace 34 hardcoded rgba values with theme-aware stat-* CSS tokens - Fix light theme: solid white cards, off-white background, readable text - Add card-border tokens with sharper directional lighting (top edge 2x) - Add chart-grid/chart-tick tokens for theme-aware axis rendering - Upgrade body glow: teal-tinted (dark), warm amber (light) - Terminal-inspired sidebar: monospaced UP/DN status codes, Geist Mono - Add tabular-nums to stat values to prevent layout jitter - Light mode cards get shadow-sm for depth against off-white background * refactor(ui): Linear materiality pass — ghosted nav, translucent sidebar, font unity - De-escalate Delete button from solid destructive to ghost with hover fill - Make sidebar translucent (80% opacity + backdrop-blur) so body glow bleeds through - Bump dark nav accent to 0.07 for ghosted backlit selection - Unify all terminal/editor fonts to Geist Mono (was JetBrains/Consolas mix) - Add Monaco editor fontFamily for YAML/env editing consistency - Add threshold-based color to Host RAM and Host Disk stat values (warn/crit) * refactor(ui): material simulation — inherent depth, layer separation, recessed terminal - Bump dark background 0.065→0.08, card surfaces 0.10→0.12 for 4% layer separation - Add card-bevel token (inset top shimmer) for permanent structural depth - Add button-inner-glow token for physical key feel on outline buttons - Recess terminal with inset shadow and dimmed label - Reduce action icon strokeWidth to 1.5 for refined industrial feel - Add teal LED backlight bar on active nav item via blur pseudo-element * fix(ui): parse usagePercent string to number for getValueColor usagePercent is typed as string in SystemStats but getValueColor expects number, causing TS2345 in CI builds.
291 lines
9.9 KiB
TypeScript
291 lines
9.9 KiB
TypeScript
import { Terminal } from '@xterm/xterm';
|
|
import { FitAddon } from '@xterm/addon-fit';
|
|
import { SearchAddon } from '@xterm/addon-search';
|
|
import { SerializeAddon } from '@xterm/addon-serialize';
|
|
import { useEffect, useRef, useState } from 'react';
|
|
import { Button } from './ui/button';
|
|
import { Input } from './ui/input';
|
|
import { Download, Search, ChevronUp, ChevronDown, X } from 'lucide-react';
|
|
import '@xterm/xterm/css/xterm.css';
|
|
|
|
interface TerminalComponentProps {
|
|
stackName?: string;
|
|
}
|
|
|
|
export default function TerminalComponent({ stackName }: TerminalComponentProps) {
|
|
const terminalRef = useRef<HTMLDivElement>(null);
|
|
const terminalInstance = useRef<Terminal | null>(null);
|
|
const fitAddonRef = useRef<FitAddon | null>(null);
|
|
const searchAddonRef = useRef<SearchAddon | null>(null);
|
|
const serializeAddonRef = useRef<SerializeAddon | null>(null);
|
|
const searchInputRef = useRef<HTMLInputElement>(null);
|
|
const wsRef = useRef<WebSocket | null>(null);
|
|
|
|
const [isSearchVisible, setIsSearchVisible] = useState(false);
|
|
const [searchText, setSearchText] = useState('');
|
|
|
|
useEffect(() => {
|
|
if (!terminalRef.current) {
|
|
console.error('Terminal ref not ready');
|
|
return;
|
|
}
|
|
|
|
// Clean up any existing terminal
|
|
if (terminalInstance.current) {
|
|
try {
|
|
terminalInstance.current.dispose();
|
|
} catch {
|
|
// Ignore dispose errors
|
|
}
|
|
}
|
|
if (wsRef.current) {
|
|
try {
|
|
wsRef.current.close();
|
|
} catch {
|
|
// Ignore close errors
|
|
}
|
|
}
|
|
|
|
let mounted = true;
|
|
|
|
const initTerminal = () => {
|
|
if (!mounted || !terminalRef.current) return;
|
|
|
|
try {
|
|
const term = new Terminal({
|
|
cursorBlink: true,
|
|
convertEol: true,
|
|
allowProposedApi: true,
|
|
theme: {
|
|
background: '#0d1117',
|
|
foreground: '#e6edf3',
|
|
cursor: '#58a6ff',
|
|
black: '#484f58',
|
|
red: '#ff7b72',
|
|
green: '#3fb950',
|
|
yellow: '#d29922',
|
|
blue: '#58a6ff',
|
|
magenta: '#bc8cff',
|
|
cyan: '#39c5cf',
|
|
white: '#b1bac4',
|
|
brightBlack: '#6e7681',
|
|
brightRed: '#ffa198',
|
|
brightGreen: '#56d364',
|
|
brightYellow: '#e3b341',
|
|
brightBlue: '#79c0ff',
|
|
brightMagenta: '#d2a8ff',
|
|
brightCyan: '#56d4dd',
|
|
brightWhite: '#ffffff',
|
|
},
|
|
fontFamily: "'Geist Mono', monospace",
|
|
fontSize: 13,
|
|
scrollback: 10000,
|
|
});
|
|
|
|
const fitAddon = new FitAddon();
|
|
const searchAddon = new SearchAddon();
|
|
const serializeAddon = new SerializeAddon();
|
|
|
|
term.loadAddon(fitAddon);
|
|
term.loadAddon(searchAddon);
|
|
term.loadAddon(serializeAddon);
|
|
|
|
fitAddonRef.current = fitAddon;
|
|
searchAddonRef.current = searchAddon;
|
|
serializeAddonRef.current = serializeAddon;
|
|
|
|
term.open(terminalRef.current);
|
|
terminalInstance.current = term;
|
|
|
|
// Custom key handler for Ctrl+F
|
|
term.attachCustomKeyEventHandler((event) => {
|
|
if (event.ctrlKey && event.key === 'f' && event.type === 'keydown') {
|
|
event.preventDefault();
|
|
setIsSearchVisible(prev => {
|
|
const next = !prev;
|
|
if (next) {
|
|
setTimeout(() => searchInputRef.current?.focus(), 50);
|
|
}
|
|
return next;
|
|
});
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
|
|
// Fit after DOM paint using requestAnimationFrame
|
|
requestAnimationFrame(() => {
|
|
if (!mounted || !fitAddonRef.current || !terminalRef.current) return;
|
|
try {
|
|
fitAddonRef.current.fit();
|
|
} catch (err) {
|
|
console.error('Error fitting terminal:', err);
|
|
}
|
|
});
|
|
|
|
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const cleanStackName = stackName?.replace(/\.(yml|yaml)$/, '');
|
|
const activeNodeId = localStorage.getItem('sencho-active-node') || '';
|
|
|
|
// If a stackName is provided, connect to the dedicated logs WebSocket
|
|
// Otherwise, fall back to the generic terminal WebSocket
|
|
const wsUrl = cleanStackName
|
|
? `${wsProtocol}//${window.location.host}/api/stacks/${cleanStackName}/logs${activeNodeId ? `?nodeId=${activeNodeId}` : ''}`
|
|
: `${wsProtocol}//${window.location.host}`;
|
|
|
|
const ws = new WebSocket(wsUrl);
|
|
wsRef.current = ws;
|
|
|
|
ws.onopen = () => {
|
|
if (mounted) {
|
|
if (!cleanStackName) {
|
|
// Generic terminal mode - send connect action
|
|
ws.send(JSON.stringify({ action: 'connectTerminal' }));
|
|
}
|
|
// For stack logs mode, the server starts streaming automatically on connection
|
|
}
|
|
};
|
|
|
|
ws.onmessage = (event) => {
|
|
if (mounted && terminalInstance.current) {
|
|
const text = typeof event.data === 'string' ? event.data : event.data.toString();
|
|
terminalInstance.current.write(text.replace(/\r?\n/g, '\r\n'));
|
|
}
|
|
};
|
|
|
|
ws.onerror = (err) => {
|
|
console.error('WebSocket error:', err);
|
|
};
|
|
|
|
} catch (err) {
|
|
console.error('Error initializing terminal:', err);
|
|
}
|
|
};
|
|
|
|
// Initialize terminal after a small delay to ensure container is rendered
|
|
const timeoutId = setTimeout(initTerminal, 50);
|
|
|
|
// Attach ResizeObserver to the terminal's parent container
|
|
let resizeTimeout: number | undefined;
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
if (resizeTimeout) clearTimeout(resizeTimeout);
|
|
resizeTimeout = setTimeout(() => {
|
|
if (fitAddonRef.current && terminalRef.current && mounted) {
|
|
try {
|
|
fitAddonRef.current.fit();
|
|
} catch {
|
|
// Ignore fit errors during resize
|
|
}
|
|
}
|
|
}, 50);
|
|
});
|
|
|
|
if (terminalRef.current.parentElement) {
|
|
resizeObserver.observe(terminalRef.current.parentElement);
|
|
}
|
|
|
|
return () => {
|
|
mounted = false;
|
|
clearTimeout(timeoutId);
|
|
resizeObserver.disconnect();
|
|
if (wsRef.current) {
|
|
try {
|
|
wsRef.current.close();
|
|
} catch {
|
|
// Ignore close errors
|
|
}
|
|
wsRef.current = null;
|
|
}
|
|
if (terminalInstance.current) {
|
|
try {
|
|
terminalInstance.current.dispose();
|
|
} catch {
|
|
// Ignore dispose errors
|
|
}
|
|
terminalInstance.current = null;
|
|
}
|
|
fitAddonRef.current = null;
|
|
searchAddonRef.current = null;
|
|
serializeAddonRef.current = null;
|
|
};
|
|
}, [stackName]);
|
|
|
|
const handleDownload = () => {
|
|
if (!serializeAddonRef.current) return;
|
|
const content = serializeAddonRef.current.serialize();
|
|
const blob = new Blob([content], { type: 'text/plain' });
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
a.download = `logs-${stackName || 'terminal'}-${timestamp}.txt`;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
URL.revokeObjectURL(url);
|
|
};
|
|
|
|
const handleSearchNext = () => {
|
|
if (!searchAddonRef.current || !searchText) return;
|
|
searchAddonRef.current.findNext(searchText);
|
|
};
|
|
|
|
const handleSearchPrev = () => {
|
|
if (!searchAddonRef.current || !searchText) return;
|
|
searchAddonRef.current.findPrevious(searchText);
|
|
};
|
|
|
|
const handleSearchKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
if (e.key === 'Enter') {
|
|
if (e.shiftKey) handleSearchPrev();
|
|
else handleSearchNext();
|
|
} else if (e.key === 'Escape') {
|
|
setIsSearchVisible(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="flex flex-col h-full w-full relative group">
|
|
{/* Floating Action Bar / Search Bar Panel */}
|
|
<div className={`absolute top-2 right-6 z-10 flex gap-2 transition-opacity duration-200 ${isSearchVisible ? 'opacity-100' : 'opacity-0 group-hover:opacity-100 focus-within:opacity-100'}`}>
|
|
{!isSearchVisible ? (
|
|
<Button variant="outline" size="sm" onClick={() => {
|
|
setIsSearchVisible(true);
|
|
setTimeout(() => searchInputRef.current?.focus(), 50);
|
|
}} className="h-8 bg-background/80 backdrop-blur-sm shadow-sm" title="Search (Ctrl+F)">
|
|
<Search className="w-4 h-4 mr-2" />
|
|
Search
|
|
</Button>
|
|
) : (
|
|
<div className="flex flex-row items-center p-1 pr-1 bg-background/95 backdrop-blur-sm border border-border shadow-md rounded-md">
|
|
<Input
|
|
ref={searchInputRef}
|
|
value={searchText}
|
|
onChange={(e) => setSearchText(e.target.value)}
|
|
onKeyDown={handleSearchKeyDown}
|
|
placeholder="Find in terminal..."
|
|
className="h-7 w-48 border-none focus-visible:ring-0 bg-transparent text-sm min-h-0"
|
|
/>
|
|
<Button variant="ghost" size="icon" className="h-6 w-6" onClick={handleSearchPrev} title="Previous (Shift+Enter)">
|
|
<ChevronUp className="w-4 h-4" />
|
|
</Button>
|
|
<Button variant="ghost" size="icon" className="h-6 w-6" onClick={handleSearchNext} title="Next (Enter)">
|
|
<ChevronDown className="w-4 h-4" />
|
|
</Button>
|
|
<div className="w-px h-4 bg-border mx-1" />
|
|
<Button variant="ghost" size="icon" className="h-6 w-6 hover:bg-destructive/10 hover:text-destructive" onClick={() => setIsSearchVisible(false)} title="Close (Esc)">
|
|
<X className="w-4 h-4" />
|
|
</Button>
|
|
</div>
|
|
)}
|
|
|
|
<Button variant="outline" size="sm" onClick={handleDownload} className="h-8 bg-background/80 backdrop-blur-sm shadow-sm" title="Download Logs">
|
|
<Download className="w-4 h-4 mr-2" />
|
|
Download
|
|
</Button>
|
|
</div>
|
|
|
|
<div ref={terminalRef} className="flex-1 w-full overflow-hidden" />
|
|
</div>
|
|
);
|
|
} |