Skip to content

Commit a66e558

Browse files
committed
Add node-canvas help increase the testable surface
This is at least a first step towards fixing xtermjs#1247. This adds some complexity to the initial setup, since canvas needs to be built from source. This won't be true once canvas 2.x is stabilized, because that version downloads (Automattic/node-canvas#992). JSDom doesn't support 2.x, and doesn't plan to (jsdom/jsdom#1964) until a stable release is cut. We could use [canvas-prebuilt](https://github.com/node-gfx/node-canvas-prebuilt), which JSDom does appear to support. However, I'm not sure if that would cause pain for people with 32-bit operating systems (see the compatibility table on that page). I'm not sure if this travis configuration will work; I'll iterate on it in the PR if it fails. I removed a bunch of hacks that were added in xtermjs#690, since they don't look necessary anymore (the sleep module is gone).
1 parent cf8fa10 commit a66e558

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

.travis.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ os:
44
node_js:
55
- 6
66
before_install:
7-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test ; fi
8-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq update ; fi
9-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq install g++-4.8 ; fi
10-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-4.8 ; fi
117
- npm install -g [email protected]
8+
addons:
9+
apt:
10+
sources:
11+
- ubuntu-toolchain-r-test
12+
packages:
13+
- libcairo2-dev
14+
- libjpeg8-dev
15+
- libpango1.0-dev
16+
- libgif-dev
17+
- g++-4.9
1218
env:
19+
global:
20+
- CXX=g++-4.9
1321
matrix:
1422
- NPM_COMMAND=tsc
1523
- NPM_COMMAND=lint

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,19 @@ Then open http://0.0.0.0:3000 in a web browser to access the demo.
185185

186186
### Linux or macOS
187187

188-
First, be sure that a C++ compiler such as GCC-C++ or Clang is installed, then run the following commands in your terminal:
188+
First, be sure that a C++ compiler such as GCC-C++ or Clang is installed.
189+
190+
Then, depending on your operating system and distribution, run one of the following:
191+
192+
OS | Command
193+
----- | -----
194+
OS X | Using [Homebrew](https://brew.sh/):<br/>`brew install pkg-config cairo pango libpng jpeg giflib`<br/><br/>Using [MacPorts](https://www.macports.org/):<br/>`port install pkgconfig cairo pango libpng jpeg giflib`
195+
Ubuntu | `sudo apt-get install libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++`
196+
Fedora | `sudo yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel`
197+
198+
*This table is borrowed from [the node-canvas documentation](https://github.com/Automattic/node-canvas/blob/master/Readme.md#compiling).*
199+
200+
Then run the following commands in your terminal:
189201

190202
```
191203
npm install
@@ -197,7 +209,7 @@ Then open http://0.0.0.0:3000 in a web browser to access the demo.
197209

198210
### Windows
199211

200-
First, ensure [node-gyp](https://github.com/nodejs/node-gyp) is installed and configured correctly, then run the following commands in your terminal:
212+
First, [follow the node-canvas setup instructions](https://github.com/Automattic/node-canvas/wiki/Installation---Windows), then run the following commands in your terminal:
201213

202214
```
203215
npm install

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@types/node": "^6.0.41",
4646
"@types/text-encoding": "0.0.32",
4747
"browserify": "^13.3.0",
48+
"canvas": "^1.6.10",
4849
"chai": "3.5.0",
4950
"express": "4.13.4",
5051
"express-ws": "2.0.0-rc.1",

src/renderer/ColorManager.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ describe('ColorManager', () => {
1717
dom = new jsdom.JSDOM('');
1818
window = dom.window;
1919
document = window.document;
20-
(<any>window).HTMLCanvasElement.prototype.getContext = () => ({
21-
createLinearGradient(): any {
22-
return null;
23-
},
24-
25-
fillRect(): void { },
26-
27-
getImageData(): any {
28-
return {data: [0, 0, 0, 0xFF]};
29-
}
30-
});
3120
cm = new ColorManager(document, false);
3221
});
3322

@@ -309,5 +298,17 @@ describe('ColorManager', () => {
309298
// FG reverts back to default
310299
assert.equal(cm.colors.foreground.css, '#ffffff');
311300
});
301+
302+
it('should parse rgb colors', () => {
303+
cm.setTheme({
304+
background: '#123456',
305+
foreground: 'rgb(111, 222, 33)',
306+
});
307+
assert.equal(cm.colors.background.rgba, 0x123456FF);
308+
assert.equal(cm.colors.foreground.rgba >>> 24, 111);
309+
assert.equal(cm.colors.foreground.rgba >>> 16 & 0xFF, 222);
310+
assert.equal(cm.colors.foreground.rgba >>> 8 & 0xFF, 33);
311+
assert.equal(cm.colors.foreground.rgba & 0xFF, 0xFF);
312+
});
312313
});
313314
});

0 commit comments

Comments
 (0)