get-cursor-position
Advanced tools
Comparing version 0.0.1 to 0.0.2
74
index.js
@@ -1,33 +0,64 @@ | ||
var tty = require('tty'); | ||
var deasync = require('deasync'); | ||
var tty = require('tty'); | ||
var code = '\x1b[6n'; | ||
var data = '\x1b[6n'; | ||
module.exports = { | ||
sync : function () { | ||
var sync = true; | ||
var position = null; | ||
module.exports = function (callback) { | ||
// start listening | ||
process.stdin.resume(); | ||
raw(true); | ||
// start listening | ||
process.stdin.resume(); | ||
raw(true); | ||
process.stdin.once('data', function (b) { | ||
var match = /\[(\d+)\;(\d+)R$/.exec(b.toString()); | ||
if (match) { | ||
sync = false; | ||
position = match.slice(1, 3).reverse().map(Number); | ||
} | ||
process.stdin.once('data', function (b) { | ||
var match = /\[(\d+)\;(\d+)R$/.exec(b.toString()); | ||
if (match) { | ||
var position = match.slice(1, 3).reverse().map(Number); | ||
callback && callback({ | ||
x: position[0], | ||
y: position[1] | ||
}); | ||
// cleanup and close stdin | ||
raw(false); | ||
process.stdin.pause(); | ||
}); | ||
process.stdout.write(code); | ||
process.stdout.emit('data', code); | ||
while (sync) { | ||
deasync.sleep(1); | ||
} | ||
// cleanup and close stdin | ||
raw(false); | ||
process.stdin.pause(); | ||
return { | ||
row: position[1], | ||
col: position[0] | ||
}; | ||
}, | ||
async: function (callback, context) { | ||
}); | ||
// start listening | ||
process.stdin.resume(); | ||
raw(true); | ||
process.stdin.once('data', function (b) { | ||
var match = /\[(\d+)\;(\d+)R$/.exec(b.toString()); | ||
if (match) { | ||
var position = match.slice(1, 3).reverse().map(Number); | ||
process.stdout.write(data); | ||
process.stdout.emit('data', data); | ||
callback && callback.call(context, position[1], position[0]); | ||
} | ||
// cleanup and close stdin | ||
raw(false); | ||
process.stdin.pause(); | ||
}); | ||
process.stdout.write(code); | ||
process.stdout.emit('data', code); | ||
} | ||
}; | ||
function raw(mode) { | ||
@@ -40,2 +71,1 @@ if (process.stdin.setRawMode) { | ||
} | ||
{ | ||
"name": "get-cursor-position", | ||
"version": "0.0.1", | ||
"description": "Get cursor's absolute position in the terminal.", | ||
"version": "0.0.2", | ||
"description": "Get the cursor's current position in your terminal.", | ||
"main": "index.js", | ||
@@ -26,3 +26,6 @@ "scripts": { | ||
}, | ||
"homepage": "https://github.com/bubkoo/get-cursor-position" | ||
"homepage": "https://github.com/bubkoo/get-cursor-position", | ||
"dependencies": { | ||
"deasync": "^0.1.4" | ||
} | ||
} |
# get-cursor-position | ||
> Get cursor's absolute position in the terminal. | ||
> Get the cursor's current position in your terminal. | ||
[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/bubkoo/get-cursor-position/blob/master/LICENSE) | ||
[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/bubkoo/get-cursor-position/blob/master/LICENSE) | ||
[![NPM](https://nodei.co/npm/get-cursor-position.png)](https://nodei.co/npm/get-cursor-position/) | ||
[![NPM](https://nodei.co/npm/get-cursor-position.png)](https://nodei.co/npm/get-cursor-position/) | ||
## Install | ||
First make sure you have installed the latest version of [node.js](http://nodejs.org/) | ||
(You may need to restart your computer after this step). | ||
Install with npm: | ||
``` | ||
$ npm install restful-mock-server --save | ||
$ npm install get-cursor-position --save | ||
``` | ||
@@ -24,2 +18,4 @@ | ||
Async: | ||
```js | ||
@@ -29,5 +25,5 @@ | ||
getCursorPosition(function(pos) { | ||
console.log('x: ' + pos.x); | ||
console.log('y: ' + pos.y); | ||
getCursorPosition.async(function(row, col) { | ||
console.log('row: ' + row); | ||
console.log('col: ' + col); | ||
}); | ||
@@ -37,5 +33,15 @@ | ||
Sync: | ||
```js | ||
var getCursorPosition = require('get-cursor-position'); | ||
var pos = getCursorPosition.sync(); | ||
console.log('row: ' + pos.row); | ||
console.log('col: ' + pos.col); | ||
``` | ||
## License | ||
MIT © bubkoo | ||
[MIT](https://github.com/bubkoo/get-cursor-position/blob/master/LICENSE) © bubkoo | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4054
55
45
1
+ Addeddeasync@^0.1.4
+ Addedbindings@1.5.0(transitive)
+ Addeddeasync@0.1.30(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addednode-addon-api@1.7.2(transitive)