Gathering detailed insights and metrics for blessed
Gathering detailed insights and metrics for blessed
Gathering detailed insights and metrics for blessed
Gathering detailed insights and metrics for blessed
A high-level terminal interface library for node.js.
npm install blessed
64.8
Supply Chain
99.7
Quality
76.1
Maintenance
100
Vulnerability
93.3
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
11,338 Stars
1,170 Commits
537 Forks
116 Watching
6 Branches
12 Contributors
Updated on 29 Nov 2024
Minified
Minified + Gzipped
JavaScript (99.92%)
Shell (0.06%)
Makefile (0.02%)
Cumulative downloads
Total Downloads
Last day
-16.4%
224,298
Compared to previous day
Last week
-4.8%
1,498,544
Compared to previous week
Last month
2%
6,520,022
Compared to previous month
Last year
-18.6%
81,288,389
Compared to previous year
No dependencies detected.
A curses-like library with a high level terminal interface API for node.js.
Blessed is over 16,000 lines of code and terminal goodness. It's completely implemented in javascript, and its goal consists of two things:
Reimplement ncurses entirely by parsing and compiling terminfo and termcap,
and exposing a Program
object which can output escape sequences compatible
with any terminal.
Implement a widget API which is heavily optimized for terminals.
The blessed renderer makes use of CSR (change-scroll-region), and BCE (back-color-erase). It draws the screen using the painter's algorithm and is sped up with smart cursor movements and a screen damage buffer. This means rendering of your application will be extremely efficient: blessed only draws the changes (damage) to the screen.
Blessed is arguably as accurate as ncurses, but even more optimized in some ways. The widget library gives you an API which is reminiscent of the DOM. Anyone is able to make an awesome terminal application with blessed. There are terminal widget libraries for other platforms (primarily python and perl), but blessed is possibly the most DOM-like (dare I say the most user-friendly?).
Blessed has been used to implement other popular libraries and programs. Examples include: the slap text editor and blessed-contrib. The blessed API itself has gone on to inspire termui for Go.
1$ npm install blessed
This will render a box with line borders containing the text 'Hello world!'
,
perfectly centered horizontally and vertically.
NOTE: It is recommend you use either smartCSR
or fastCSR
as a
blessed.screen
option. This will enable CSR when scrolling text in elements
or when manipulating lines.
1var blessed = require('blessed'); 2 3// Create a screen object. 4var screen = blessed.screen({ 5 smartCSR: true 6}); 7 8screen.title = 'my window title'; 9 10// Create a box perfectly centered horizontally and vertically. 11var box = blessed.box({ 12 top: 'center', 13 left: 'center', 14 width: '50%', 15 height: '50%', 16 content: 'Hello {bold}world{/bold}!', 17 tags: true, 18 border: { 19 type: 'line' 20 }, 21 style: { 22 fg: 'white', 23 bg: 'magenta', 24 border: { 25 fg: '#f0f0f0' 26 }, 27 hover: { 28 bg: 'green' 29 } 30 } 31}); 32 33// Append our box to the screen. 34screen.append(box); 35 36// Add a png icon to the box 37var icon = blessed.image({ 38 parent: box, 39 top: 0, 40 left: 0, 41 type: 'overlay', 42 width: 'shrink', 43 height: 'shrink', 44 file: __dirname + '/my-program-icon.png', 45 search: false 46}); 47 48// If our box is clicked, change the content. 49box.on('click', function(data) { 50 box.setContent('{center}Some different {red-fg}content{/red-fg}.{/center}'); 51 screen.render(); 52}); 53 54// If box is focused, handle `enter`/`return` and give us some more content. 55box.key('enter', function(ch, key) { 56 box.setContent('{right}Even different {black-fg}content{/black-fg}.{/right}\n'); 57 box.setLine(1, 'bar'); 58 box.insertLine(1, 'foo'); 59 screen.render(); 60}); 61 62// Quit on Escape, q, or Control-C. 63screen.key(['escape', 'q', 'C-c'], function(ch, key) { 64 return process.exit(0); 65}); 66 67// Focus our element. 68box.focus(); 69 70// Render the screen. 71screen.render();
Blessed comes with a number of high-level widgets so you can avoid all the nasty low-level terminal stuff.
The base node which everything inherits from.
box
).i
.The screen on which every other node renders.
Program
to be associated with. Will be
automatically instantiated if none is provided.smartCSR
, but may cause flickering depending on
what is on each side of the element.back_color_erase
optimizations for terminals
that support it. It will also work with terminals that don't support it, but
only on lines with the default background color. As it stands with the current
implementation, it's uncertain how much terminal performance this adds at the
cost of overhead within node.null
is default).log
method.log
option if set as a boolean.debug
method. Also creates a
debug console which will display when pressing F12. It will display all log
and debug messages.C-c
) to ignore
when keys are locked or grabbed. Useful for creating a key that will always
exit no matter whether the keys are locked.┌─────────┌─────────┐
│ box1 │ box2 │
└─────────└─────────┘
Become:
┌─────────┬─────────┐
│ box1 │ box2 │
└─────────┴─────────┘
'??'
, '?'
, ''
respectively. (NOTE: iTerm2 cannot display
combining characters properly. Blessed simply removes them from an element's
content if iTerm2 is detected).true
unicode
is forced. If value is false
non-unicode is forced (default: null
).process.stdin
/process.stdout
by default, however, it could be a net.Socket
if you want to make a program
that runs over telnet or something of that nature.TERM
name used for terminfo parsing. The $TERM
env variable is
used by default.tput: true
to the Program constructor.)program.cols
).program.rows
).screen.width
.screen.height
.Set
calls screen.setTerminal()
internally.debug
option was set.screen.focused = el
).term
. Reloads terminfo.The base element.
1 { 2 fg: 'blue', 3 bg: 'black', 4 border: { 5 fg: 'blue' 6 }, 7 scrollbar: { 8 bg: 'blue' 9 }, 10 focus: { 11 bg: 'red' 12 }, 13 hover: { 14 bg: 'red' 15 } 16 }
left
, center
, or right
.top
, middle
, or bottom
.left
, right
, top
, and bottom
.0-100%
), or keyword (half
or shrink
). Percentages can also have
offsets (50%+1
, 50%-1
).0-100%
), or keyword (center
).
right
and bottom
do not accept keywords. Percentages can also have
offsets (50%+1
, 50%-1
).
).line
or bg
). bg
by default.bg
type, default is space.fg/bg/underline
). See above.scrollable
option is enabled, Element inherits all methods
from ScrollableBox.el.on('screen', ...)
except this
will automatically keep track of which listeners are bound to the screen
object. For use with removeScreenEvent()
, free()
, and destroy()
.el.removeListener('screen', ...)
except this will automatically keep track of which listeners are bound
to the screen object. For use with onScreenEvent()
, free()
, and
destroy()
.onScreenEvent()
, removeScreenEvent()
, and destroy()
.detach()
method, except this will automatically
call free()
and unbind any screen events to prevent memory leaks. for use
with onScreenEvent()
, removeScreenEvent()
, and free()
.{text:'foo',side:'left'}
{text:'foo'}
Methods for dealing with text content, line by line. Useful for writing a text editor, irc client, etc.
Note: All of these methods deal with pre-aligned, pre-wrapped text. If you use deleteTop() on a box with a wrapped line at the top, it may remove 3-4 "real" lines (rows) depending on how long the original line was.
The lines
parameter can be a string or an array of strings. The line
parameter must be a string.
el.content
.
Assume the above formatting.setContent
, but ignore tags and remove escape
codes.getContent
, but return content with tags and
escape codes removed.A box element which draws a simple box containing content
or other elements.
An element similar to Box, but geared towards rendering simple text elements.
left
, center
, or right
.Inherits all options, properties, events, and methods from Element.
A simple line which can be line
or bg
styled.
vertical
or horizontal
.style
).Inherits all options, properties, events, and methods from Box.
DEPRECATED - Use Box with the scrollable
option instead.
A box with scrollable content.
Infinity
.childOffset
. This
in turn causes the childBase to change every time the element is scrolled.scrollTo
.DEPRECATED - Use Box with the scrollable
and alwaysScroll
options
instead.
A scrollable text box which can display and scroll text, as well as handle pre-existing newlines and escape codes.
keys
option.A box which can render content drawn as 8x14 cell characters using the terminus font.
' '
)A scrollable list which can display selectable items.
keys
option.vi
mode is enabled and the key
/
is pressed. This function accepts a callback function which should be
called with the search string. The search string is then used to jump to an
item that is found in items
.true
).esc
is pressed with the keys
option).A very simple file manager for selecting files.
readdir
on cwd
and update the list items).A stylized table of text elements with a list.
2
by default:
one space on each side (only useful if the width is shrunken).1 table.setData([ 2 [ 'Animals', 'Foods' ], 3 [ 'Elephant', 'Apple' ], 4 [ 'Bird', 'Orange' ] 5 ]);
A horizontal list. Useful for a main menu bar.
keys
and callback
.commands
option above).A form which can contain form elements.
A form input.
A box which allows multiline text input.
i
or enter
for insert, e
for editor,
C-e
for editor while inserting).readInput()
when the element is focused.
Automatically unfocus.submit
).cancel
).$EDITOR
, read the output from
the resulting file. Takes a callback which receives the final value.this.value
, for now.A box which allows text input.
*
).*
).A button which can be focused and allows key and mouse input.
press
.A checkbox which can be used in a form element.
check.text = ''
).checked
.An element wrapping RadioButtons. RadioButtons within this element will be mutually exclusive with each other.
A radio button which can be used in a form element.
A prompt box containing a text input, okay, and cancel buttons (automatically hidden).
A question box containing okay and cancel buttons (automatically hidden).
question
. callback
will yield the
result.A box containing a message to be displayed (automatically hidden).
A box with a spinning line to denote loading (automatically hidden).
stop
is called.A progress bar allowing various styles. This can also be used as a form input.
horizontal
or vertical
.filled
.A log permanently scrolled to the bottom.
A stylized table of text elements.
2
by default:
one space on each side (only useful if the width is shrunken).1 table.setData([ 2 [ 'Animals', 'Foods' ], 3 [ 'Elephant', 'Apple' ], 4 [ 'Bird', 'Orange' ] 5 ]);
A box which spins up a pseudo terminal and renders the output. Useful for
writing a terminal multiplexer, or something similar to an mc-like file
manager. Requires term.js and pty.js to be installed. See
example/multiplex.js
for an example terminal multiplexer.
$SHELL
by default.line
, underline
, and block
.xterm
).element.screenshot
,
however, the specified region includes the terminal's entire scrollback,
rather than just what is visible on the screen.Display an image in the terminal (jpeg, png, gif) using either blessed's
internal png/gif-to-terminal renderer (using a ANSIImage element) or
using w3mimgdisplay
(using a OverlayImage element).
ansi
or overlay
. Whether to render the file as ANSI art or
using w3m
to overlay. See the ANSIImage element for
more information/options. (default: ansi
).Convert any .png
file (or .gif
, see below) to an ANSI image and display it
as an element. This differs from the OverlayImage
element in that it uses
blessed's internal PNG/GIF parser and does not require external dependencies.
Blessed uses an internal from-scratch PNG/GIF reader because no other javascript PNG reader supports Adam7 interlaced images (much less pass the png test suite).
The blessed PNG reader supports adam7 deinterlacing, animation (APNG), all color types, bit depths 1-32, alpha, alpha palettes, and outputs scaled bitmaps (cellmaps) in blessed for efficient rendering to the screen buffer. It also uses some code from libcaca/libcucul to add density ASCII characters in order to give the image more detail in the terminal.
If a corrupt PNG or a non-PNG is passed in, blessed will display error text in the element.
.gif
files are also supported via a javascript implementation (they are
internally converted to bitmaps and fed to the PNG renderer). Any other image
format is support only if the user has imagemagick (convert
and identify
)
installed.
0-1.0
) from its original pixel width/height
(Default: 1.0
).width
or height
in
that only one of them is needed: blessed will maintain the aspect ratio of
the image as it scales down to the proper number of cells. NOTE: PNG/GIF's
are always automatically shrunken to size (based on scale) if a width
or
height
is not given.true
).0.0-1.0
. Faster: 1-1000
.
It cannot go faster than 1 frame per millisecond, so 1000 is the fastest.
(Default: 1.0)mem
or cpu
. If optimizing for memory, animation frames
will be rendered to bitmaps as the animation plays, using less memory.
Optimizing for cpu will precompile all bitmaps beforehand, which may be
faster, but might also OOM the process on large images. (Default: mem
).Display an image in the terminal (jpeg, png, gif) using w3mimgdisplay. Requires w3m to be installed. X11 required: works in xterm, urxvt, and possibly other terminals.
w3m
to overlay
Internally uses the ANSIImage element. See the ANSIImage element for
more information/options. (Default: true
).w3mimgdisplay
path is not
given, blessed will search the entire disk for the binary./usr
, /bin
, and /lib
for
w3mimgdisplay
(Default: true
).spawnSync
.A box which spins up a pseudo terminal in order to render a video via mplayer -vo caca
or mpv --vo caca
. Requires mplayer
or mpv
to be installed with
libcaca support.
mplayer
or mpv
.A layout which can position children automatically based on a renderer
method
(experimental - the mechanics of this element may be changed in the
future!).
By default, the Layout element automatically positions children as if they were
display: inline-block;
in CSS.
inline
is the default and will render akin to inline-block
. grid
will create an automatic grid based on element dimensions. The grid cells'
width and height are always determined by the largest children in the layout.You must always give Layout
a width and height. This is a chicken-and-egg
problem: blessed cannot calculate the width and height dynamically before the
children are positioned.
border
and padding
are already calculated into the coords
object the
renderer
receives, so there is no need to account for it in your renderer.
Try to set position for children using el.position
. el.position
is the most
primitive "to-be-rendered" way to set coordinates. Setting el.left
directly
has more dynamic behavior which may interfere with rendering.
Some definitions for coords
(otherwise known as el.lpos
):
coords.xi
- the absolute x coordinate of the left side of a rendered
element. It is absolute: relative to the screen itself.coords.xl
- the absolute x coordinate of the right side of a rendered
element. It is absolute: relative to the screen itself.coords.yi
- the absolute y coordinate of the top side of a rendered
element. It is absolute: relative to the screen itself.coords.yl
- the absolute y coordinate of the bottom side of a rendered
element. It is absolute: relative to the screen itself.Note again: the coords
the renderer receives for the Layout already has
border and padding subtracted, so you do not have to account for these. The
children do not.
Here is an example of how to provide a renderer. Note that this is also the
default renderer if none is provided. This renderer will render each child as
though they were display: inline-block;
in CSS, as if there were a
dynamically sized horizontal grid from left to right.
1var layout = blessed.layout({ 2 parent: screen, 3 top: 'center', 4 left: 'center', 5 width: '50%', 6 height: '50%', 7 border: 'line', 8 style: { 9 bg: 'red', 10 border: { 11 fg: 'blue' 12 } 13 }, 14 // NOTE: This is already the default renderer if none is provided! 15 renderer: function(coords) { 16 var self = this; 17 18 // The coordinates of the layout element 19 var width = coords.xl - coords.xi 20 , height = coords.yl - coords.yi 21 , xi = coords.xi 22 , xl = coords.xl 23 , yi = coords.yi 24 , yl = coords.yl; 25 26 // The current row offset in cells (which row are we on?) 27 var rowOffset = 0; 28 29 // The index of the first child in the row 30 var rowIndex = 0; 31 32 return function iterator(el, i) { 33 // Make our children shrinkable. If they don't have a height, for 34 // example, calculate it for them. 35 el.shrink = true; 36 37 // Find the previous rendered child's coordinates 38 var last = self.getLastCoords(i); 39 40 // If there is no previously rendered element, we are on the first child. 41 if (!last) { 42 el.position.left = 0; 43 el.position.top = 0; 44 } else { 45 // Otherwise, figure out where to place this child. We'll start by 46 // setting it's `left`/`x` coordinate to right after the previous 47 // rendered element. This child will end up directly to the right of it. 48 el.position.left = last.xl - xi; 49 50 // If our child does not overlap the right side of the Layout, set it's 51 // `top`/`y` to the current `rowOffset` (the coordinate for the current 52 // row). 53 if (el.position.left + el.width <= width) { 54 el.position.top = rowOffset; 55 } else { 56 // Otherwise we need to start a new row and calculate a new 57 // `rowOffset` and `rowIndex` (the index of the child on the current 58 // row). 59 rowOffset += self.children.slice(rowIndex, i).reduce(function(out, el) { 60 if (!self.isRendered(el)) return out; 61 out = Math.max(out, el.lpos.yl - el.lpos.yi); 62 return out; 63 }, 0); 64 rowIndex = i; 65 el.position.left = 0; 66 el.position.top = rowOffset; 67 } 68 } 69 70 // If our child overflows the Layout, do not render it! 71 // Disable this feature for now. 72 if (el.position.top + el.height > height) { 73 // Returning false tells blessed to ignore this child. 74 // return false; 75 } 76 }; 77 } 78}); 79 80for (var i = 0; i < 10; i++) { 81 blessed.box({ 82 parent: layout, 83 width: i % 2 === 0 ? 10 : 20, 84 height: i % 2 === 0 ? 5 : 10, 85 border: 'line' 86 }); 87}
All helpers reside on blessed.helpers
or blessed
.
a
and b
into object a
.name
prop.index
prop.start
directory with name
target
.el.setContent()
.
Example: box.setContent('escaped tag: ' + blessed.escape('{bold}{/bold}'));
style
object.style
attributes to binary
format.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:
1box.setContent('hello {red-fg}{green-bg}{bold}world{/bold}{/green-bg}{/red-fg}');
To make this more concise {/}
cancels all character attributes.
1box.setContent('hello {red-fg}{green-bg}{bold}world{/}');
Blessed tags support the basic 16 colors for colors, as well as up to 256 colors.
1box.setContent('hello {red-fg}{green-bg}world{/}');
Tags can also use hex colors (which will be reduced to the most accurate terminal color):
1box.setContent('hello {#ff0000-fg}{#00ff00-bg}world{/}');
Blessed supports all terminal attributes, including bold
, underline
,
blink
, inverse
, and invisible
.
1box.setContent('hello {bold}world{/bold}');
Newlines and alignment are also possible in content.
1box.setContent('hello\n'
2 + '{right}world{/right}\n'
3 + '{center}foo{/center}\n');
4 + 'left{|}right');
This will produce a box that looks like:
| hello |
| world |
| foo |
| left right |
Escaping can either be done using blessed.escape()
box.setContent('here is an escaped tag: ' + blessed.escape('{bold}{/bold}'));
Or with the special {open}
and {close}
tags:
box.setContent('here is an escaped tag: {open}bold{close}{open}/bold{close}');
Either will produce:
here is an escaped tag: {bold}{/bold}
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.
The style option controls most of the visual aspects of an element.
1 style: { 2 fg: 'blue', 3 bg: 'black', 4 bold: true, 5 underline: false, 6 blink: false, 7 inverse: false, 8 invisible: false, 9 transparent: false, 10 border: { 11 fg: 'blue', 12 bg: 'red' 13 }, 14 scrollbar: { 15 bg: 'blue' 16 }, 17 focus: { 18 bg: 'red' 19 }, 20 hover: { 21 bg: 'red' 22 } 23 }
Colors can be the names of any of the 16 basic terminal colors, along with hex
values (e.g. #ff0000
) for 256 color terminals. If 256 or 88 colors is not
supported. Blessed with reduce the color to whatever is available.
Blessed supports all terminal attributes, including bold
, underline
,
blink
, inverse
, and invisible
. Attributes are represented as bools in the
style
object.
Blessed can set the opacity of an element to 50% using style.transparent = true;
. While this seems like it normally shouldn't be possible in a terminal,
blessed will use a color blending algorithm to blend the element of the
foremost element with the background behind it. Obviously characters cannot be
blended, but background colors can.
Translucent shadows are also an option when it comes to styling an element. This option will create a 50% opacity 2-cell wide, 1-cell high shadow offset to the bottom-right.
1shadow: true
Blessed supports hover and focus styles. (Hover is only useful is mouse input is enabled).
1 style: { 2 hover: { 3 bg: 'red' 4 }, 5 focus: { 6 border: { 7 fg: 'blue' 8 } 9 } 10 }
On scrollable elements, blessed will support style options for the scrollbar, such as:
1style: { 2 scrollbar: { 3 bg: 'red', 4 fg: 'blue' 5 } 6}
As a main option, scrollbar will either take a bool or an object:
1scrollbar: { 2 ch: ' ' 3}
Or:
1scrollbar: true
Events in Blessed work similar to the traditional node.js model, with one important difference: they have a concept of a tree and event bubbling.
Events can bubble in blessed. For example:
Receiving all click events for box
(a normal event listener):
1box.on('click', function(mouse) { 2 box.setContent('You clicked ' + mouse.x + ', ' + mouse.y + '.'); 3 screen.render(); 4});
Receiving all click events for box
, as well as all of its children:
1box.on('element click', function(el, mouse) { 2 box.setContent('You clicked ' 3 + el.type + ' at ' + mouse.x + ', ' + mouse.y + '.'); 4 screen.render(); 5 if (el === box) { 6 return false; // Cancel propagation. 7 } 8});
el
gets passed in as the first argument. It refers to the target element the
event occurred on. Returning false
will cancel propagation up the tree.
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:
1var box = blessed.box({ 2 left: 'center', 3 top: 'center', 4 bg: 'yellow', 5 width: '50%', 6 height: '50%' 7});
This tells blessed to create a box, perfectly centered relative to its parent, 50% as wide and 50% as tall as its parent.
Percentages can also have offsets applied to them:
1 ... 2 height: '50%-1', 3 left: '45%+1', 4 ...
To access the calculated offsets, relative to the parent:
1console.log(box.left); 2console.log(box.top);
To access the calculated offsets, absolute (relative to the screen):
1console.log(box.aleft); 2console.log(box.atop);
This still needs to be tested a bit, but it should work.
To actually render the screen buffer, you must call render
.
1box.setContent('Hello {#0fe1ab-fg}world{/}.'); 2screen.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.
Terminal cursors can be tricky. They all have different custom escape codes to alter. As an experimental alternative, blessed can draw a cursor for you, allowing you to have a custom cursor that you control.
1var screen = blessed.screen({ 2 cursor: { 3 artificial: true, 4 shape: 'line', 5 blink: true, 6 color: null // null for default 7 } 8});
That's it. It's controlled the same way as the regular cursor.
To create a custom cursor:
1var screen = blessed.screen({ 2 cursor: { 3 artificial: true, 4 shape: { 5 bg: 'red', 6 fg: 'white', 7 bold: true, 8 ch: '#' 9 }, 10 blink: true 11 } 12});
Blessed supports the ability to create multiple screens. This may not seem useful at first, but if you're writing a program that serves terminal interfaces over http, telnet, or any other protocol, this can be very useful.
A simple telnet server might look like this (see examples/blessed-telnet.js for a full example):
1var blessed = require('blessed'); 2var telnet = require('telnet2'); 3 4telnet({ tty: true }, function(client) { 5 client.on('term', function(terminal) { 6 screen.terminal = terminal; 7 screen.render(); 8 }); 9 10 client.on('size', function(width, height) { 11 client.columns = width; 12 client.rows = height; 13 client.emit('resize'); 14 }); 15 16 var screen = blessed.screen({ 17 smartCSR: true, 18 input: client, 19 output: client, 20 terminal: 'xterm-256color', 21 fullUnicode: true 22 }); 23 24 client.on('close', function() { 25 if (!screen.destroyed) { 26 screen.destroy(); 27 } 28 }); 29 30 screen.key(['C-c', 'q'], function(ch, key) { 31 screen.destroy(); 32 }); 33 34 screen.on('destroy', function() { 35 if (client.writable) { 36 client.destroy(); 37 } 38 }); 39 40 screen.data.main = blessed.box({ 41 parent: screen, 42 left: 'center', 43 top: 'center', 44 width: '80%', 45 height: '90%', 46 border: 'line', 47 content: 'Welcome to my server. Here is your own private session.' 48 }); 49 50 screen.render(); 51}).listen(2300);
Once you've written something similar and started it, you can simply telnet into your blessed app:
1$ telnet localhost 2300
Creating a netcat server would also work as long as you disable line buffering
and terminal echo on the commandline via stty
:
$ stty -icanon -echo; ncat localhost 2300; stty icanon echo
Or by using netcat's -t
option: $ ncat -t localhost 2300
Creating a streaming http 1.1 server than runs in the terminal is possible by
curling it with special arguments: $ curl -sSNT. localhost:8080
.
There are currently no examples of netcat/nc/ncat or http->curl servers yet.
The blessed.screen
constructor can accept input
, output
, and term
arguments to aid with this. The multiple screens will be managed internally by
blessed. The programmer just has to keep track of the references, however, to
avoid ambiguity, it's possible to explicitly dictate which screen a node is
part of by using the screen
option when creating an element.
The screen.destroy()
method is also crucial: this will clean up all event
listeners the screen has bound and make sure it stops listening on the event
loop. Make absolutely certain to remember to clean up your screens once you're
done with them.
A tricky part is making sure to include the ability for the client to send the TERM which is reset on the serverside, and the terminal size, which is should also be reset on the serverside. Both of these capabilities are demonstrated above.
For a working example of a blessed telnet server, see
examples/blessed-telnet.js
.
Currently there is no mouse
or resize
event support on Windows.
Windows users will need to explicitly set term
when creating a screen like so
(NOTE: This is no longer necessary as of the latest versions of blessed.
This is now handled automatically):
1var screen = blessed.screen({ terminal: 'windows-ansi' });
This will actually parse the xterm terminfo and compile every string capability to a javascript function:
1var blessed = require('blessed'); 2 3var tput = blessed.tput({ 4 terminal: 'xterm-256color', 5 extended: true 6}); 7 8process.stdout.write(tput.setaf(4) + 'Hello' + tput.sgr0() + '\n');
To play around with it on the command line, it works just like tput:
1$ tput.js setaf 2 2$ tput.js sgr0 3$ echo "$(tput.js setaf 2)Hello World$(tput.js sgr0)"
The main functionality is exposed in the main blessed
module:
1var blessed = require('blessed') 2 , program = blessed.program(); 3 4program.key('q', function(ch, key) { 5 program.clear(); 6 program.disableMouse(); 7 program.showCursor(); 8 program.normalBuffer(); 9 process.exit(0); 10}); 11 12program.on('mouse', function(data) { 13 if (data.action === 'mousemove') { 14 program.move(data.x, data.y); 15 program.bg('red'); 16 program.write('x'); 17 program.bg('!red'); 18 } 19}); 20 21program.alternateBuffer(); 22program.enableMouse(); 23program.hideCursor(); 24program.clear(); 25 26program.move(1, 1); 27program.bg('black'); 28program.write('Hello world', 'blue fg'); 29program.setx((program.cols / 2 | 0) - 4); 30program.down(5); 31program.write('Hi again!'); 32program.bg('!black'); 33program.feed();
Most tests contained in the test/
directory are interactive. It's up to the
programmer to determine whether the test is properly displayed. In the future
it might be better to do something similar to vttest.
Examples can be found in examples/
.
ncurses-base
package and the ncurses-term
package. (#98)127
to 255
. If
you're not happy with this, you may want to look into using xterm or urxvt,
or a terminal which uses a modern VTE, like gnome-terminal.If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. </legalese>
Copyright (c) 2013-2015, Christopher Jeffrey. (MIT License)
See LICENSE for more info.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More