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:
``` js
var Tput = require('blessed').Tput
, tput = Tput('xterm');
var blessed = require('blessed')
, tput = blessed.tput('xterm-256color');
console.log(tput.setaf(4) + 'hello' + tput.sgr0());
```
@ -905,7 +905,7 @@ The main functionality is exposed in the main `blessed` module:
``` js
var blessed = require('blessed')
, program = blessed();
, program = blessed.program();
program.key('q', function(ch, key) {
program.clear();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@
// $ node test/tput.js xterm-256color --ifile ~/.terminfo/x/xterm-256color | tee out
// $ cdiff test/terminfo out
var Tput = require('../').Tput;
var blessed = require('../');
// Simple argument parser
// Copyright (c) 2012, Christopher Jeffrey (MIT License)
@ -80,7 +80,7 @@ function parseArg() {
var argv = parseArg();
var tput = Tput({
var tput = blessed.tput({
term: argv[0] || 'xterm',
extended: 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(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');

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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