-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathterminal.tsx
More file actions
43 lines (39 loc) · 1.19 KB
/
terminal.tsx
File metadata and controls
43 lines (39 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use client";
import Ansi from "ansi-to-react";
import { useEffect, useRef } from "react";
export function Terminal({
title,
children,
variant = "default",
}: {
title: string;
children: string;
variant?: "default" | "error";
}) {
const scrollRef = useRef<HTMLPreElement>(null);
useEffect(() => {
if (scrollRef.current) {
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
}
}, [children]);
return (
<div className="flex h-full flex-col">
<div className="flex items-center gap-2 border-b border-[rgba(255,255,255,0.1)] bg-black px-4 py-2">
<div className="flex gap-1.5">
<div className="h-2.5 w-2.5 rounded-full bg-[#484f58]" />
<div className="h-2.5 w-2.5 rounded-full bg-[#484f58]" />
<div className="h-2.5 w-2.5 rounded-full bg-[#484f58]" />
</div>
<span className="ml-2 text-xs text-[#484f58]">{title}</span>
</div>
<pre
ref={scrollRef}
className={`flex-1 overflow-auto bg-black p-4 font-mono text-sm leading-relaxed ${
variant === "error" ? "text-[#f85149]" : "text-[#e6edf3]"
}`}
>
<Ansi>{children}</Ansi>
</pre>
</div>
);
}