Skip to content
Open
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
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Logs
logs
*.log
npm-debug.log*
tmp/squirrel-*.json
.DS_Store

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# private docker files
/docker/cloud/
ansible*.retry
staging.yml
production.yml

#ETCD certs
config/ETCD_CA*

#ETCD certs
app/config/ETCD_CA*

# Flow definitions
flow-typed/

# Build target
dist

#keep tmp folder for squirrel
!tmp/.keepit

.idea
package-lock.json

# VSCode
.vscode
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- '6'
- '8'
- '10'
- '11'
script:
# - npm run lint
- npm run cover
after_script:
- npm run publish-coverage
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Term Mouse

[![npm](https://img.shields.io/npm/v/term-mouse.svg)](https://www.npmjs.com/package/term-mouse)
[![Build Status](https://travis-ci.com/CoderPuppy/term-mouse.svg?branch=master)](https://travis-ci.com/CoderPuppy/term-mouse)
[![codecov](https://codecov.io/gh/CoderPuppy/term-mouse/branch/master/graph/badge.svg)](https://codecov.io/gh/CoderPuppy/term-mouse)

### A mouse reporting interface

Originally based on [TooTallNate's gist](https://gist.github.com/1702813), rewritten to use all the mouse reporting modes.
Expand Down
2 changes: 1 addition & 1 deletion test.js → example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var mouse = require('./')();
var mouse = require('.')();

mouse.start();
mouse.on('click', function(key) {
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,5 @@ var Mouse = module.exports = (function() {
return this;
}).call(Mouse);
})();

module.exports.decodeBtn = decodeBtn;
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
"version": "0.2.0",
"author": "CoderPuppy <[email protected]>",
"main": "./index",
"scripts": {
"test": "ava",
"cover": "nyc npm test",
"publish-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
},
"repository": {
"type": "git",
"url" : "git://github.com/CoderPuppy/term-mouse.git"
}
"url": "git://github.com/CoderPuppy/term-mouse.git"
},
"devDependencies": {
"ava": "^0.25.0",
"codecov": "^3.1.0",
"highland": "^2.13.0",
"nyc": "^13.1.0"
},
"dependencies": {}
}
30 changes: 30 additions & 0 deletions test/decode-button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const test = require('ava');
const {decodeBtn} = require('../index');


test('decodeBtn left', t => {
t.deepEqual(decodeBtn(0), {
btnNum: 1,
button: 'left',
control: false,
down: true,
meta: false,
name: 'buttons',
shift: false

})
});

test('decodeBtn middle', t => {
t.deepEqual(decodeBtn(1), {
btnNum: 2,
button: 'middle',
control: false,
down: true,
meta: false,
name: 'buttons',
shift: false
})
});

// maybe do more to capture logic of tests
55 changes: 55 additions & 0 deletions test/mouse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const test = require('ava');
const Mouse = require('../index');
const stream = require('stream');
const highland = require('highland');

test('I can create a mouse with custom input and output', t => {
const input = new stream.Readable();
const output = new stream.Writable({
write(chunk, encoding, callback) {
callback();
}
})
const mouse = new Mouse({ input, output });
t.is(mouse.input, input);
t.is(mouse.output, output);
});


test.cb('I can simulate a click', t => {
const down = new Buffer('\u001b[32;60;8M');
const up = new Buffer('\u001b[35;60;8M');
const input = highland([down, up]);
input.setRawMode = () => {}
const output = new stream.Writable({
write(chunk, encoding, callback) {
callback();
}
})
const mouse = new Mouse({ input, output });
mouse.on('click', function(key) {
try{
t.is(key.button, 'left')
t.is(key.down, true)
t.is(key.name, 'buttons')
t.is(key.x, 28);
t.is(key.y, -24)
} catch(err){
t.end(err);
}
t.end();
}).on('up', function(d) {
try{
t.deepEqual(d.buf, up)
} catch(err){
t.end(err);
}
}).on('down', function(d) {
try{
t.deepEqual(d.buf, down)
} catch(err){
t.end(err);
}
})
mouse.start();
});