🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

blessed

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blessed

A high-level terminal interface library for node.js.

0.1.81
latest
Source
npm
Version published
Weekly downloads
1.6M
9.56%
Maintainers
1
Weekly downloads
 
Created

What is blessed?

The blessed npm package is a high-level terminal interface library for Node.js that allows developers to create terminal applications with rich interactive UIs. It provides a way to render widgets like text boxes, lists, and forms in the terminal, handle user input, and manage layout and rendering.

What are blessed's main functionalities?

Creating a basic window

This code creates a simple window (box) that is centered on the screen with a border and some styled text content. It also sets up a key listener to exit the application.

const blessed = require('blessed');

// Create a screen object.
const screen = blessed.screen({
  smartCSR: true
});

// Create a box perfectly centered horizontally and vertically.
const box = blessed.box({
  top: 'center',
  left: 'center',
  width: '50%',
  height: '50%',
  content: 'Hello {bold}world{/bold}!',
  tags: true,
  border: {
    type: 'line'
  },
  style: {
    fg: 'white',
    bg: 'magenta',
    border: {
      fg: '#f0f0f0'
    },
    hover: {
      bg: 'green'
    }
  }
});

// Append our box to the screen.
screen.append(box);

// Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
  return process.exit(0);
});

// Focus our element.
box.focus();

// Render the screen.
screen.render();

Handling input

This code creates an input box that allows the user to type in text. When the user submits the input, it is logged to the console, and the input box is cleared.

const blessed = require('blessed');

// Create a screen object.
const screen = blessed.screen();

// Create a box for input.
const inputBox = blessed.textbox({
  top: 'center',
  left: 'center',
  width: '50%',
  height: '10%',
  inputOnFocus: true
});

// Append input box to the screen.
screen.append(inputBox);

// Focus the input box.
inputBox.focus();

// Handle submit event.
inputBox.on('submit', function(value) {
  console.log(value);
  inputBox.clearValue();
});

// Render the screen.
screen.render();

Creating a list

This code creates a list widget with three items. The user can navigate the list using the keyboard, and the selected item's text is logged to the console when selected.

const blessed = require('blessed');

// Create a screen object.
const screen = blessed.screen();

// Create a list.
const list = blessed.list({
  items: ['Item 1', 'Item 2', 'Item 3'],
  top: 'center',
  left: 'center',
  width: '50%',
  height: '50%',
  keys: true,
  border: { type: 'line' },
  selectedBg: 'green'
});

// Append list to the screen.
screen.append(list);

// Handle item select.
list.on('select', function(item) {
  console.log(item.getText());
});

// Render the screen.
screen.render();

Other packages similar to blessed

Keywords

curses

FAQs

Package last updated on 03 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts