Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make input command to lowercase. #99

Open
Zeeshan-2k1 opened this issue Mar 11, 2021 · 1 comment
Open

Make input command to lowercase. #99

Zeeshan-2k1 opened this issue Mar 11, 2021 · 1 comment

Comments

@Zeeshan-2k1
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants