MCPcopy
hub / github.com/Cveinnt/LiveTerm / Input

Function Input

src/components/input.tsx:7–105  ·  view source on GitHub ↗
({
  inputRef,
  containerRef,
  command,
  history,
  lastCommandIndex,
  setCommand,
  setHistory,
  setLastCommandIndex,
  clearHistory,
})

Source from the content-addressed store, hash-verified

5import { Ps1 } from './Ps1';
6
7export const Input = ({
8 inputRef,
9 containerRef,
10 command,
11 history,
12 lastCommandIndex,
13 setCommand,
14 setHistory,
15 setLastCommandIndex,
16 clearHistory,
17}) => {
18 const onSubmit = async (event: React.KeyboardEvent<HTMLInputElement>) => {
19 const commands: [string] = history
20 .map(({ command }) => command)
21 .filter((command: string) => command);
22
23 if (event.key === 'c' && event.ctrlKey) {
24 event.preventDefault();
25 setCommand('');
26 setHistory('');
27 setLastCommandIndex(0);
28 }
29
30 if (event.key === 'l' && event.ctrlKey) {
31 event.preventDefault();
32 clearHistory();
33 }
34
35 if (event.key === 'Tab') {
36 event.preventDefault();
37 handleTabCompletion(command, setCommand);
38 }
39
40 if (event.key === 'Enter' || event.code === '13') {
41 event.preventDefault();
42 setLastCommandIndex(0);
43 await shell(command, setHistory, clearHistory, setCommand);
44 containerRef.current.scrollTo(0, containerRef.current.scrollHeight);
45 }
46
47 if (event.key === 'ArrowUp') {
48 event.preventDefault();
49 if (!commands.length) {
50 return;
51 }
52 const index: number = lastCommandIndex + 1;
53 if (index <= commands.length) {
54 setLastCommandIndex(index);
55 setCommand(commands[commands.length - index]);
56 }
57 }
58
59 if (event.key === 'ArrowDown') {
60 event.preventDefault();
61 if (!commands.length) {
62 return;
63 }
64 const index: number = lastCommandIndex - 1;

Callers

nothing calls this directly

Calls 1

commandExistsFunction · 0.90

Tested by

no test coverage detected