Skip to content

Commit bf07b7c

Browse files
committed
webgl terminal renderer
1 parent 2c6094e commit bf07b7c

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

lib/console/console.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ export default class InkTerminal extends PaneItem {
9090
opts.windowsMode = true
9191
}
9292

93+
this.persistentState = {}
94+
this.persistentState.opts = opts
95+
96+
if (opts.rendererType === 'webgl') {
97+
this.isWebgl = true
98+
opts.rendererType = 'canvas'
99+
}
100+
93101
this.terminal = new Terminal(opts)
94102
const webLinksAddon = new WebLinksAddon((ev, uri) => openExternal(uri))
95103
this.terminal.loadAddon(webLinksAddon)
@@ -100,11 +108,8 @@ export default class InkTerminal extends PaneItem {
100108
this.fitAddon = new FitAddon()
101109
this.terminal.loadAddon(this.fitAddon)
102110

103-
104111
this.setTitle('Terminal')
105112

106-
this.persistentState = {}
107-
this.persistentState.opts = opts
108113
this.classname = ''
109114

110115
this.enterhandler = (e) => {
@@ -119,7 +124,7 @@ export default class InkTerminal extends PaneItem {
119124

120125
this.terminal.attachCustomKeyEventHandler(this.enterhandler)
121126

122-
this.view = new TerminalElement
127+
this.view = new TerminalElement()
123128

124129
this.searchui = new SearchUI(this.terminal, this.searchAddon)
125130

@@ -141,6 +146,30 @@ export default class InkTerminal extends PaneItem {
141146
return [this.terminal._core.buffer.x, this.terminal._core.buffer.y]
142147
}
143148

149+
setOption (key, val) {
150+
if (!this.persistentState) {
151+
this.persistentState = { opts: {} }
152+
}
153+
if (!this.persistentState.opts) {
154+
this.persistentState.opts = {}
155+
}
156+
157+
if (key === 'rendererType' && !this.element.initialized) {
158+
return
159+
}
160+
try {
161+
if (key === 'rendererType' && val === 'webgl') {
162+
this.persistentState.opts[key] = val
163+
val = 'canvas'
164+
} else {
165+
this.persistentState.opts[key] = val
166+
}
167+
this.terminal.setOption(key, val)
168+
} catch (err) {
169+
console.warn('Error while applying settings for terminal:', this, err)
170+
}
171+
}
172+
144173
update () {}
145174

146175
render () {

lib/console/view.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use babel'
22

33
import { CompositeDisposable } from 'atom'
4+
import { WebglAddon } from 'xterm-addon-webgl'
45
import ResizeDetector from 'element-resize-detector'
56
import { debounce, throttle } from 'underscore-plus'
67
import chroma from 'chroma-js'
@@ -24,6 +25,10 @@ class TerminalElement extends HTMLElement {
2425

2526
this.model.terminal.open(this)
2627

28+
if (this.model.isWebgl) {
29+
this.model.terminal.loadAddon(new WebglAddon())
30+
}
31+
2732
this.subs.add(atom.config.observe('editor.fontSize', (val) => {
2833
this.model.terminal.setOption('fontSize', val)
2934
}))

package-lock.json

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
"katex": "0.11.0",
2525
"replace-in-file": "^3.0.0",
2626
"underscore-plus": "^1.6.6",
27-
"xterm": "4.2.0",
27+
"xterm": "4.3.0",
2828
"xterm-addon-fit": "^0.3.0",
29-
"xterm-addon-search": "^0.3.0",
30-
"xterm-addon-web-links": "^0.2.1"
29+
"xterm-addon-search": "^0.4.0",
30+
"xterm-addon-web-links": "^0.2.1",
31+
"xterm-addon-webgl": "^0.4.0"
3132
},
3233
"scripts": {
3334
"postinstall": "node scripts/postinstall.js"

0 commit comments

Comments
 (0)