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

How to send a message to the terminal? #70

Open vBoykoGit opened 5 years ago

vBoykoGit commented 5 years ago

Hi, I want to send messages to terminal from code like console.log('message') but without showing it in application console

luisgrases commented 2 years ago

this might help:

  const printInTerminal = (content) => {
    terminalRef.current.state.instances[0].instance.updater.enqueueSetState(
      terminalRef.current.state.instances[0].instance,
      {
        summary: [
          ...terminalRef.current.state.instances[0].instance.state.summary,
          ...(Array.isArray(content) ? content.map((c) => [c]) : [content]),
        ],
      }
    );
  };

To print one line just do printInTerminal('Hello world!') To print multiple lines do printInTerminal(['Hello world!', 'Foo bar'])