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

Is it possible to simulate typing? #911

Open
BasedXeno opened this issue Mar 29, 2021 · 1 comment
Open

Is it possible to simulate typing? #911

BasedXeno opened this issue Mar 29, 2021 · 1 comment

Comments

@BasedXeno
Copy link

BasedXeno commented Mar 29, 2021

Hi - thanks for making this software, it's great! I have a question - I would like the initial welcome message and subsequent messages to be printed to the screen 1 character at a time, with e.g. a 40ms delay. I've managed to use an interval + pushToStdout to do this, but each character is being printed on its own line, rather than in one line.

Is there an option I'm missing whereby I can simulate typing in this way, so that each pushToStdout can be configured to either print to a newline or to keep the new characters in the same line?

##UPDATE##
I managed to get the effect I want, but it feels pretty hacky, I'd be happy to know if someone has a better solution!

  useEffect(() => {
    const welcomeMessageDelay = setInterval(() => {
      const terminal = terminalRef.current;
      // console.dir(terminal);
      let cachedInput =
        (terminal.state.stdout[0] && terminal.state.stdout[0].message) || "";
      terminal.clearStdout();
      terminal.state.stdout.push({
        message: (cachedInput += welcomeText.shift()),
      });
      terminal.setState({
        stdout: terminal.state.stdout,
      });
      if (welcomeText.length === 0) {
        clearTimeout(welcomeMessageDelay);
      }
    }, 80);
    return function clearTimer() {
      clearTimeout(welcomeMessageDelay);
    };
  }, []);
@Sanskar-tyagi
Copy link

You can use [react-type-animation] to use this and then after that, u can callback a function to clear the Screen.

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