Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app" >Loading...</div>
<!-- React Component wrapper for jQuery Terminal library.
In order to use two way data binding from this example you need at least version 1.11.0 of jQuery Terminal (that version introduced silent option to terminal::set_command so it don't trigger recursive render, because it don't trigger onCommandChange event)

See also: DTerm (UI dialog) with ReactJS

https://codepen.io/jcubic/pen/rZpjvL
-->

              
            
!

CSS

              
                .terminal {
  /* 10 lines - weird */
  height:calc(var(--size, 1) * 10 * 16px + 4px)
}
              
            
!

JS

              
                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

Console