Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cursorPosition.js « examples « ansi « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 50f964490ea1eae1eded733082bcd1a106c39bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node

var tty = require('tty')
var cursor = require('../')(process.stdout)

// listen for the queryPosition report on stdin
process.stdin.resume()
raw(true)

process.stdin.once('data', function (b) {
  var match = /\[(\d+)\;(\d+)R$/.exec(b.toString())
  if (match) {
    var xy = match.slice(1, 3).reverse().map(Number)
    console.error(xy)
  }

  // cleanup and close stdin
  raw(false)
  process.stdin.pause()
})


// send the query position request code to stdout
cursor.queryPosition()

function raw (mode) {
  if (process.stdin.setRawMode) {
    process.stdin.setRawMode(mode)
  } else {
    tty.setRawMode(mode)
  }
}