From 02176938c9da5e046364e916d9f58d8137d88700 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 27 Jan 2015 20:39:00 -0800 Subject: [PATCH] add screen.title property. misc. --- README.md | 3 +++ example/time.js | 6 ++++-- lib/program.js | 11 +++++++++++ lib/widget.js | 12 ++++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eca533c..8b03f7b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ var blessed = require('blessed'); // Create a screen object. var screen = blessed.screen(); +screen.title = 'my window title'; + // Create a box perfectly centered horizontally and vertically. var box = blessed.box({ top: 'center', @@ -194,6 +196,7 @@ The screen on which every other node renders. - **grabKeys** - whether the focused element grabs all keypresses. - **lockKeys** - prevent keypresses from being received by any element. - **hover** - the currently hovered element. only set if mouse events are bound. +- **title** - set or get window title. ##### Events: diff --git a/example/time.js b/example/time.js index 67bffac..0fe3dee 100755 --- a/example/time.js +++ b/example/time.js @@ -15,6 +15,7 @@ if (~argv.indexOf('-h') || ~argv.indexOf('--help')) { console.log('-s - Show seconds.'); console.log('-n - No leading zero on hours.'); console.log('-d - Show date box.'); + console.log('--skinny - Skinny text.'); return process.exit(0); } @@ -64,7 +65,8 @@ var date = blessed.box({ date.hide(); var wid = ~argv.indexOf('--skinny') ? 1 : 2; -var bch = ' '; +// var bch = ' '; +var bch = '│'; var inverse = true; // var bch = '*'; @@ -1030,7 +1032,7 @@ function updateTime() { if (~argv.indexOf('-d')) { date.show(); - date.setContent(d.toISOString()); + date.setContent(d.toISOString().replace(/\.\d+/, '')); } screen.render(); diff --git a/lib/program.js b/lib/program.js index 9f2f709..f438168 100644 --- a/lib/program.js +++ b/lib/program.js @@ -1708,6 +1708,8 @@ Program.prototype.setG = function(val) { // OSC Ps ; Pt BEL // Set Text Parameters. Program.prototype.setTitle = function(title) { + this._title = title; + if (this.term('screen')) { // Tmux pane // if (process.env.TMUX) { @@ -1715,9 +1717,18 @@ Program.prototype.setTitle = function(title) { // } return this._write('\x1bk' + title + '\x1b\\'); } + return this._write('\x1b]0;' + title + '\x07'); }; +Program.prototype.__defineGetter__('title', function() { + return this._title; +}); + +Program.prototype.__defineSetter__('title', function(title) { + return this.setTitle(title); +}); + // OSC Ps ; Pt ST // OSC Ps ; Pt BEL // Reset colors diff --git a/lib/widget.js b/lib/widget.js index c7b3ed6..41bf2e5 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -402,6 +402,14 @@ Screen.prototype.__proto__ = Node.prototype; Screen.prototype.type = 'screen'; +Screen.prototype.__defineGetter__('title', function() { + return this.program.title; +}); + +Screen.prototype.__defineSetter__('title', function(title) { + return this.program.title = title; +}); + Screen.prototype.enter = function() { if (this.program.isAlt) return; this.program.alternateBuffer(); @@ -4754,8 +4762,8 @@ Form.prototype.reset = function() { case 'dir-manager': el.refresh(el.options.cwd); return; - case 'passbox': - el.clearInput(); + case 'terminal': + el.write(''); return; } el.children.forEach(fn);