diff --git a/src/components/CLI/CLI.tsx b/src/components/CLI/CLI.tsx
index 50c1c6c..7db36b6 100644
--- a/src/components/CLI/CLI.tsx
+++ b/src/components/CLI/CLI.tsx
@@ -1,13 +1,21 @@
// src/components/CLI/CLI.tsx
'use client';
+import React from 'react';
// hooks
import { useCli } from './hooks/useCli';
+import { SyntaxPart } from '@/data/commandSyntaxMap';
interface CliProps {
decreaseCommandsLeft: () => void;
}
+const InlineHint = ({ part }: { part: SyntaxPart }) => (
+
+ {" " + part.syntax}
+
+);
+
export default function Cli({ decreaseCommandsLeft }: CliProps) {
const {
handleInputChange,
@@ -16,7 +24,10 @@ export default function Cli({ decreaseCommandsLeft }: CliProps) {
inputRef,
output,
command,
+ remainingSyntax
} = useCli(decreaseCommandsLeft);
+
+
return (
);
}
+
+
+
+
diff --git a/src/components/CLI/hooks/useCli.tsx b/src/components/CLI/hooks/useCli.tsx
index a6cfbb3..77ac688 100644
--- a/src/components/CLI/hooks/useCli.tsx
+++ b/src/components/CLI/hooks/useCli.tsx
@@ -1,9 +1,11 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
// react
import { useState, useEffect, useRef, KeyboardEvent, ChangeEvent } from 'react';
// utils
import { handleCommand } from '@/shared/utils/cliUtils';
import blacklistedCommands from '@/shared/utils/blacklist'; // Assuming you added blacklist here
+import { syntaxMap } from '@/data/commandSyntaxMap';
export const useCli = (decreaseCommandsLeft: () => void) => {
// states
@@ -13,11 +15,35 @@ export const useCli = (decreaseCommandsLeft: () => void) => {
//Initialise the command history with sessionStorage
const [commandHistory, setCommandHistory] = useState([]);
const [historyIndex, setHistoryIndex] = useState(-1);
+ const [remainingSyntax, setRemainingSyntax] = useState([]);
// useRefs
const terminalRef = useRef(null);
const inputRef = useRef(null);
+
+
+
+
+ const updateSyntax = (value: string) => {
+ const inputParts = value.trim().split(' ');
+ const command = inputParts[0].toUpperCase();
+
+ if (syntaxMap[command]) {
+ const parts = syntaxMap[command].parts;
+ if (inputParts.length === 1) {
+ // Only command typed, show all parts
+ setRemainingSyntax(parts);
+ } else {
+ // Show remaining parts based on what's already typed
+ const remainingParts = parts.slice(inputParts.length - 1);
+ setRemainingSyntax(remainingParts);
+ }
+ } else {
+ setRemainingSyntax([]);
+ }
+ };
+
const handleCommandWrapper = (e: KeyboardEvent) => {
if (e.key === 'Enter') {
const commandName = command.trim().split(' ')[0].toUpperCase(); // Extract the command
@@ -33,6 +59,7 @@ export const useCli = (decreaseCommandsLeft: () => void) => {
setCommand(''); // Clear input
decreaseCommandsLeft(); // Call to update remaining commands
+
}
};
@@ -61,7 +88,9 @@ export const useCli = (decreaseCommandsLeft: () => void) => {
}, []);
const handleInputChange = (e: ChangeEvent) => {
- setCommand(e.target.value);
+ const value = e.target.value;
+ setCommand(value);
+ updateSyntax(value);
};
const handleKeyDown = (e: KeyboardEvent) => {
@@ -71,6 +100,7 @@ export const useCli = (decreaseCommandsLeft: () => void) => {
setCommandHistory((prev) => [...prev, command]);
setHistoryIndex(-1);
}
+ setRemainingSyntax([])
}
if (e.key === 'ArrowUp') {
@@ -109,5 +139,6 @@ export const useCli = (decreaseCommandsLeft: () => void) => {
command,
tempCommand,
setTempCommand,
+ remainingSyntax
};
};
diff --git a/src/data/commandSyntaxMap.ts b/src/data/commandSyntaxMap.ts
new file mode 100644
index 0000000..4bf1a0b
--- /dev/null
+++ b/src/data/commandSyntaxMap.ts
@@ -0,0 +1,56 @@
+export type SyntaxPart = {
+ syntax: string;
+ doc: string;
+ }
+
+ export type CommandSyntax = {
+ parts: SyntaxPart[];
+ }
+
+ export type SyntaxMap = {
+ [command: string]: CommandSyntax;
+ }
+
+ export const syntaxMap: SyntaxMap = {
+ SET: {
+ parts: [
+ {
+ syntax: 'key',
+ doc: 'The key under which to store the value'
+ },
+ {
+ syntax: 'value',
+ doc: 'The value to be stored'
+ },
+ {
+ syntax: '[NX | XX]',
+ doc: 'NX - Only set if key does not exist. XX - Only set if key exists'
+ },
+ {
+ syntax: '[EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]',
+ doc: 'Options to set the key expiration: EX (seconds), PX (milliseconds), EXAT/PXAT (unix timestamp), or KEEPTTL to retain existing TTL'
+ }
+ ]
+ },
+ GET:{
+ parts: [
+ {
+ syntax:"Key",
+ doc:"Key of the value you want to retrive"
+ }
+ ]
+ },
+ DEL:{
+ parts: [
+ {
+ syntax:"Key",
+ doc:"Key that you want to delete"
+ },{
+ syntax:"[Key ...]",
+ doc:"Multiple keys you want to delete"
+ }
+ ]
+ },
+
+ };
+