2013-01-27 16:06:58 +00:00
|
|
|
# blessed
|
|
|
|
|
|
|
|
A curses-like library for node.js.
|
|
|
|
|
2013-02-24 02:52:49 +00:00
|
|
|
Blessed was originally written to only support the xterm terminfo, but can
|
|
|
|
now parse and compile any terminfo to be completely portable accross all
|
|
|
|
terminals. See the `tput` example below.
|
2013-01-27 17:14:06 +00:00
|
|
|
|
2013-06-20 11:43:56 +00:00
|
|
|
Blessed also includes an extremely high-level widget library.
|
2013-01-27 17:14:06 +00:00
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
2013-02-24 02:52:49 +00:00
|
|
|
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');
|
|
|
|
|
2013-02-24 16:59:20 +00:00
|
|
|
console.log(tput.setaf(4) + 'hello' + tput.sgr0());
|
2013-02-24 02:52:49 +00:00
|
|
|
```
|
|
|
|
|
2013-02-24 18:14:12 +00:00
|
|
|
To play around with it on the command line, it works just like tput:
|
|
|
|
|
|
|
|
``` bash
|
|
|
|
$ tput.js setaf 2
|
|
|
|
$ tput.js sgr0
|
2013-02-24 18:53:37 +00:00
|
|
|
$ echo "$(tput.js setaf 2)hello world$(tput.js sgr0)"
|
2013-02-24 18:14:12 +00:00
|
|
|
```
|
|
|
|
|
2013-06-20 11:43:56 +00:00
|
|
|
The main functionality is exposed in the main `blessed` module:
|
2013-02-24 18:14:12 +00:00
|
|
|
|
2013-01-27 17:14:06 +00:00
|
|
|
``` js
|
2013-01-30 05:26:27 +00:00
|
|
|
var blessed = require('blessed')
|
|
|
|
, program = blessed();
|
|
|
|
|
|
|
|
program.on('keypress', function(ch, key) {
|
|
|
|
if (key.name === 'q') {
|
|
|
|
program.clear();
|
|
|
|
program.disableMouse();
|
|
|
|
program.showCursor();
|
|
|
|
program.normalBuffer();
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
2013-01-27 17:14:06 +00:00
|
|
|
|
2013-01-30 05:26:27 +00:00
|
|
|
program.on('mouse', function(data) {
|
2013-06-18 16:00:41 +00:00
|
|
|
if (data.action === 'mousemove') {
|
|
|
|
program.move(data.x, data.y);
|
|
|
|
program.bg('red');
|
|
|
|
program.write('x');
|
|
|
|
program.bg('!red');
|
2013-01-27 17:14:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
program.alternateBuffer();
|
2013-01-30 05:26:27 +00:00
|
|
|
program.enableMouse();
|
|
|
|
program.hideCursor();
|
2013-01-27 17:14:06 +00:00
|
|
|
program.clear();
|
|
|
|
|
2013-01-30 05:26:27 +00:00
|
|
|
program.move(1, 1);
|
|
|
|
program.bg('black');
|
2013-01-27 18:33:32 +00:00
|
|
|
program.write('Hello world', 'blue fg');
|
2013-01-30 05:26:27 +00:00
|
|
|
program.setx((program.cols / 2 | 0) - 4);
|
2013-01-27 17:14:06 +00:00
|
|
|
program.down(5);
|
|
|
|
program.write('Hi again!');
|
2013-01-30 05:26:27 +00:00
|
|
|
program.bg('!black');
|
2013-01-27 17:14:06 +00:00
|
|
|
program.feed();
|
|
|
|
```
|
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
## High-level Documentation
|
|
|
|
|
|
|
|
### Example
|
|
|
|
|
|
|
|
This will render a box with ascii borders containing the text 'Hello world!',
|
2013-06-14 00:02:02 +00:00
|
|
|
perfectly centered horizontally and vertically.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
``` js
|
|
|
|
var blessed = require('blessed')
|
2013-06-24 11:16:02 +00:00
|
|
|
, screen = new blessed.Screen;
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-24 11:16:02 +00:00
|
|
|
var box = new blessed.Box({
|
2013-06-11 16:48:37 +00:00
|
|
|
top: 'center',
|
|
|
|
left: 'center',
|
|
|
|
width: '50%',
|
|
|
|
height: '50%',
|
|
|
|
border: {
|
|
|
|
type: 'ascii',
|
2013-06-14 00:02:02 +00:00
|
|
|
fg: 'white'
|
2013-06-11 16:48:37 +00:00
|
|
|
},
|
2013-06-14 00:02:02 +00:00
|
|
|
fg: 'white',
|
|
|
|
bg: 'magenta',
|
2013-06-11 16:48:37 +00:00
|
|
|
content: 'Hello world!',
|
2013-06-24 11:16:02 +00:00
|
|
|
tags: true
|
|
|
|
});
|
|
|
|
|
|
|
|
screen.append(box);
|
|
|
|
|
|
|
|
box.on('click', function(data) {
|
|
|
|
box.setContent('{center}Some different {red-fg}content{/red-fg}.{/center}');
|
|
|
|
});
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
screen.on('keypress', function(ch, key) {
|
|
|
|
if (key.name === 'escape') {
|
2013-06-14 00:02:02 +00:00
|
|
|
return process.exit(0);
|
2013-06-11 16:48:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
screen.render();
|
|
|
|
```
|
|
|
|
|
|
|
|
### Widgets
|
|
|
|
|
|
|
|
Blessed comes with a number of high-level widgets so you can avoid all the
|
|
|
|
nasty low-level terminal stuff.
|
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### Node (from EventEmitter)
|
|
|
|
|
|
|
|
The base node which everything inherits from.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
- **screen** - the screen to be associated with.
|
|
|
|
- **parent** - the desired parent.
|
|
|
|
- **children** - an arrray of children.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from EventEmitter.
|
2013-06-18 11:30:26 +00:00
|
|
|
- **options** - original options object.
|
|
|
|
- **parent** - parent node.
|
|
|
|
- **screen** - parent screen.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **children** - array of node's children.
|
2013-06-18 11:30:26 +00:00
|
|
|
- **data, _, $** - an object for any miscellanous user data.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from EventEmitter.
|
2013-06-11 18:13:49 +00:00
|
|
|
- **adopt** - received when node is added to a parent.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **remove** - received when node is removed from it's current parent.
|
|
|
|
- **reparent** - received when node gains a new parent.
|
2013-06-20 11:43:56 +00:00
|
|
|
- **attach** - received when node is attached to the screen directly or
|
|
|
|
somewhere in its ancestry.
|
|
|
|
- **detach** - received when node is detached from the screen directly or
|
|
|
|
somewhere in its ancestry.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from EventEmitter.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **prepend(node)** - prepend a node to this node's children.
|
|
|
|
- **append(node)** - append a node to this node's children.
|
|
|
|
- **remove(node)** - remove child node from node.
|
|
|
|
- **detach()** - remove node from its parent.
|
2013-06-20 12:18:04 +00:00
|
|
|
- **emitDescendants(type, args..., [iterator])** - emit event for element, and
|
|
|
|
recursively emit same event for all descendants.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### Screen (from Node)
|
|
|
|
|
|
|
|
The screen on which every other node renders.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
- **program** - the blessed Program to be associated with.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Node.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **program** - the blessed Program object.
|
2013-06-13 21:49:48 +00:00
|
|
|
- **tput** - the blessed Tput object (only available if you passed `tput: true`
|
|
|
|
to the Program constructor.)
|
2013-06-11 17:52:18 +00:00
|
|
|
- **focused** - top of the focus history stack.
|
|
|
|
- **width** - width of the screen (same as `program.cols`).
|
|
|
|
- **height** - height of the screen (same as `program.rows`).
|
2013-06-13 21:49:48 +00:00
|
|
|
- **cols** - same as `screen.width`.
|
|
|
|
- **rows** - same as `screen.height`.
|
|
|
|
- **left**, **rleft** - left offset, always zero.
|
|
|
|
- **right**, **rright** - right offset, always zero.
|
|
|
|
- **top**, **rtop** - top offset, always zero.
|
|
|
|
- **bottom**, **rbottom** - bottom offset, always zero.
|
2013-06-18 15:52:48 +00:00
|
|
|
- **grabKeys** - whether the focused element grabs all keypresses.
|
|
|
|
- **lockKeys** - prevent keypresses from being received by any element.
|
2013-06-11 17:52:18 +00:00
|
|
|
|
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Node.
|
2013-06-16 14:31:55 +00:00
|
|
|
- **resize** - received on screen resize.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **mouse** - received on mouse events.
|
|
|
|
- **keypress** - received on key events.
|
|
|
|
- **element [name]** - global events received for all elements.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Node.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **alloc()** - allocate a new pending screen buffer and a new output screen buffer.
|
|
|
|
- **draw(start, end)** - draw the screen based on the contents of the screen buffer.
|
|
|
|
- **render()** - render all child elements, writing all data to the screen buffer and drawing the screen.
|
|
|
|
- **clearRegion(x1, x2, y1, y2)** - clear any region on the screen.
|
|
|
|
- **fillRegion(attr, ch, x1, x2, y1, y2)** - fill any region with a character of a certain attribute.
|
|
|
|
- **focus(offset)** - focus element by offset of focusable elements.
|
|
|
|
- **focusPrev()** - focus previous element in the index.
|
|
|
|
- **focusNext()** - focus next element in the index.
|
|
|
|
- **focusPush(element)** - push element on the focus stack (equivalent to `screen.focused = el`).
|
|
|
|
- **focusPop()/focusLast()** - pop element off the focus stack.
|
2013-06-20 18:03:31 +00:00
|
|
|
- **saveFocus()** - save the focused element.
|
|
|
|
- **restoreFocus()** - restore the saved focused element.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### Element (from Node)
|
|
|
|
|
|
|
|
The base element.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
- **fg, bg, bold, underline** - attributes.
|
|
|
|
- **border** - border object, see below.
|
|
|
|
- **content** - element's text content.
|
|
|
|
- **clickable** - element is clickable.
|
|
|
|
- **input** - element is focusable and can receive key input.
|
|
|
|
- **hidden** - whether the element is hidden.
|
|
|
|
- **label** - a simple text label for the element.
|
2013-06-13 09:14:14 +00:00
|
|
|
- **align** - text alignment: `left`, `center`, or `right`.
|
2013-06-13 21:49:48 +00:00
|
|
|
- **shrink** - shrink/flex/grow to content width during render.
|
2013-06-14 00:02:02 +00:00
|
|
|
- **padding** - amount of padding on the inside of the element.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Node.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **border** - border object.
|
|
|
|
- **type** - type of border (`ascii` or `bg`). `bg` by default.
|
2013-06-11 17:53:28 +00:00
|
|
|
- **ch** - character to use if `bg` type, default is space.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **bg, fg** - border foreground and background, must be numbers (-1 for default).
|
|
|
|
- **bold, underline** - border attributes.
|
|
|
|
- **position** - raw width, height, and offsets.
|
|
|
|
- **content** - text content.
|
|
|
|
- **hidden** - whether the element is hidden or not.
|
|
|
|
- **fg, bg** - foreground and background, must be numbers (-1 for default).
|
|
|
|
- **bold, underline** - attributes.
|
|
|
|
- **width** - calculated width.
|
|
|
|
- **height** - calculated height.
|
|
|
|
- **left** - calculated absolute left offset.
|
|
|
|
- **right** - calculated absolute right offset.
|
|
|
|
- **top** - calculated absolute top offset.
|
|
|
|
- **bottom** - calculated absolute bottom offset.
|
|
|
|
- **rleft** - calculated relative left offset.
|
|
|
|
- **rright** - calculated relative right offset.
|
|
|
|
- **rtop** - calculated relative top offset.
|
|
|
|
- **rbottom** - calculated relative bottom offset.
|
|
|
|
|
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Node.
|
2013-06-16 14:31:55 +00:00
|
|
|
- **blur, focus** - received when an element is focused or unfocused.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **mouse** - received on mouse events for this element.
|
2013-06-16 14:31:55 +00:00
|
|
|
- **mousedown, mouseup** - mouse button was pressed or released.
|
|
|
|
- **wheeldown, wheelup** - wheel was scrolled down or up.
|
|
|
|
- **mouseover, mouseout** - element was hovered or unhovered.
|
|
|
|
- **mousemove** - mouse was moved somewhere on this element.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **keypress** - received on key events for this element.
|
|
|
|
- **move** - received when the element is moved.
|
|
|
|
- **resize** - received when the element is resized.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Node.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **render()** - write content and children to the screen buffer.
|
|
|
|
- **setContent(text)** - set the content.
|
|
|
|
- **hide()** - hide element.
|
|
|
|
- **show()** - show element.
|
|
|
|
- **toggle()** - toggle hidden/shown.
|
|
|
|
- **focus()** - focus element.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### Box (from Element)
|
|
|
|
|
|
|
|
A box element which draws a simple box containing `content` or other elements.
|
|
|
|
|
|
|
|
Inherits all options, properties, events, and methods from Box.
|
|
|
|
|
|
|
|
#### Text (from Element)
|
|
|
|
|
|
|
|
An element similar to Box, but geared towards rendering simple text elements.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Element.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **fill** - fill the entire line with chosen bg until parent bg ends, even if
|
2013-06-13 21:49:48 +00:00
|
|
|
there is not enough text to fill the entire width. **(deprecated)**
|
2013-06-13 09:14:14 +00:00
|
|
|
- **align** - text alignment: `left`, `center`, or `right`.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
Inherits all options, properties, events, and methods from Element.
|
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### Line (from Box)
|
|
|
|
|
|
|
|
A simple line which can be `ascii` or `bg` styled.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Box.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **orientation** - can be `vertical` or `horizontal`.
|
|
|
|
- **type, bg, fg, ch** - treated the same as a border object.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
Inherits all options, properties, events, and methods from Box.
|
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### ScrollableBox (from Box)
|
|
|
|
|
|
|
|
A box with scrollable content.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Box.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **baseLimit** - a limit to the childBase. default is `Infinity`.
|
|
|
|
- **alwaysScroll** - a option which causes the ignoring of `childOffset`. this in
|
2013-06-11 16:48:37 +00:00
|
|
|
turn causes the childBase to change every time the element is scrolled.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Box.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **childBase** - the offset of the top of the scroll content.
|
|
|
|
- **childOffset** - the offset of the chosen item (if there is one).
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Box.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **scroll** - received when the element is scrolled.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
- **scroll(offset)** - scroll the content by an offset.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### List (from ScrollableBox)
|
|
|
|
|
|
|
|
A scrollable list which can display selectable items.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **selectFg, selectedBg** - foreground and background for selected item, treated
|
2013-06-11 16:48:37 +00:00
|
|
|
like fg and bg.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **selectedBold, selectedUnderline** - character attributes for selected item,
|
2013-06-11 16:48:37 +00:00
|
|
|
treated like bold and underline.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **mouse** - whether to automatically enable mouse support for this list (allows
|
2013-06-11 16:48:37 +00:00
|
|
|
clicking items).
|
2013-06-18 15:52:48 +00:00
|
|
|
- **keys** - use predefined keys for navigating the list.
|
|
|
|
- **vi** - use vi keys with the `keys` option.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **items** - an array of strings which become the list's items.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **select** - received when an item is selected.
|
2013-06-18 15:52:48 +00:00
|
|
|
- **cancel** - list was canceled (when `esc` is pressed with the `keys` option).
|
|
|
|
- **action** - either a select or a cancel event was received.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **add(text)** - add an item based on a string.
|
|
|
|
- **select(index)** - select an index of an item.
|
|
|
|
- **move(offset)** - select item based on current offset.
|
|
|
|
- **up(amount)** - select item above selected.
|
|
|
|
- **down(amount)** - select item below selected.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### ScrollableText (from ScrollableBox)
|
|
|
|
|
|
|
|
A scrollable text box which can display and scroll text, as well as handle pre-existing newlines and escape codes.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **mouse** - whether to enable automatic mouse support for this element.
|
2013-06-18 15:52:48 +00:00
|
|
|
- **keys** - use predefined keys for navigating the text.
|
|
|
|
- **vi** - use vi keys with the `keys` option.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
|
|
|
|
|
|
|
#### Input (from Box)
|
|
|
|
|
|
|
|
A form input.
|
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### Textbox (from Input)
|
|
|
|
|
|
|
|
A box which allows text input.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **setInput(callback)** - grab key events and start reading text from the
|
2013-06-11 16:48:37 +00:00
|
|
|
keyboard. takes a callback which receives the final value.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **setEditor(callback)** - open text editor in $EDITOR, read the output from the
|
2013-06-11 16:48:37 +00:00
|
|
|
resulting file. takes a callback which receives the final value.
|
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
|
|
|
#### Button (from Input)
|
|
|
|
|
|
|
|
A button which can be focused and allows key and mouse input.
|
|
|
|
|
|
|
|
##### Options:
|
|
|
|
|
|
|
|
- inherits all from Input.
|
|
|
|
|
|
|
|
##### Properties:
|
|
|
|
|
|
|
|
- inherits all from Input.
|
|
|
|
|
|
|
|
##### Events:
|
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
|
|
|
- **press** - received when the button is clicked/pressed.
|
|
|
|
|
|
|
|
##### Methods:
|
|
|
|
|
|
|
|
- inherits all from ScrollableBox.
|
|
|
|
- **add(text)** - add an item based on a string.
|
|
|
|
- **select(index)** - select an index of an item.
|
|
|
|
- **move(offset)** - select item based on current offset.
|
|
|
|
- **up(amount)** - select item above selected.
|
|
|
|
- **down(amount)** - select item below selected.
|
|
|
|
|
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
#### ProgressBar (from Input)
|
|
|
|
|
|
|
|
A progress bar allowing various styles.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Options:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **barFg, barBg** - (completed) bar foreground and background.
|
|
|
|
- **ch** - the character to fill the bar with (default is space).
|
|
|
|
- **filled** - the amount filled (0 - 100).
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Properties:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Events:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **reset** - bar was reset.
|
|
|
|
- **complete** - bar has completely filled.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-11 17:52:18 +00:00
|
|
|
##### Methods:
|
2013-06-11 16:48:37 +00:00
|
|
|
|
|
|
|
- inherits all from Input.
|
2013-06-11 17:52:18 +00:00
|
|
|
- **progress(amount)** - progress the bar by a fill amount.
|
|
|
|
- **reset()** - reset the bar.
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-06-16 09:21:57 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
### Positioning
|
|
|
|
|
|
|
|
Offsets may be a number, a percentage (e.g. `50%`), or a keyword (e.g.
|
|
|
|
`center`).
|
|
|
|
|
|
|
|
Dimensions may be a number, or a percentage (e.g. `50%`).
|
|
|
|
|
|
|
|
Positions are treated almost *exactly* the same as they are in CSS/CSSOM when
|
|
|
|
an element has the `position: absolute` CSS property.
|
|
|
|
|
|
|
|
When an element is created, it can be given coordinates in its constructor:
|
|
|
|
|
|
|
|
``` js
|
|
|
|
var box = new blessed.Box({
|
|
|
|
left: 'center',
|
|
|
|
top: 'center',
|
2013-06-14 00:02:02 +00:00
|
|
|
bg: 'yellow',
|
2013-06-11 16:48:37 +00:00
|
|
|
width: '50%',
|
|
|
|
height: '50%'
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
This tells blessed to create a box, perfectly centered **relative to its
|
|
|
|
parent**, 50% as wide and 50% as tall as its parent.
|
|
|
|
|
|
|
|
To access the calculated offsets, relative to the parent:
|
|
|
|
|
|
|
|
``` js
|
|
|
|
console.log(box.rleft);
|
|
|
|
console.log(box.rtop);
|
|
|
|
```
|
|
|
|
|
|
|
|
To access the calculated offsets, absolute (relative to the screen):
|
|
|
|
|
|
|
|
``` js
|
|
|
|
console.log(box.left);
|
|
|
|
console.log(box.top);
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Overlapping offsets and dimensions greater than parents'
|
|
|
|
|
|
|
|
This still needs to be tested a bit, but it should work.
|
|
|
|
|
2013-06-24 11:16:02 +00:00
|
|
|
### Content
|
|
|
|
|
|
|
|
Every element can have text content via `setContent`. If `tags: true` was
|
|
|
|
passed to the element's constructor, the content can contain tags. For example:
|
|
|
|
|
|
|
|
```
|
|
|
|
box.setContent('hello {red-fg}{green-bg}{bold}world{/bold}{/green-bg}{/red-fg}');
|
|
|
|
```
|
|
|
|
|
|
|
|
To make this more concise `{/}` cancels all character attributes.
|
|
|
|
|
|
|
|
```
|
|
|
|
box.setContent('hello {red-fg}{green-bg}{bold}world{/}');
|
|
|
|
```
|
|
|
|
|
|
|
|
Newlines and alignment are also possible in content.
|
|
|
|
|
|
|
|
```
|
|
|
|
box.setContent('hello\n'
|
|
|
|
+ '{right}world{/right}\n'
|
|
|
|
+ '{center}foo{/center}');
|
|
|
|
```
|
|
|
|
|
|
|
|
This will produce a box that looks like:
|
|
|
|
|
|
|
|
```
|
|
|
|
| hello |
|
|
|
|
| world |
|
|
|
|
| foo |
|
|
|
|
```
|
|
|
|
|
|
|
|
Content can also handle SGR escape codes. This means if you got output from a
|
|
|
|
program, say `git log` for example, you can feed it directly to an element's
|
|
|
|
content and the colors will be parsed appropriately.
|
|
|
|
|
|
|
|
This means that while `{red-fg}foo{/red-fg}` produces `^[[31mfoo^[[39m`, you
|
|
|
|
could just feed `^[[31mfoo^[[39m` directly to the content.
|
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
### Rendering
|
|
|
|
|
|
|
|
To actually render the screen buffer, you must call `render`.
|
|
|
|
|
|
|
|
``` js
|
|
|
|
box.setContent('Hello world.');
|
|
|
|
screen.render();
|
|
|
|
```
|
|
|
|
|
|
|
|
Elements are rendered with the lower elements in the children array being
|
|
|
|
painted first. In terms of the painter's algorithm, the lowest indicies in the
|
|
|
|
array are the furthest away, just like in the DOM.
|
|
|
|
|
|
|
|
### Testing
|
|
|
|
|
|
|
|
- For an interactive test, see `test/widget.js`.
|
|
|
|
- For a less interactive position testing, see `test/widget-pos.js`.
|
|
|
|
|
2013-01-27 16:06:58 +00:00
|
|
|
## License
|
|
|
|
|
|
|
|
Copyright (c) 2013, Christopher Jeffrey. (MIT License)
|
|
|
|
|
|
|
|
See LICENSE for more info.
|