charm vs blessed
Terminal User Interface Libraries Comparison
1 Year
charmblessedSimilar Packages:
What's Terminal User Interface Libraries?

Terminal User Interface (TUI) libraries are essential tools for building interactive command-line applications that provide a rich user experience. These libraries allow developers to create text-based interfaces that can handle user input, display dynamic content, and manage layouts in a structured manner. They are particularly useful for applications that require a more engaging interface than simple command-line output, enabling functionalities like menus, forms, and real-time updates. Both Blessed and Charm serve this purpose but cater to different needs and design philosophies.

Package Weekly Downloads Trend
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
charm1,613,605---8 years agoMIT
blessed1,484,05511,449-2569 years agoMIT
Feature Comparison: charm vs blessed

Component Support

  • charm:

    Charm is more focused on creating simple and lightweight terminal applications. It offers basic components like text and colors but lacks the extensive component library of Blessed, making it suitable for simpler UIs.

  • blessed:

    Blessed provides a wide array of pre-built components such as buttons, text boxes, and lists, making it easy to create complex interfaces without starting from scratch. It also supports advanced features like mouse events and keyboard navigation, enhancing user interaction.

Performance

  • charm:

    Charm is lightweight and fast, but it may not perform as well as Blessed in scenarios with many UI components. It is best suited for applications where performance is critical and complexity is minimal.

  • blessed:

    Blessed is optimized for performance and can handle a large number of components efficiently. It uses a virtual DOM approach to minimize re-renders, which is beneficial for applications with dynamic content.

Customization

  • charm:

    Charm provides basic styling capabilities, focusing on simplicity rather than extensive customization. It is suitable for developers who prefer a straightforward approach without the need for elaborate designs.

  • blessed:

    Blessed offers extensive customization options, allowing developers to style components using various attributes and methods. This flexibility enables the creation of visually appealing interfaces tailored to specific needs.

Learning Curve

  • charm:

    Charm is easier to learn and use, making it a good choice for beginners or those looking to quickly build simple terminal applications without a steep learning curve.

  • blessed:

    Blessed has a steeper learning curve due to its rich feature set and extensive API. Developers may need to invest more time to understand its capabilities and how to leverage them effectively.

Community and Support

  • charm:

    Charm has a smaller community and less documentation available, which may pose challenges for developers seeking help or examples. However, its simplicity can mitigate some of these issues.

  • blessed:

    Blessed has a larger community and more extensive documentation, providing ample resources for troubleshooting and learning. This support can be invaluable for developers facing challenges during implementation.

How to Choose: charm vs blessed
  • blessed:

    Choose Blessed if you need a comprehensive and feature-rich library that supports a wide range of UI components, including forms, boxes, and lists. It is ideal for applications that require complex layouts and extensive customization options.

README for charm

charm

Use ansi terminal characters to write colors and cursor positions.

me lucky charms

example

lucky

var charm = require('charm')();
charm.pipe(process.stdout);
charm.reset();

var colors = [ 'red', 'cyan', 'yellow', 'green', 'blue' ];
var text = 'Always after me lucky charms.';

var offset = 0;
var iv = setInterval(function () {
    var y = 0, dy = 1;
    for (var i = 0; i < 40; i++) {
        var color = colors[(i + offset) % colors.length];
        var c = text[(i + offset) % text.length];
        charm
            .move(1, dy)
            .foreground(color)
            .write(c)
        ;
        y += dy;
        if (y <= 0 || y >= 5) dy *= -1;
    }
    charm.position(0, 1);
    offset ++;
}, 150);

events

Charm objects pass along the data events from their input stream except for events generated from querying the terminal device.

Because charm puts stdin into raw mode, charm emits two special events: "^C" and "^D" when the user types those combos. It's super convenient with these events to do:

charm.on('^C', process.exit)

The above is set on all charm streams. If you want to add your own handling for these special events simply:

charm.removeAllListeners('^C')
charm.on('^C', function () {
  // Don't exit. Do some mad science instead.
})

methods

var charm = require('charm')(param or stream, ...)

Create a new readable/writable charm stream.

You can pass in readable or writable streams as parameters and they will be piped to or from accordingly. You can also pass process in which case process.stdin and process.stdout will be used.

You can pipe() to and from the charm object you get back.

charm.reset()

Reset the entire screen, like the /usr/bin/reset command.

charm.destroy(), charm.end()

Emit an "end" event downstream.

charm.write(msg)

Pass along msg to the output stream.

charm.position(x, y)

Set the cursor position to the absolute coordinates x, y.

charm.position(cb)

Query the absolute cursor position from the input stream through the output stream (the shell does this automatically) and get the response back as cb(x, y).

charm.move(x, y)

Move the cursor position by the relative coordinates x, y.

charm.up(y)

Move the cursor up by y rows.

charm.down(y)

Move the cursor down by y rows.

charm.left(x)

Move the cursor left by x columns.

charm.right(x)

Move the cursor right by x columns.

charm.push(withAttributes=false)

Push the cursor state and optionally the attribute state.

charm.pop(withAttributes=false)

Pop the cursor state and optionally the attribute state.

charm.erase(s)

Erase a region defined by the string s.

s can be:

  • end - erase from the cursor to the end of the line
  • start - erase from the cursor to the start of the line
  • line - erase the current line
  • down - erase everything below the current line
  • up - erase everything above the current line
  • screen - erase the entire screen

charm.delete(mode, n)

Delete 'line' or 'char's. delete differs from erase because it does not write over the deleted characters with whitesapce, but instead removes the deleted space.

mode can be 'line' or 'char'. n is the number of items to be deleted. n must be a positive integer.

The cursor position is not updated.

charm.insert(mode, n)

Insert space into the terminal. insert is the opposite of delete, and the arguments are the same.

charm.display(attr)

Set the display mode with the string attr.

attr can be:

  • reset
  • bright
  • dim
  • underscore
  • blink
  • reverse
  • hidden

charm.foreground(color)

Set the foreground color with the string color, which can be:

  • red
  • yellow
  • green
  • blue
  • cyan
  • magenta
  • black
  • white

or color can be an integer from 0 to 255, inclusive.

charm.background(color)

Set the background color with the string color, which can be:

  • red
  • yellow
  • green
  • blue
  • cyan
  • magenta
  • black
  • white

or color can be an integer from 0 to 255, inclusive.

charm.cursor(visible)

Set the cursor visibility with a boolean visible.

install

With npm do:

npm install charm