diff --git a/client/app/scripts/components/terminal.js b/client/app/scripts/components/terminal.js index d1989f28d..486edd62e 100644 --- a/client/app/scripts/components/terminal.js +++ b/client/app/scripts/components/terminal.js @@ -142,7 +142,12 @@ class Terminal extends React.Component { socket.onmessage = (event) => { log('pipe data', event.data.size); const input = ab2str(event.data); + const scrolledToBottom = term.ydisp === term.ybase; + const savedScrollPosition = term.ydisp; term.write(input); + if (!scrolledToBottom) { + this.scrollTo(savedScrollPosition); + } }; this.socket = socket; @@ -154,6 +159,19 @@ class Terminal extends React.Component { } } + scrollToBottom() { + this.scrollTo(this.term.ybase); + } + + scrollTo(y) { + if (!this.term) { + return; + } + this.term.ydisp = y; + this.term.emit('scroll', y); + this.term.refresh(0, this.term.rows - 1); + } + componentDidMount() { this._isMounted = true; if (this.props.connect) { @@ -167,12 +185,14 @@ class Terminal extends React.Component { cols: this.state.cols, rows: this.state.rows, convertEol: !this.props.raw, - cursorBlink: true + cursorBlink: true, + scrollback: 10000, }); const innerNode = ReactDOM.findDOMNode(component.innerFlex); this.term.open(innerNode); this.term.on('data', (data) => { + this.scrollToBottom(); if (this.socket) { this.socket.send(data); }