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

Change term.js library to xterm.js #1948

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Changed term.js lib to xterm.js
  • Loading branch information
jpellizzari committed Oct 27, 2016
commit ca49cfdfe6cacce1490eabf49abe5a65f2466462
5 changes: 2 additions & 3 deletions client/app/scripts/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ class App extends React.Component {
}

onKeyPress(ev) {
const { dispatch, searchFocused } = this.props;
const { dispatch, searchFocused, showingTerminal } = this.props;
//
// keyup gives 'key'
// keypress gives 'char'
// Distinction is important for international keyboard layouts where there
// is often a different {key: char} mapping.
//
if (!searchFocused) {
if (!searchFocused && !showingTerminal) {
keyPressLog('onKeyPress', 'keyCode', ev.keyCode, ev);
const char = String.fromCharCode(ev.charCode);
if (char === '<') {
Expand Down
1 change: 1 addition & 0 deletions client/app/scripts/components/debug-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class DebugToolbar extends React.Component {
<button onClick={() => enableLog('*')}>scope:*</button>
<button onClick={() => enableLog('dispatcher')}>scope:dispatcher</button>
<button onClick={() => enableLog('app-key-press')}>scope:app-key-press</button>
<button onClick={() => enableLog('terminal')}>scope:terminal</button>
<button onClick={() => disableLog()}>Disable log</button>
</div>

Expand Down
22 changes: 17 additions & 5 deletions client/app/scripts/components/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { clickCloseTerminal } from '../actions/app-actions';
import { getNeutralColor } from '../utils/color-utils';
import { setDocumentTitle } from '../utils/title-utils';
import { getPipeStatus, basePath } from '../utils/web-api-utils';
import Term from '../vendor/term.js';
import Term from 'xterm';

const wsProto = location.protocol === 'https:' ? 'wss' : 'ws';
const wsUrl = `${wsProto}://${location.host}${basePath(location.pathname)}`;
Expand All @@ -24,6 +24,7 @@ const MDASH = '\u2014';

const reconnectTimerInterval = 2000;


function ab2str(buf) {
// http://stackoverflow.com/questions/17191945/conversion-between-utf-8-arraybuffer-and-string
const encodedString = String.fromCharCode.apply(null, new Uint8Array(buf));
Expand Down Expand Up @@ -54,6 +55,7 @@ function terminalCellSize(wrapperNode, rows, cols) {
return {pixelPerCol, pixelPerRow};
}


function openNewWindow(url, bcr, minWidth = 200) {
const screenLeft = window.screenX || window.screenLeft;
const screenTop = window.screenY || window.screenTop;
Expand All @@ -74,6 +76,7 @@ function openNewWindow(url, bcr, minWidth = 200) {
window.open(url, '', windowOptionsString);
}


class Terminal extends React.Component {
constructor(props, context) {
super(props, context);
Expand Down Expand Up @@ -117,7 +120,11 @@ class Terminal extends React.Component {
}
this.socket = null;
const wereConnected = this.state.connected;
this.setState({connected: false});
if (this._isMounted) {
// Calling setState on an unmounted component will throw a warning.
// `connected` will get set to false by `componentWillUnmount`.
this.setState({connected: false});
}
if (this.term && this.props.pipe.get('status') !== 'PIPE_DELETED') {
if (wereConnected) {
this.createWebsocket(term);
Expand Down Expand Up @@ -148,19 +155,22 @@ class Terminal extends React.Component {
}

componentDidMount() {
this._isMounted = true;
if (this.props.connect) {
this.mountTerminal();
}
}

mountTerminal() {
const component = this;
this.term = new Term({
cols: this.state.cols,
rows: this.state.rows,
convertEol: !this.props.raw
convertEol: !this.props.raw,
cursorBlink: true
});

const innerNode = ReactDOM.findDOMNode(this.inner);
const innerNode = ReactDOM.findDOMNode(component.innerFlex);
this.term.open(innerNode);
this.term.on('data', (data) => {
if (this.socket) {
Expand All @@ -171,7 +181,7 @@ class Terminal extends React.Component {
this.createWebsocket(this.term);

const {pixelPerCol, pixelPerRow} = terminalCellSize(
innerNode, this.state.rows, this.state.cols);
this.term.element, this.state.rows, this.state.cols);

window.addEventListener('resize', this.handleResize);

Expand All @@ -185,6 +195,8 @@ class Terminal extends React.Component {
}

componentWillUnmount() {
this._isMounted = false;
this.setState({connected: false});
log('cwu terminal');

clearTimeout(this.reconnectTimeout);
Expand Down
Loading