nitin42 / terminal-in-react

👨‍💻 A component that renders a terminal
http://terminal-in-react.surge.sh/
MIT License
2.12k stars 151 forks source link

Make input command to lowercase. #99

Open Zeeshan-2k1 opened 3 years ago

Zeeshan-2k1 commented 3 years ago

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?

mohammedfarish commented 3 years ago

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("hello@mohammedfarish.com");
        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