misc. options. refactor tests/bin.

This commit is contained in:
Christopher Jeffrey 2013-07-18 17:56:05 -05:00
parent f03f51267b
commit b8e0fafaeb
18 changed files with 122 additions and 80 deletions

View File

@ -887,8 +887,8 @@ This will actually parse the xterm terminfo and compile every
string capability to a javascript function: string capability to a javascript function:
``` js ``` js
var Tput = require('blessed').Tput var blessed = require('blessed')
, tput = Tput('xterm'); , tput = blessed.tput('xterm-256color');
console.log(tput.setaf(4) + 'hello' + tput.sgr0()); console.log(tput.setaf(4) + 'hello' + tput.sgr0());
``` ```
@ -905,7 +905,7 @@ The main functionality is exposed in the main `blessed` module:
``` js ``` js
var blessed = require('blessed') var blessed = require('blessed')
, program = blessed(); , program = blessed.program();
program.key('q', function(ch, key) { program.key('q', function(ch, key) {
program.clear(); program.clear();

View File

@ -1,6 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
var tput = require('../lib/tput')(process.env.TERM || 'xterm') var blessed = require('../')
, tput = blessed.tput()
, argv = process.argv.slice(2) , argv = process.argv.slice(2)
, cmd = argv.shift(); , cmd = argv.shift();

View File

@ -5,7 +5,7 @@
*/ */
var blessed = require('blessed') var blessed = require('blessed')
, program = blessed(); , program = blessed.program();
process.title = 'blessed'; process.title = 'blessed';

View File

@ -24,7 +24,6 @@ if (/^(-h|--help|-\?)$/.test(process.argv[2])) {
} }
var blessed = require('blessed') var blessed = require('blessed')
, program = blessed()
, nssocket; , nssocket;
try { try {
@ -40,18 +39,16 @@ var server
* Screen Layout * Screen Layout
*/ */
var screen = new blessed.Screen({ var screen = blessed.screen();
program: program
});
var table = new blessed.Box({ var table = blessed.box({
left: 0, left: 0,
top: 0, top: 0,
width: screen.width, width: screen.width,
height: screen.height height: screen.height
}); });
var ball = new blessed.Box({ var ball = blessed.box({
width: 1, width: 1,
height: 1, height: 1,
bg: 'white', bg: 'white',
@ -59,7 +56,7 @@ var ball = new blessed.Box({
left: 0 left: 0
}); });
var lpaddle = new blessed.Box({ var lpaddle = blessed.box({
width: 1, width: 1,
height: 3, height: 3,
bg: 'yellow', bg: 'yellow',
@ -67,7 +64,7 @@ var lpaddle = new blessed.Box({
left: 0 left: 0
}); });
var rpaddle = new blessed.Box({ var rpaddle = blessed.box({
width: 1, width: 1,
height: 3, height: 3,
bg: 'yellow', bg: 'yellow',
@ -75,24 +72,25 @@ var rpaddle = new blessed.Box({
right: 0 right: 0
}); });
var score = new blessed.Box({ var score = blessed.box({
top: 0, top: 0,
left: 4, left: 4,
height: 3, height: 3,
//width: 26, width: 'shrink',
border: { border: {
type: 'ascii' type: 'line'
}, },
shrink: true,
//align: 'center', //align: 'center',
bold: true, style: {
bold: true
},
tags: true tags: true
}); });
score.lwins = 0; score.lwins = 0;
score.rwins = 0; score.rwins = 0;
var net = new blessed.Box({ var net = blessed.box({
width: 1, width: 1,
height: '100%', height: '100%',
bg: 'yellow', bg: 'yellow',
@ -100,17 +98,17 @@ var net = new blessed.Box({
left: 'center' left: 'center'
}); });
var message = new blessed.Box({ var message = blessed.box({
width: '50%', width: '50%',
height: 3, height: 3,
border: { border: {
type: 'ascii' type: 'line'
}, },
top: 'center', top: 'center',
left: 'center' left: 'center'
}); });
var text = new blessed.Box({ var text = blessed.box({
top: 'center', top: 'center',
left: 1, left: 1,
right: 1, right: 1,

View File

@ -18,12 +18,12 @@ var EventEmitter = require('events').EventEmitter
*/ */
function Program(options) { function Program(options) {
var self = this;
if (!(this instanceof Program)) { if (!(this instanceof Program)) {
return new Program(options); return new Program(options);
} }
var self = this;
EventEmitter.call(this); EventEmitter.call(this);
if (!options || options.__proto__ !== Object.prototype) { if (!options || options.__proto__ !== Object.prototype) {
@ -3319,8 +3319,8 @@ Program.prototype.sigtstp = function(callback) {
*/ */
exports = Program; exports = Program;
exports.Program = Program; exports.Program = exports.program = Program;
exports.Tput = Tput; exports.Tput = exports.tput = Tput;
exports.widget = require('./widget'); exports.widget = require('./widget');
Object.keys(exports.widget).forEach(function(name) { Object.keys(exports.widget).forEach(function(name) {

View File

@ -34,6 +34,7 @@ function Tput(options) {
return new Tput(options); return new Tput(options);
} }
options = options || {};
if (typeof options === 'string') { if (typeof options === 'string') {
options = { term: options }; options = { term: options };
} }
@ -72,6 +73,10 @@ function Tput(options) {
this.detectFeatures(); this.detectFeatures();
} }
Tput.prototype.term = function(is) {
return this.terminal.indexOf(is) === 0;
};
/** /**
* Fallback * Fallback
*/ */

View File

@ -25,7 +25,8 @@ function Node(options) {
EventEmitter.call(this); EventEmitter.call(this);
this.options = options || {}; options = options || {};
this.options = options;
this.screen = this.screen this.screen = this.screen
|| Screen.global || Screen.global
|| (function(){throw new Error('No active screen.')})(); || (function(){throw new Error('No active screen.')})();
@ -146,7 +147,7 @@ Node.prototype.remove = function(element) {
}; };
Node.prototype.detach = function() { Node.prototype.detach = function() {
return this.parent.remove(this); if (this.parent) this.parent.remove(this);
}; };
Node.prototype.emitDescendants = function() { Node.prototype.emitDescendants = function() {
@ -237,11 +238,11 @@ function Screen(options) {
return new Screen(options); return new Screen(options);
} }
if (options && options.rsety && options.listen) { options = options || {};
if (options.rsety && options.listen) {
options = { program: options }; options = { program: options };
} }
options = options || {};
options.program = options.program options.program = options.program
|| require('./program').global || require('./program').global
|| new (require('./program'))(options); || new (require('./program'))(options);
@ -1365,6 +1366,8 @@ function Element(options) {
return new Element(options); return new Element(options);
} }
options = options || {};
Node.call(this, options); Node.call(this, options);
this.name = options.name; this.name = options.name;
@ -2112,6 +2115,7 @@ function Box(options) {
if (!(this instanceof Box)) { if (!(this instanceof Box)) {
return new Box(options); return new Box(options);
} }
options = options || {};
Element.call(this, options); Element.call(this, options);
} }
@ -2668,6 +2672,7 @@ function Text(options) {
if (!(this instanceof Text)) { if (!(this instanceof Text)) {
return new Text(options); return new Text(options);
} }
options = options || {};
options.shrink = true; options.shrink = true;
Box.call(this, options); Box.call(this, options);
} }
@ -2685,6 +2690,8 @@ function Line(options) {
return new Line(options); return new Line(options);
} }
options = options || {};
var orientation = options.orientation || 'vertical'; var orientation = options.orientation || 'vertical';
delete options.orientation; delete options.orientation;
@ -2733,6 +2740,8 @@ function ScrollableBox(options) {
return new ScrollableBox(options); return new ScrollableBox(options);
} }
options = options || {};
Box.call(this, options); Box.call(this, options);
this.scrollable = true; this.scrollable = true;
@ -2834,6 +2843,8 @@ function List(options) {
return new List(options); return new List(options);
} }
options = options || {};
ScrollableBox.call(this, options); ScrollableBox.call(this, options);
this.value = ''; this.value = '';
@ -3134,6 +3145,8 @@ function ScrollableText(options) {
return new ScrollableText(options); return new ScrollableText(options);
} }
options = options || {};
options.alwaysScroll = true; options.alwaysScroll = true;
ScrollableBox.call(this, options); ScrollableBox.call(this, options);
@ -3277,6 +3290,8 @@ function Form(options) {
return new Form(options); return new Form(options);
} }
options = options || {};
Box.call(this, options); Box.call(this, options);
if (options.keys) { if (options.keys) {
@ -3475,6 +3490,7 @@ function Input(options) {
if (!(this instanceof Input)) { if (!(this instanceof Input)) {
return new Input(options); return new Input(options);
} }
options = options || {};
Box.call(this, options); Box.call(this, options);
} }
@ -3493,6 +3509,8 @@ function Textbox(options) {
return new Textbox(options); return new Textbox(options);
} }
options = options || {};
Input.call(this, options); Input.call(this, options);
this.screen._listenKeys(this); this.screen._listenKeys(this);
@ -3590,6 +3608,11 @@ Textbox.prototype._listener = function(ch, key) {
// Tabs only work with textareas. // Tabs only work with textareas.
if (ch === '\t') ch = ' '; if (ch === '\t') ch = ' ';
this.value += ch; this.value += ch;
if (this.content.indexOf('defined') !== -1) {
this.program.normalBuffer();
console.log(this.value);
process.exit(0);
}
if (this.secret) return; if (this.secret) return;
if (this.value.length < width) { if (this.value.length < width) {
this.screen.program.cuf(); this.screen.program.cuf();
@ -3659,6 +3682,8 @@ function Textarea(options) {
return new Textarea(options); return new Textarea(options);
} }
options = options || {};
ScrollableText.call(this, options); ScrollableText.call(this, options);
this.screen._listenKeys(this); this.screen._listenKeys(this);
@ -3851,6 +3876,8 @@ function Button(options) {
return new Button(options); return new Button(options);
} }
options = options || {};
if (options.autoFocus == null) { if (options.autoFocus == null) {
options.autoFocus = false; options.autoFocus = false;
} }
@ -3887,6 +3914,9 @@ function ProgressBar(options) {
if (!(this instanceof ProgressBar)) { if (!(this instanceof ProgressBar)) {
return new ProgressBar(options); return new ProgressBar(options);
} }
options = options || {};
Input.call(this, options); Input.call(this, options);
this.filled = options.filled || 0; this.filled = options.filled || 0;
@ -4004,12 +4034,13 @@ ProgressBar.prototype.reset = function() {
*/ */
function FileManager(options) { function FileManager(options) {
var self = this;
if (!(this instanceof FileManager)) { if (!(this instanceof FileManager)) {
return new FileManager(options); return new FileManager(options);
} }
var self = this; options = options || {};
options.parseTags = true; options.parseTags = true;
List.call(this, options); List.call(this, options);
@ -4188,6 +4219,8 @@ function Checkbox(options) {
return new Checkbox(options); return new Checkbox(options);
} }
options = options || {};
Input.call(this, options); Input.call(this, options);
this.text = options.content || options.text || ''; this.text = options.content || options.text || '';
@ -4257,12 +4290,12 @@ Checkbox.prototype.toggle = function() {
*/ */
function RadioSet(options) { function RadioSet(options) {
var self = this;
if (!(this instanceof RadioSet)) { if (!(this instanceof RadioSet)) {
return new RadioSet(options); return new RadioSet(options);
} }
options = options || {};
// Possibly inherit parent's style.
// options.style = this.parent.style;
Box.call(this, options); Box.call(this, options);
} }
@ -4282,6 +4315,8 @@ function RadioButton(options) {
return new RadioButton(options); return new RadioButton(options);
} }
options = options || {};
Checkbox.call(this, options); Checkbox.call(this, options);
this.on('check', function() { this.on('check', function() {
@ -4310,6 +4345,8 @@ function Prompt(options) {
return new Prompt(options); return new Prompt(options);
} }
options = options || {};
Box.call(this, options); Box.call(this, options);
this._.input = new Textbox({ this._.input = new Textbox({
@ -4401,6 +4438,8 @@ function Question(options) {
return new Question(options); return new Question(options);
} }
options = options || {};
Box.call(this, options); Box.call(this, options);
this._.okay = new Button({ this._.okay = new Button({
@ -4490,6 +4529,7 @@ function Message(options) {
return new Message(options); return new Message(options);
} }
options = options || {};
options.tags = true; options.tags = true;
Box.call(this, options); Box.call(this, options);
@ -4532,6 +4572,8 @@ function Info(options) {
return new Info(options); return new Info(options);
} }
options = options || {};
Box.call(this, options); Box.call(this, options);
} }
@ -4580,6 +4622,8 @@ function Loading(options) {
return new Loading(options); return new Loading(options);
} }
options = options || {};
Box.call(this, options); Box.call(this, options);
this._.icon = new Text({ this._.icon = new Text({
@ -4644,6 +4688,8 @@ function PickList(options) {
return new PickList(options); return new PickList(options);
} }
options = options || {};
List.call(this, options); List.call(this, options);
} }
@ -4676,6 +4722,8 @@ function Listbar(options) {
return new Listbar(options); return new Listbar(options);
} }
options = options || {};
this.items = []; this.items = [];
this.commands = options.commands; this.commands = options.commands;
this.leftBase = 0; this.leftBase = 0;
@ -4847,6 +4895,8 @@ function DirManager(options) {
return new DirManager(options); return new DirManager(options);
} }
options = options || {};
FileManager.call(this, options); FileManager.call(this, options);
this.on('cd', function(dir) { this.on('cd', function(dir) {
@ -4870,6 +4920,7 @@ function Passbox(options) {
return new Passbox(options); return new Passbox(options);
} }
options = options || {};
options.censor = true; options.censor = true;
Textbox.call(this, options); Textbox.call(this, options);

View File

@ -1,11 +1,7 @@
var blessed = require('blessed') var blessed = require('../')
, program = blessed(); , screen = blessed.screen();
var screen = new blessed.Screen({ var main = blessed.box({
program: program
});
var main = new blessed.Box({
width: screen.width, width: screen.width,
height: screen.height, height: screen.height,
bg: 'yellow', bg: 'yellow',

View File

@ -24,7 +24,7 @@
// $ node test/tput.js xterm-256color --ifile ~/.terminfo/x/xterm-256color | tee out // $ node test/tput.js xterm-256color --ifile ~/.terminfo/x/xterm-256color | tee out
// $ cdiff test/terminfo out // $ cdiff test/terminfo out
var Tput = require('../').Tput; var blessed = require('../');
// Simple argument parser // Simple argument parser
// Copyright (c) 2012, Christopher Jeffrey (MIT License) // Copyright (c) 2012, Christopher Jeffrey (MIT License)
@ -80,7 +80,7 @@ function parseArg() {
var argv = parseArg(); var argv = parseArg();
var tput = Tput({ var tput = blessed.tput({
term: argv[0] || 'xterm', term: argv[0] || 'xterm',
extended: true, extended: true,
debug: true, debug: true,
@ -95,7 +95,7 @@ console.log('Max colors: %d.', tput.colors);
// console.log(tput.strings.acs_chars.split('').map(function(ch) { return ch.charCodeAt(0); })); // console.log(tput.strings.acs_chars.split('').map(function(ch) { return ch.charCodeAt(0); }));
// console.log(JSON.stringify(tput.strings.acs_chars)); // console.log(JSON.stringify(tput.strings.acs_chars));
// process.stdout.write(Tput.sprintf('%-10s\n', 'hello')); // process.stdout.write(blessed.tput.sprintf('%-10s\n', 'hello'));
// tput._compile('%?%p9%t\u001b(0%e\u001b(B%;\u001b[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m'); // tput._compile('%?%p9%t\u001b(0%e\u001b(B%;\u001b[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m');

View File

@ -1,4 +1,4 @@
var blessed = require('blessed') var blessed = require('../')
, screen; , screen;
screen = blessed.screen({ screen = blessed.screen({

View File

@ -1,4 +1,4 @@
var blessed = require('blessed'); var blessed = require('../');
var screen = blessed.screen({ var screen = blessed.screen({
tput: true tput: true

View File

@ -1,4 +1,4 @@
var blessed = require('blessed') var blessed = require('../')
, screen = blessed.screen(); , screen = blessed.screen();
var form = blessed.form({ var form = blessed.form({

View File

@ -1,4 +1,4 @@
var blessed = require('blessed'); var blessed = require('../');
var screen = blessed.screen({ var screen = blessed.screen({
tput: true tput: true

View File

@ -1,5 +1,5 @@
var blessed = require('blessed') var blessed = require('../')
, screen; screen = blessed.screen(); , screen = blessed.screen();
var bar = blessed.listbar({ var bar = blessed.listbar({
parent: screen, parent: screen,

View File

@ -1,16 +1,12 @@
var blessed = require('blessed') var blessed = require('../')
, program = blessed() , screen = blessed.screen()
, assert = require('assert'); , assert = require('assert');
// My terminal size at the time of writing these tests: // My terminal size at the time of writing these tests:
program.cols = 154; screen.program.cols = 154;
program.rows = 19; screen.program.rows = 19;
var screen = new blessed.Screen({ var main = blessed.box({
program: program
});
var main = new blessed.Box({
//width: '75%', //width: '75%',
//height: '75%', //height: '75%',
width: 115, width: 115,
@ -23,7 +19,7 @@ var main = new blessed.Box({
screen.append(main); screen.append(main);
var inner = new blessed.Box({ var inner = blessed.box({
width: '50%', width: '50%',
height: '50%', height: '50%',
//width: 57, //width: 57,

View File

@ -1,4 +1,4 @@
var blessed = require('blessed') var blessed = require('../')
, screen = blessed.screen(); , screen = blessed.screen();
var outer = blessed.box({ var outer = blessed.box({

View File

@ -1,8 +1,6 @@
var blessed = require('blessed'); var blessed = require('../');
var screen = blessed.screen({ var screen = blessed.screen();
tput: true
});
var box = blessed.textarea({ var box = blessed.textarea({
parent: screen, parent: screen,

View File

@ -1,10 +1,7 @@
var blessed = require('blessed'); var blessed = require('../')
, screen = blessed.screen();
var screen = new blessed.Screen({ screen.append(blessed.text({
tput: true
});
screen.append(new blessed.Text({
top: 0, top: 0,
left: 2, left: 2,
width: '100%', width: '100%',
@ -16,7 +13,7 @@ screen.append(new blessed.Text({
align: 'center' align: 'center'
})); }));
screen.append(new blessed.Line({ screen.append(blessed.line({
orientation: 'horizontal', orientation: 'horizontal',
top: 1, top: 1,
left: 0, left: 0,
@ -24,7 +21,7 @@ screen.append(new blessed.Line({
})); }));
/* /*
screen.append(new blessed.Box({ screen.append(blessed.box({
fg: 4, fg: 4,
bg: -1, bg: -1,
border: { border: {
@ -39,7 +36,7 @@ screen.append(new blessed.Box({
left: 'center' left: 'center'
})); }));
screen.children[0].append(new blessed.Box({ screen.children[0].append(blessed.box({
fg: 4, fg: 4,
bg: 3, bg: 3,
border: { border: {
@ -56,7 +53,7 @@ screen.children[0].append(new blessed.Box({
})); }));
*/ */
var list = new blessed.List({ var list = blessed.list({
align: 'center', align: 'center',
mouse: true, mouse: true,
fg: 'blue', fg: 'blue',
@ -88,7 +85,7 @@ var list = new blessed.List({
screen.append(list); screen.append(list);
list.select(0); list.select(0);
list.prepend(new blessed.Text({ list.prepend(blessed.text({
left: 2, left: 2,
content: ' My list ' content: ' My list '
})); }));
@ -105,7 +102,7 @@ list.on('keypress', function(ch, key) {
} }
}); });
var progress = new blessed.ProgressBar({ var progress = blessed.progressbar({
fg: 'blue', fg: 'blue',
bg: 'default', bg: 'default',
barBg: 'default', barBg: 'default',
@ -134,7 +131,7 @@ var lorem = require('fs').readFileSync(__dirname + '/git.diff', 'utf8');
//lorem = lorem.replace(/\x1b[^m]*m/g, ''); //lorem = lorem.replace(/\x1b[^m]*m/g, '');
var stext = new blessed.ScrollableText({ var stext = blessed.scrollabletext({
//padding: 1, //padding: 1,
mouse: true, mouse: true,
content: lorem, content: lorem,
@ -184,7 +181,7 @@ screen.on('element mouseout', function(el) {
}); });
*/ */
var input = new blessed.Textbox({ var input = blessed.textbox({
mouse: true, mouse: true,
label: ' My Input ', label: ' My Input ',
content: '', content: '',