Skip to content

Commit 1c0b7e4

Browse files
committed
feat: add Ctrl+L shortcut
1 parent 396c4e7 commit 1c0b7e4

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/components/terminal/TerminalBody.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ const TerminalBody: FC<TerminalBodyProps> = () => {
1818

1919
const scrollToRef = useRef<HTMLDivElement>(null);
2020

21+
function handleClear() {
22+
setHistory([]);
23+
setMotdVisible(false);
24+
}
25+
2126
function handlePromptEnter(prompt: string) {
2227
const { command, args, sudo } = processPrompt(prompt);
2328

2429
if (command === "clear") {
25-
setHistory([]);
26-
setMotdVisible(false);
30+
handleClear();
2731
return;
2832
}
2933

@@ -64,7 +68,10 @@ const TerminalBody: FC<TerminalBodyProps> = () => {
6468
))}
6569

6670
<TerminalPrompt username={username}>
67-
<TerminalPromptInput onEnter={handlePromptEnter} />
71+
<TerminalPromptInput
72+
onEnter={handlePromptEnter}
73+
onClear={handleClear}
74+
/>
6875
</TerminalPrompt>
6976

7077
<div ref={scrollToRef} />

src/components/terminal/TerminalPromptInput.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import { COMMAND_NAMES } from "../../lib/commands";
66

77
interface TerminalPromptInputProps {
88
onEnter(prompt: string): void;
9+
onClear(): void;
910
}
1011

11-
const TerminalPromptInput: FC<TerminalPromptInputProps> = ({ onEnter }) => {
12+
const TerminalPromptInput: FC<TerminalPromptInputProps> = ({
13+
onEnter,
14+
onClear,
15+
}) => {
1216
const [input, setInput] = useState("");
1317
const [inputFocus, setInputFocus] = useState(false);
1418
const [caretPosition, setCaretPosition] = useState(0);
@@ -30,6 +34,13 @@ const TerminalPromptInput: FC<TerminalPromptInputProps> = ({ onEnter }) => {
3034
e.preventDefault();
3135
setInput(autocompleteCommand);
3236
setCaretPosition(autocompleteCommand.length);
37+
return;
38+
}
39+
40+
if (e.ctrlKey && e.key === "l") {
41+
e.preventDefault();
42+
onClear();
43+
return;
3344
}
3445
}
3546

tailwind.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646
},
4747
boxShadow: {
4848
"5xl": "0 10px 30px 0 rgba(0, 0, 0, 0.75)",
49-
terminal: "0 0 0 2px rgba(0, 0, 0, 0.16)",
49+
terminal: "0 0 0 3px rgba(0, 0, 0, 0.16)",
5050
},
5151
},
5252
},

0 commit comments

Comments
 (0)