Skip to content

Commit ddc993b

Browse files
committed
feature(cursor-blink) add
1 parent 6101ed2 commit ddc993b

File tree

10 files changed

+114
-2
lines changed

10 files changed

+114
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
npm-debug.log
3+
.nyc_output
34

45
dist
56
dist-dev

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
webpack.config.js
44
client
5+
test
56

67
img
78

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_js:
55

66
script:
77
- npm run lint
8+
- npm run coverage && npm run report
89

910
notifications:
1011
email:

client/cursor-blink.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const currify = require('currify/legacy');
4+
5+
module.exports = currify((terminal, blink) => {
6+
terminal.setOption('cursorBlink', blink);
7+
});
8+

client/gritty.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ require('../css/gritty.css');
55

66
require('xterm/dist/addons/fit');
77

8+
const cursorBlink = require('./cursor-blink');
9+
810
const io = require('socket.io-client/dist/socket.io.min');
911
const timeout = (fn) => () => setTimeout(fn);
1012

@@ -42,6 +44,8 @@ function createTerminal(terminalContainer, {env, socket}) {
4244
theme: 'gritty',
4345
});
4446

47+
const blink = cursorBlink(terminal);
48+
4549
terminal.open(terminalContainer);
4650
terminal.fit();
4751

@@ -63,15 +67,15 @@ function createTerminal(terminalContainer, {env, socket}) {
6367

6468
// auth check delay
6569
socket.on('connect', timeout(() => {
66-
terminal.setOption('cursorBlink', true);
70+
blink(true);
6771

6872
socket.emit('terminal', {env, cols, rows});
6973
socket.emit('resize', {cols, rows});
7074
}));
7175

7276
socket.on('disconnect', () => {
7377
terminal.writeln('terminal disconnected...');
74-
terminal.setOption('cursorBlink', false);
78+
blink(false);
7579
});
7680

7781
socket.on('data', (data) => {

client/sinon.js

Whitespace-only changes.

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
"lint:eslint:server": "eslint --rule 'no-console:0' bin server",
1919
"lint:eslint:client": "eslint --env browser --config .eslintrc client",
2020
"lint": "redrun lint:*",
21+
"coverage": "nyc npm test",
22+
"test": "tape 'test/**/*.js'",
23+
"report": "nyc report --reporter=text-lcov | coveralls",
24+
"watch:coverage": "npm run watcher -- npm run coverage",
25+
"watch:test": "npm run watcher -- npm test",
26+
"watcher": "nodemon -w test -w lib --exec",
2127
"6to5:lib": "babel server -d server_",
2228
"6to5:bin": "babel bin -d legacy/bin",
2329
"6to5:client": "webpack --progress",
@@ -54,9 +60,12 @@
5460
"eslint": "^3.10.2",
5561
"json-loader": "^0.5.4",
5662
"nodemon": "^1.11.0",
63+
"nyc": "^10.2.0",
5764
"promise-polyfill": "^6.0.2",
5865
"redrun": "^5.9.3",
66+
"sinon": "^2.1.0",
5967
"style-loader": "^0.16.0",
68+
"tape": "^4.6.3",
6069
"webpack": "^2.2.1",
6170
"whatwg-fetch": "^2.0.2",
6271
"xterm": "^2.4.0"

test/client/cursor-blink.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const test = require('tape');
4+
const sinon = require('../sinon');
5+
6+
const cursorBlink = require('../../client/cursor-blink');
7+
8+
test('gritty: cursor-blink: setOption: true', (t) => {
9+
const setOption = sinon.stub();
10+
11+
cursorBlink({setOption}, true);
12+
13+
t.ok(setOption.calledWith('cursorBlink', true), 'should call setOption with true');
14+
t.end();
15+
});
16+
17+
test('gritty: cursor-blink: setOption: true', (t) => {
18+
const setOption = sinon.stub();
19+
20+
cursorBlink({setOption}, false);
21+
22+
t.ok(setOption.calledWith('cursorBlink', false), 'should call setOption with false');
23+
t.end();
24+
});
25+

test/sinon-called-with-diff.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
/* eslint-disable no-console */
4+
5+
const chalk = require('chalk');
6+
7+
module.exports = (sinon) => {
8+
const {stub} = sinon;
9+
10+
sinon.stub = () => {
11+
const fn = stub();
12+
const {calledWith:original} = fn;
13+
14+
fn.calledWith = (...args) => {
15+
if (original.apply(fn, args))
16+
return true;
17+
18+
return calledWith.apply(fn, args);
19+
};
20+
21+
return fn;
22+
};
23+
24+
Object.assign(sinon.stub, stub);
25+
26+
return sinon;
27+
};
28+
29+
function calledWith(...args) {
30+
if (!this.called) {
31+
write(`expected to call with ${JSON.stringify(this.args)}, but not called at all\n`);
32+
return false;
33+
}
34+
35+
const actual = this.args.pop();
36+
37+
write(`wrong arguments in ${this.func.name}`);
38+
writeObjectActual('actual:', actual);
39+
writeObjectExpected('expected:', args);
40+
41+
return false;
42+
}
43+
44+
function write(str) {
45+
process.stdout.write(chalk.red(str) + '\n');
46+
}
47+
48+
function writeObjectActual(str, object) {
49+
const json = JSON.stringify(object, null, 2);
50+
console.log(str, chalk.yellow(json) + '\n');
51+
}
52+
53+
function writeObjectExpected(str, object) {
54+
const json = JSON.stringify(object, null, 2);
55+
console.log(str, chalk.green(json) + '\n');
56+
}
57+

test/sinon.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
const sinon = require('sinon');
4+
const diff = require('./sinon-called-with-diff');
5+
6+
module.exports = diff(sinon);

0 commit comments

Comments
 (0)