cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div id="app" >Loading...</div>
<!-- React Component wrapper for jQuery Terinal library.
In order to use two way data binding from this example you need 1.11 version or devel branch if not yet released
-->
            
          
!
            
              .terminal {
  /* 10 lines - weird */
  height:calc(var(--size, 1) * 10 * 16px + 4px)
}
            
          
!
            
              class Terminal extends React.Component {
  componentDidMount() {
    // ignore command
    var {interpreter, command, ...options} = this.props;
    this.terminal = $(this.node).terminal(interpreter, options);
  }
  componentWillUnmount() {
    this.terminal.destroy();
  }
  isCommandControlled() {
    return this.props.command != undefined;
  }
  render() {
    if (this.terminal && this.isCommandControlled()) {
      this.terminal.set_command(this.props.command, true);
    }
    return (
      <div ref={(node) => this.node = node}></div>
    );
  }
}

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {command: ''};
  }
  update(command) {
    this.setState({
      command
    });
  }
  exec() {
    // we access internal representation, but we need this in order to have
    // enter in input to trigger enter in terminal
    this.terminal.exec(this.state.command);
    this.update('');
  }
  render() {
    let command = this.state.command;
    return (
      <div>
        <Terminal
          interpreter={(command, term) => {term.echo('you typed ' + command); }}
          outputLimit={0}
          command={command}
          onInit={(term) => {this.terminal = term}}
          onCommandChange={(command) => this.update(command)}
          greetings="ReactJS Terminal"/>
        <input value={command} onChange={(event) => this.update(event.target.value)}
               onKeyDown={(e) => { if (e.which == 13) { this.exec(); }}}/>
        <div>{command}</div>
      </div>
    );
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('app')
);

github('jcubic/jquery.terminal');
            
          
!
999px
Loading ..................

Console