Skip to content

Commit

Permalink
WebGL renderer (using xterm.js fork) (#3368)
Browse files Browse the repository at this point in the history
* Enabling webGL renderer

* Use @zeit/xterm fork of xterm

* Adding webGLRenderer config

* Fix linting issues

* Allow for hot-reloading of webGLRenderer

* Adding link to WebGL renderer issue we're working around

* Using NPM tarball instead of resolutions (which wasn't working

* Hard-coding selection color to white because nothing else is yet supported
  • Loading branch information
juancampa authored and rauchg committed Dec 28, 2018
1 parent dd68286 commit 7a40fd7
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/config/config-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ module.exports = {
// to load it and avoid it being `npm install`ed
localPlugins: [],

webGLRenderer: true,

keymaps: {
// Example
// 'window:devtools': 'cmd+alt+o',
Expand Down
1 change: 1 addition & 0 deletions lib/components/term-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class TermGroup_ extends React.PureComponent {
borderColor: this.props.borderColor,
selectionColor: this.props.selectionColor,
quickEdit: this.props.quickEdit,
webGLRenderer: this.props.webGLRenderer,
uid
});

Expand Down
25 changes: 22 additions & 3 deletions lib/components/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ const getTermOptions = props => {
lineHeight: props.lineHeight,
letterSpacing: props.letterSpacing,
allowTransparency: needTransparency,
experimentalCharAtlas: 'dynamic',
// HACK: Terminal.setOption breaks if we don't apply these in this order
// TODO: The above notice can be removed once this is addressed:
// https://github.com/xtermjs/xterm.js/pull/1790#issuecomment-450000121
rendererType: props.webGLRenderer ? 'webgl' : 'canvas',
experimentalCharAtlas: props.webGLRenderer ? 'webgl' : 'dynamic',
theme: {
foreground: props.foregroundColor,
background: backgroundColor,
cursor: props.cursorColor,
cursorAccent: props.cursorAccentColor,
selection: props.selectionColor,
// TODO: This hard codes the selection color to opaque white because the
// webgl renderer doesn't support anything else at the moment. Remove this
// once WebGL gets support for selection color. Discussed here:
// https://github.com/xtermjs/xterm.js/pull/1790
selection: props.webGLRenderer ? '#fff' : props.selectionColor,
black: props.colors.black,
red: props.colors.red,
green: props.colors.green,
Expand Down Expand Up @@ -243,11 +251,22 @@ export default class Term extends React.PureComponent {
// Update only options that have changed.
Object.keys(nextTermOptions)
.filter(option => option !== 'theme' && nextTermOptions[option] !== this.termOptions[option])
.forEach(option => this.term.setOption(option, nextTermOptions[option]));
.forEach(option => {
try {
this.term.setOption(option, nextTermOptions[option]);
} catch (e) {
if (/The webgl renderer only works with the webgl char atlas/i.test(e.message)) {
// Ignore this because the char atlas will also be changed
} else {
throw e;
}
}
});

// Do we need to update theme?
const shouldUpdateTheme =
!this.termOptions.theme ||
nextTermOptions.rendererType !== this.termOptions.rendererType ||
Object.keys(nextTermOptions.theme).some(
option => nextTermOptions.theme[option] !== this.termOptions.theme[option]
);
Expand Down
1 change: 1 addition & 0 deletions lib/components/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class Terms extends React.Component {
onURLAbort: this.props.onURLAbort,
onContextMenu: this.props.onContextMenu,
quickEdit: this.props.quickEdit,
webGLRenderer: this.props.webGLRenderer,
parentProps: this.props
});

Expand Down
3 changes: 2 additions & 1 deletion lib/containers/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const TermsContainer = connect(
bellSoundURL: state.ui.bellSoundURL,
copyOnSelect: state.ui.copyOnSelect,
modifierKeys: state.ui.modifierKeys,
quickEdit: state.ui.quickEdit
quickEdit: state.ui.quickEdit,
webGLRenderer: state.ui.webGLRenderer
};
},
dispatch => {
Expand Down
7 changes: 6 additions & 1 deletion lib/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ const initial = Immutable({
},
showHamburgerMenu: '',
showWindowControls: '',
quickEdit: false
quickEdit: false,
webGLRenderer: true
});

const currentWindow = remote.getCurrentWindow();
Expand Down Expand Up @@ -237,6 +238,10 @@ const reducer = (state = initial, action) => {
ret.quickEdit = config.quickEdit;
}

if (typeof config.webGLRenderer !== undefined) {
ret.webGLRenderer = config.webGLRenderer;
}

ret._lastUpdate = now;

return ret;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"styled-jsx": "2.2.6",
"stylis": "3.5.0",
"uuid": "3.1.0",
"xterm": "3.9.1"
"xterm": "https://registry.npmjs.org/@zeit/xterm/-/xterm-3.9.1.tgz"
},
"devDependencies": {
"ava": "0.25.0",
Expand Down
5 changes: 2 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7111,10 +7111,9 @@ xtend@~2.1.1:
dependencies:
object-keys "~0.4.0"

xterm@3.9.1:
"xterm@https://registry.npmjs.org/@zeit/xterm/-/xterm-3.9.1.tgz":
version "3.9.1"
resolved "https://registry.yarnpkg.com/xterm/-/xterm-3.9.1.tgz#65756beb09bb6fb44aeb29032adcd6789aaaa5f4"
integrity sha512-5AZlhP0jvH/Sskx1UvvNFMqDRHVFqapl59rjV3RRpTJmveoharJplxPfzSThk85I4+AZo2xvD0X0nh0AAzkeZQ==
resolved "https://registry.npmjs.org/@zeit/xterm/-/xterm-3.9.1.tgz#576ba39c4159e8a31540b98a2bfebda4940e98ed"

y18n@^3.2.1:
version "3.2.1"
Expand Down

0 comments on commit 7a40fd7

Please sign in to comment.