terminal-in-react icon indicating copy to clipboard operation
terminal-in-react copied to clipboard

Make input command to lowercase.

Open Zeeshan-2k1 opened this issue 3 years ago • 1 comments

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?

Zeeshan-2k1 avatar Mar 11 '21 16:03 Zeeshan-2k1

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

mohammedfarish avatar May 27 '21 21:05 mohammedfarish