minor bug fixes. handle tmux escaping.

This commit is contained in:
Christopher Jeffrey 2015-03-14 16:14:39 -07:00
parent 0e2b626556
commit 3dcc0b3d1b
5 changed files with 65 additions and 29 deletions

View File

@ -100,14 +100,20 @@ function GpmClient(options) {
var pid = process.pid; var pid = process.pid;
// check tty for /dev/tty[n] // check tty for /dev/tty[n]
var tty = /tty[0-9]+$/.exec(fs.readlinkSync('/proc/' + pid + '/fd/0')); var path;
try {
path = fs.readlinkSync('/proc/' + pid + '/fd/0');
} catch (e) {
;
}
var tty = /tty[0-9]+$/.exec(path);
if (tty === null) { if (tty === null) {
// TODO: should also check for /dev/input/.. // TODO: should also check for /dev/input/..
} }
var vc; var vc;
if (tty) { if (tty) {
var tty = tty[0]; tty = tty[0];
vc = +/[0-9]+$/.exec(tty)[0]; vc = +/[0-9]+$/.exec(tty)[0];
} }
@ -176,8 +182,8 @@ function GpmClient(options) {
break; break;
} }
}); });
gpm.on('error', function(err) { gpm.on('error', function(err) {
// console.log('GPM ERROR', err);
self.stop(); self.stop();
}); });
}); });

View File

@ -469,11 +469,11 @@ Program.prototype._bindMouse = function(s, buf) {
key.x = x - 32; key.x = x - 32;
key.y = y - 32; key.y = y - 32;
if (key.x === -32) key.x = 255;
if (key.y === -32) key.y = 255;
if (this.zero) key.x--, key.y--; if (this.zero) key.x--, key.y--;
if (x === 0) key.x = 255;
if (y === 0) key.y = 255;
mod = b >> 2; mod = b >> 2;
key.shift = !!(mod & 1); key.shift = !!(mod & 1);
key.meta = !!((mod >> 1) & 1); key.meta = !!((mod >> 1) & 1);
@ -570,6 +570,8 @@ Program.prototype._bindMouse = function(s, buf) {
: button === 1 ? 'middle' : button === 1 ? 'middle'
: button === 2 ? 'right' : button === 2 ? 'right'
: 'unknown'; : 'unknown';
// NOTE: 0/32 = mousemove, 32/64 = mousemove with left down
// if ((b >> 1) === 32)
this._lastButton = key.button; this._lastButton = key.button;
} }
@ -1412,7 +1414,7 @@ Program.prototype.response = function(name, text, callback) {
return callback(new Error('Timeout.')); return callback(new Error('Timeout.'));
}, 2000); }, 2000);
return this._write(text); return this._twrite(text);
}; };
Program.prototype._buffer = function(text) { Program.prototype._buffer = function(text) {
@ -1446,6 +1448,15 @@ Program.prototype._write = function(text) {
return this.output.write(text); return this.output.write(text);
}; };
// Example: `DCS tmux; ESC Pt ST`
// Real: `DCS tmux; ESC Pt ESC \`
Program.prototype._twrite = function(data) {
if (process.env.TMUX) data = '\x1bPtmux;\x1b' + data + '\x1b\\';
// Should work but tmux doesn't implement ST correctly:
// if (process.env.TMUX) data = '\x1bPtmux;\x1b' + data + '\x07';
return this._write(data);
};
Program.prototype.echo = Program.prototype.echo =
Program.prototype.write = function(text, attr) { Program.prototype.write = function(text, attr) {
return attr return attr
@ -1870,10 +1881,10 @@ Program.prototype.setTitle = function(title) {
// if (process.env.TMUX) { // if (process.env.TMUX) {
// return this._write('\x1b]2;' + title + '\x1b\\'); // return this._write('\x1b]2;' + title + '\x1b\\');
// } // }
return this._write('\x1bk' + title + '\x1b\\'); return this._twrite('\x1bk' + title + '\x1b\\');
} }
return this._write('\x1b]0;' + title + '\x07'); return this._twrite('\x1b]0;' + title + '\x07');
}; };
// OSC Ps ; Pt ST // OSC Ps ; Pt ST
@ -1883,8 +1894,8 @@ Program.prototype.resetColors = function(param) {
if (this.has('Cr')) { if (this.has('Cr')) {
return this.put.Cr(param); return this.put.Cr(param);
} }
return this._write('\x1b]112\x07'); return this._twrite('\x1b]112\x07');
//return this._write('\x1b]112;' + param + '\x07'); //return this._twrite('\x1b]112;' + param + '\x07');
}; };
// OSC Ps ; Pt ST // OSC Ps ; Pt ST
@ -1894,7 +1905,7 @@ Program.prototype.dynamicColors = function(param) {
if (this.has('Cs')) { if (this.has('Cs')) {
return this.put.Cs(param); return this.put.Cs(param);
} }
return this._write('\x1b]12;' + param + '\x07'); return this._twrite('\x1b]12;' + param + '\x07');
}; };
// OSC Ps ; Pt ST // OSC Ps ; Pt ST
@ -1904,7 +1915,7 @@ Program.prototype.selData = function(a, b) {
if (this.has('Ms')) { if (this.has('Ms')) {
return this.put.Ms(a, b); return this.put.Ms(a, b);
} }
return this._write('\x1b]52;' + a + ';' + b + '\x07'); return this._twrite('\x1b]52;' + a + ';' + b + '\x07');
}; };
/** /**

View File

@ -732,7 +732,7 @@ Tput.prototype._compile = function(info, key, str) {
try { try {
str = fs.readFileSync(str, 'utf8'); str = fs.readFileSync(str, 'utf8');
if (this.debug) { if (this.debug) {
v = ('return "' + str + '";') v = ('return ' + JSON.stringify(str) + ';')
.replace(/\x1b/g, '\\x1b') .replace(/\x1b/g, '\\x1b')
.replace(/\r/g, '\\r') .replace(/\r/g, '\\r')
.replace(/\n/g, '\\n'); .replace(/\n/g, '\\n');
@ -2058,7 +2058,8 @@ Tput.prototype.detectBrokenACS = function(info) {
} }
// screen termcap is bugged? // screen termcap is bugged?
if (info.name.indexOf('screen') == 0 if (this.termcap
&& info.name.indexOf('screen') == 0
&& process.env.TERMCAP && process.env.TERMCAP
&& ~process.env.TERMCAP.indexOf('screen') && ~process.env.TERMCAP.indexOf('screen')
&& ~process.env.TERMCAP.indexOf('hhII00')) { && ~process.env.TERMCAP.indexOf('hhII00')) {
@ -2180,7 +2181,7 @@ function sprintf(src) {
var flags = (flag || '').split('') var flags = (flag || '').split('')
, param = params[i] != null ? params[i] : '' , param = params[i] != null ? params[i] : ''
, initial = param , initial = param
, width = +width // , width = +width
, opt = {} , opt = {}
, pre = ''; , pre = '';
@ -2231,6 +2232,17 @@ function sprintf(src) {
} }
}); });
width = +width.split('.')[0];
// Should this be for opt.left too?
// Example: %2.2X - turns 0 into 00
if (width && !opt.left) {
param = param + '';
while (param.length < width) {
param = '0' + param;
}
}
if (opt.signs) { if (opt.signs) {
if (+initial >= 0) { if (+initial >= 0) {
pre += '+'; pre += '+';

View File

@ -4649,6 +4649,7 @@ List.prototype.select = function(index) {
this.selected = index; this.selected = index;
this.value = this.ritems[this.selected]; this.value = this.ritems[this.selected];
if (!this.parent) return;
this.scrollTo(this.selected); this.scrollTo(this.selected);
}; };
@ -4951,6 +4952,9 @@ Form.prototype.reset = function() {
case 'terminal': case 'terminal':
el.write(''); el.write('');
return; return;
case 'image':
//el.clearImage();
return;
} }
el.children.forEach(fn); el.children.forEach(fn);
}); });
@ -6732,25 +6736,20 @@ Terminal.prototype.bootstrap = function() {
, s; , s;
if (self.term.urxvtMouse) { if (self.term.urxvtMouse) {
s = '\x1b[' if (self.screen.program.sgrMouse) {
+ String.fromCharCode(b) b += 32;
+ ';' }
+ String.fromCharCode(x) s = '\x1b[' + b + ';' + (x + 32) + ';' + (y + 32) + 'M';
+ ';'
+ String.fromCharCode(y);
+ 'M';
} else if (self.term.sgrMouse) { } else if (self.term.sgrMouse) {
if (!self.screen.program.sgrMouse) { if (!self.screen.program.sgrMouse) {
b -= 32; b -= 32;
} }
s = '\x1b[<' s = '\x1b[<' + b + ';' + x + ';' + y
+ String.fromCharCode(b)
+ ';'
+ String.fromCharCode(x)
+ ';'
+ String.fromCharCode(y)
+ (data.action === 'mousedown' ? 'M' : 'm'); + (data.action === 'mousedown' ? 'M' : 'm');
} else { } else {
if (self.screen.program.sgrMouse) {
b += 32;
}
s = '\x1b[M' s = '\x1b[M'
+ String.fromCharCode(b) + String.fromCharCode(b)
+ String.fromCharCode(x + 32) + String.fromCharCode(x + 32)
@ -6807,6 +6806,10 @@ Terminal.prototype.bootstrap = function() {
self.screen.render(); self.screen.render();
}); });
this.pty.on('exit', function(code) {
self.emit('exit', code || null);
});
this.screen.on('keypress', function() { this.screen.on('keypress', function() {
self.screen.render(); self.screen.render();
}); });

View File

@ -42,3 +42,7 @@ program.on('keypress', function(ch, data) {
// program.getCursor(function(err, data) { // program.getCursor(function(err, data) {
// program.write(util.inspect(data)); // program.write(util.inspect(data));
// }); // });
// program.manipulateWindow(18, function(err, data) {
// program.write(util.inspect(data));
// });