Skip to content

Commit fabe794

Browse files
committed
feat: don't blink the cursor while typing
1 parent f4791b2 commit fabe794

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/assets/kali-layers.png

-2.3 MB
Binary file not shown.

src/assets/kali-layers.webp

48.8 KB
Binary file not shown.

src/components/terminal/TerminalPromptInput.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Fragment,
55
KeyboardEvent,
66
useEffect,
7+
useRef,
78
useState,
89
} from "react";
910
import { twMerge } from "tailwind-merge";
@@ -24,6 +25,9 @@ const TerminalPromptInput: FC<TerminalPromptInputProps> = ({
2425
}) => {
2526
const [input, setInput] = useState("");
2627
const [inputFocus, setInputFocus] = useState(false);
28+
const [shouldBlink, setShouldBlink] = useState(true);
29+
const shouldBlinkTimeoutRef = useRef<number>();
30+
2731
const [caretPosition, setCaretPosition] = useState(0);
2832
const [currentHistoryIndex, setCurrentHistoryIndex] = useState(
2933
history.length
@@ -87,9 +91,17 @@ const TerminalPromptInput: FC<TerminalPromptInputProps> = ({
8791
onClick={(e) => setCaretPosition(e.currentTarget.selectionStart ?? 0)}
8892
onKeyDown={handleKeyDown}
8993
onChange={(e) => {
94+
clearTimeout(shouldBlinkTimeoutRef.current);
95+
9096
setInput(e.target.value);
9197
setCaretPosition(e.target.selectionStart ?? 0);
9298
setCurrentHistoryIndex(history.length);
99+
100+
setShouldBlink(false);
101+
shouldBlinkTimeoutRef.current = setTimeout(
102+
() => setShouldBlink(true),
103+
500
104+
);
93105
}}
94106
className="w-full cursor-default whitespace-nowrap bg-transparent p-0 text-kali-white text-transparent focus:outline-none"
95107
/>
@@ -110,7 +122,10 @@ const TerminalPromptInput: FC<TerminalPromptInputProps> = ({
110122
>
111123
{inputFocus && (
112124
<span
113-
className="content[''] absolute top-0 h-[20px] w-2 animate-blink bg-kali-gray/[.8]"
125+
className={twMerge(
126+
"content[''] absolute top-0 h-[20px] w-2 bg-kali-gray/[.8]",
127+
shouldBlink && "animate-blink"
128+
)}
114129
style={{ left: `${input.length === 0 ? 0 : caretPosition}ch` }}
115130
/>
116131
)}

tailwind.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
theme: {
55
extend: {
66
backgroundImage: {
7-
kali: "url('./assets/kali-layers.png')",
7+
kali: "url('./assets/kali-layers.webp')",
88
},
99
colors: {
1010
"kali-text-muted": "#8C8C8C",

0 commit comments

Comments
 (0)