mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-10 19:16:20 +00:00
decode mouse events and responses properly.
This commit is contained in:
parent
d42adf7e32
commit
070cbd9001
@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
, StringDecoder = require('string_decoder').StringDecoder
|
||||
, util = require('util')
|
||||
, Tput = require('./tput')
|
||||
, colors = require('./colors')
|
||||
@ -105,9 +106,7 @@ Program.prototype._log = function(pre, msg) {
|
||||
Program.prototype.setupDump = function() {
|
||||
var self = this
|
||||
, write = this.output.write
|
||||
, decoder;
|
||||
|
||||
decoder = new (require('string_decoder')).StringDecoder('utf8');
|
||||
, decoder = new StringDecoder('utf8');
|
||||
|
||||
function stringify(data) {
|
||||
return caret(data
|
||||
@ -349,8 +348,17 @@ Program.prototype.removeKey = function(key, listener) {
|
||||
// left click: ^[[M 3<^[[M#3<
|
||||
// mousewheel up: ^[[M`3>
|
||||
Program.prototype.bindMouse = function() {
|
||||
this.on('data', this._bindMouse.bind(this));
|
||||
this.bindMouse = function() {};
|
||||
if (this._boundMouse) return;
|
||||
this._boundMouse = true;
|
||||
|
||||
var decoder = new StringDecoder('utf8')
|
||||
, self = this;
|
||||
|
||||
this.on('data', function(data) {
|
||||
data = decoder.write(data);
|
||||
if (!data) return;
|
||||
self._bindMouse(data);
|
||||
});
|
||||
};
|
||||
|
||||
Program.prototype._bindMouse = function(s) {
|
||||
@ -611,8 +619,17 @@ Program.prototype._bindMouse = function(s) {
|
||||
|
||||
// All possible responses from the terminal
|
||||
Program.prototype.bindResponse = function() {
|
||||
this.on('data', this._bindResponse.bind(this));
|
||||
this.bindResponse = function() {};
|
||||
if (this._boundResponse) return;
|
||||
this._boundResponse = true;
|
||||
|
||||
var decoder = new StringDecoder('utf8')
|
||||
, self = this;
|
||||
|
||||
this.on('data', function(data) {
|
||||
data = decoder.write(data);
|
||||
if (!data) return;
|
||||
self._bindResponse(data);
|
||||
});
|
||||
};
|
||||
|
||||
Program.prototype._bindResponse = function(s) {
|
||||
|
@ -30,6 +30,7 @@ program.key(['q', 'escape', 'C-c'], function() {
|
||||
});
|
||||
|
||||
program.on('keypress', function(ch, data) {
|
||||
if (data.name === 'mouse') return;
|
||||
program.clear();
|
||||
program.cup(0, 0);
|
||||
console.log(data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user