terminal-in-react
terminal-in-react copied to clipboard
Make input command to lowercase.
Generally, mobile users have autocorrect on or by default first letter as a capital letter. So we can have a .tolowercase() function on input string. So can I proceed with this issue and make a pr. Is it a valuable change?
It's currently not possible if you're going the ususal method, but I've found a workaround by using commandPassThrough
instead of commands
for all my commands.
commands(cmd, print) {
const command = cmd.join(" ").toLowerCase();
switch (command) {
case "email":
print("[email protected]");
break;
default:
print(`bash: command not found: ${cmd.join(" ")}`);
break;
}
}
renderHelp() {
const commandsList = [
{
name: "clear",
description: "Clears the terminal",
},
{
name: "email",
description: "Displays my email",
},
];
const parsedArray = [];
commandsList.forEach((comm) => {
const { name, description } = comm;
parsedArray.push(`${name} - ${description}`);
});
return parsedArray.join("\n\n");
}
render() {
const commandList = {
help: () => this.renderHelp(),
"-h": () => this.renderHelp(),
"--h": () => this.renderHelp(),
};
return (
<Terminal
commandPassThrough={(cmd, print) => this.commands(cmd, print)}
commands={commandList}
/>
)
You can checkout the full version of this code at https://github.com/mohammedfarish/website/blob/master/components/terminal/Terminal.jsx