Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-cursor-position

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-cursor-position - npm Package Compare versions

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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc