Convert Figma logo to code with AI

jquast logoblessed

Blessed is an easy, practical library for making python terminal apps

1,251
75
1,251
21

Top Related Projects

50,391

Rich is a Python library for rich text and beautiful formatting in the terminal.

27,893

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.

2,875

Console user interface library for Python (official repo)

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations

11,405

Terminal UI library with rich, interactive widgets — written in Golang

Quick Overview

Blessed is a Python library that provides a curses-like interface for creating terminal applications with a text-based user interface (TUI). It offers a high-level API for building interactive console programs with features like widgets, layouts, and event handling.

Pros

  • Rich set of widgets and controls for creating complex TUIs
  • Cross-platform compatibility (Windows, macOS, Linux)
  • Supports both Python 2 and Python 3
  • Extensive documentation and examples

Cons

  • Learning curve for developers new to TUI programming
  • Limited graphical capabilities compared to GUI frameworks
  • Performance can be slower for very complex interfaces
  • Some reported issues with certain terminal emulators

Code Examples

Creating a simple window:

from blessed import Terminal

term = Terminal()

print(term.clear())
with term.fullscreen(), term.cbreak(), term.hidden_cursor():
    print(term.white_on_blue('Hello, Blessed!'))
    term.inkey()

Displaying colored text:

from blessed import Terminal

term = Terminal()

print(term.red('This is red text'))
print(term.bold_green('This is bold green text'))
print(term.underline_yellow('This is underlined yellow text'))

Creating a simple menu:

from blessed import Terminal

term = Terminal()

def display_menu():
    print(term.clear())
    print(term.bold('Menu:'))
    print('1. Option 1')
    print('2. Option 2')
    print('3. Exit')
    return term.inkey()

with term.fullscreen(), term.cbreak(), term.hidden_cursor():
    while True:
        key = display_menu()
        if key == '3':
            break
        elif key in ('1', '2'):
            print(f'You selected option {key}')
            term.inkey()

Getting Started

To get started with Blessed, first install it using pip:

pip install blessed

Then, you can create a simple application:

from blessed import Terminal

term = Terminal()

print(term.clear())
with term.fullscreen(), term.cbreak(), term.hidden_cursor():
    print(term.bold_green('Welcome to Blessed!'))
    print('Press any key to exit...')
    term.inkey()

This example creates a fullscreen terminal application that displays a welcome message and waits for a key press before exiting.

Competitor Comparisons

50,391

Rich is a Python library for rich text and beautiful formatting in the terminal.

Pros of Rich

  • More modern and actively maintained
  • Extensive features for rich text formatting, tables, and progress bars
  • Easier to use for complex console output

Cons of Rich

  • Larger library size and more dependencies
  • May be overkill for simpler terminal applications
  • Less focus on input handling and terminal control

Code Comparison

Rich:

from rich import print
print("[bold red]Hello[/bold red] [green]World[/green]!")

Blessed:

from blessed import Terminal
term = Terminal()
print(f"{term.bold_red}Hello{term.normal} {term.green}World{term.normal}!")

Rich provides a more intuitive syntax for styling text, while Blessed requires more explicit terminal control. Rich excels in creating complex, colorful output with less code, making it ideal for data presentation and logging. Blessed, on the other hand, offers finer control over terminal behavior and is better suited for interactive terminal applications.

Both libraries have their strengths, with Rich being more user-friendly for rich text output and Blessed providing more low-level terminal control. The choice between them depends on the specific requirements of your project.

27,893

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.

Pros of Textual

  • Modern, feature-rich framework for building Text User Interfaces (TUIs)
  • Supports reactive programming and async/await syntax
  • Extensive widget library and layout system

Cons of Textual

  • Steeper learning curve for beginners
  • Requires Python 3.7+ and additional dependencies

Code Comparison

Blessed example:

from blessed import Terminal

term = Terminal()
print(term.bold('Hello, World!'))
print(term.red_on_green('Colorful text'))

Textual example:

from textual.app import App, ComposeResult
from textual.widgets import Header, Footer

class MyApp(App):
    def compose(self) -> ComposeResult:
        yield Header()
        yield Footer()

if __name__ == "__main__":
    app = MyApp()
    app.run()

Key Differences

  • Blessed focuses on low-level terminal manipulation, while Textual provides a high-level framework for building complex TUIs
  • Textual offers a more structured approach with widgets and layouts, whereas Blessed gives direct control over terminal output
  • Blessed has broader compatibility with older Python versions and systems, while Textual leverages modern Python features
2,875

Console user interface library for Python (official repo)

Pros of urwid

  • More comprehensive widget toolkit with a wider range of UI elements
  • Better suited for complex, full-screen terminal applications
  • Supports both mouse and keyboard input handling

Cons of urwid

  • Steeper learning curve due to its more complex architecture
  • Less actively maintained compared to blessed
  • May be overkill for simpler terminal applications

Code Comparison

urwid example:

import urwid

def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()

palette = [('banner', 'black', 'light gray')]
txt = urwid.Text(('banner', u" Hello World "), align='center')
map1 = urwid.AttrMap(txt, 'banner')
loop = urwid.MainLoop(map1, palette, unhandled_input=exit_on_q)
loop.run()

blessed example:

from blessed import Terminal

term = Terminal()

print(term.home + term.clear + term.move_y(term.height // 2))
print(term.black_on_lightgray(term.center(" Hello World ")))
with term.cbreak(), term.hidden_cursor():
    term.inkey()

The urwid example demonstrates its widget-based approach, while the blessed example shows its simpler, more direct terminal manipulation. Urwid offers more structure but requires more setup, whereas blessed provides a more straightforward way to create basic terminal UIs.

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations

Pros of asciimatics

  • More comprehensive animation and effects capabilities
  • Built-in support for complex screen layouts and widgets
  • Includes a high-level API for creating interactive text user interfaces (TUIs)

Cons of asciimatics

  • Steeper learning curve due to more complex API
  • Potentially higher resource usage for advanced features
  • Less focus on low-level terminal handling compared to blessed

Code comparison

asciimatics example:

from asciimatics.screen import Screen
from asciimatics.scene import Scene
from asciimatics.effects import Cycle, Stars
from asciimatics.renderers import FigletText

def demo(screen):
    effects = [
        Cycle(screen, FigletText("ASCIIMATICS", font='big'), int(screen.height / 2 - 8)),
        Stars(screen, 200)
    ]
    screen.play([Scene(effects, 500)])

Screen.wrapper(demo)

blessed example:

from blessed import Terminal

term = Terminal()

print(term.home + term.clear + term.move_y(term.height // 2))
print(term.black_on_darkkhaki(term.center('Press any key to continue.')))

with term.cbreak(), term.hidden_cursor():
    term.inkey()
11,405

Terminal UI library with rich, interactive widgets — written in Golang

Pros of tview

  • Written in Go, offering better performance and concurrency support
  • More modern and actively maintained, with frequent updates
  • Simpler API and easier to get started with for Go developers

Cons of tview

  • Less feature-rich compared to blessed's extensive widget set
  • Limited cross-platform support (primarily focused on Unix-like systems)
  • Smaller community and fewer third-party extensions

Code Comparison

blessed (Python):

from blessed import Terminal

term = Terminal()
with term.fullscreen(), term.cbreak(), term.hidden_cursor():
    print(term.home + term.clear)
    print(term.green_on_black('Hello, World!'))

tview (Go):

package main

import (
    "github.com/rivo/tview"
)

func main() {
    app := tview.NewApplication()
    app.SetRoot(tview.NewTextView().SetText("Hello, World!"), true)
    app.Run()
}

Summary

tview is a modern, Go-based TUI library that offers excellent performance and a simpler API. It's ideal for Go developers looking for a straightforward solution. However, blessed provides a more comprehensive set of widgets and better cross-platform support, making it a solid choice for complex Python-based TUI applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

| |pypi_downloads| |codecov| |windows| |linux| |mac| |bsd|

Introduction

Blessed is an easy, practical library for making terminal apps, by providing an elegant, well-documented interface to Colors_, Keyboard_ input, and screen position and Location_ capabilities.

.. code-block:: python

from blessed import Terminal

term = Terminal()

print(term.home + term.clear + term.move_y(term.height // 2))
print(term.black_on_darkkhaki(term.center('press any key to continue.')))

with term.cbreak(), term.hidden_cursor():
    inp = term.inkey()

print(term.move_down(2) + 'You pressed ' + term.bold(repr(inp)))

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/demo_basic_intro.gif :alt: Animation of running the code example

It's meant to be fun and easy, to do basic terminal graphics and styling with Python using blessed. Terminal_ is the only class you need to import and the only object you should need for Terminal capabilities.

Whether you want to improve CLI apps with colors, or make fullscreen applications or games, blessed should help get you started quickly. Your users will love it because it works on Windows, Mac, and Linux, and you will love it because it has plenty of documentation and examples!

Full documentation at https://blessed.readthedocs.io/en/latest/

Examples

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/blessed_demo_intro.gif :alt: Animations of x11-colorpicker.py, bounce.py, worms.py, and plasma.py

x11-colorpicker.py_, bounce.py_, worms.py_, and plasma.py_, from our repository.

Exemplary 3rd-party examples which use blessed,

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/demo_3rdparty_voltron.png :alt: Screenshot of 'Voltron' (By the author of Voltron, from their README).

Voltron_ is an extensible debugger UI toolkit written in Python

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/demo_3rdparty_cursewords.gif :alt: Animation of 'cursewords' (By the author of cursewords, from their README).

cursewords_ is "graphical" command line program for solving crossword puzzles in the terminal.

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/demo_3rdparty_githeat.gif :alt: Animation of 'githeat.interactive', using blessed repository at the time of capture.

GitHeat_ builds an interactive heatmap of git history.

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/demo_3rdparty_dashing.gif :alt: Animations from 'Dashing' (By the author of Dashing, from their README)

Dashing_ is a library to quickly create terminal-based dashboards.

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/demo_3rdparty_enlighten.gif :alt: Animations from 'Enlighten' (By the author of Enlighten, from their README)

Enlighten_ is a console progress bar library that allows simultaneous output without redirection.

.. figure:: https://dxtz6bzwq9sxx.cloudfront.net/blessed_3rdparty_macht.gif :alt: Demonstration of 'macht', a 2048 clone

macht_ is a clone of the (briefly popular) puzzle game, 2048.

Requirements

Blessed works with Windows, Mac, Linux, and BSD's, on Python 2.7, 3.5+.

Brief Overview

Blessed is more than just a Python wrapper around curses_:

  • Styles_, Colors_, and maybe a little positioning without necessarily clearing the whole screen first.
  • Works great with Python's new f-strings_ or any other kind of string formatting.
  • Provides up-to-the-moment Location_ and terminal height and width, so you can respond to terminal size changes.
  • Avoids making a mess if the output gets piped to a non-terminal, you can output sequences to any file-like object such as StringIO, files, pipes or sockets.
  • Uses terminfo(5)_ so it works with any terminal type and capability: No more C-like calls to tigetstr_ and tparm_.
  • Non-obtrusive calls to only the capabilities database ensures that you are free to mix and match with calls to any other curses application code or library you like.
  • Provides context managers Terminal.fullscreen()_ and Terminal.hidden_cursor()_ to safely express terminal modes, curses development will no longer fudge up your shell.
  • Act intelligently when somebody redirects your output to a file, omitting all of the special sequences colors, but still containing all of the text.

Blessed is a fork of blessings <https://github.com/erikrose/blessings>_, which does all of the same above with the same API, as well as following enhancements:

  • Windows support, new since Dec. 2019!
  • Dead-simple keyboard handling: safely decoding unicode input in your system's preferred locale and supports application/arrow keys.
  • 24-bit color support, using Terminal.color_rgb()_ and Terminal.on_color_rgb()_ and all X11 Colors_ by name, and not by number.
  • Determine cursor location using Terminal.get_location(), enter key-at-a-time input mode using Terminal.cbreak() or Terminal.raw()_ context managers, and read timed key presses using Terminal.inkey()_.
  • Allows the printable length of strings that contain sequences to be determined by Terminal.length(), supporting additional methods Terminal.wrap() and Terminal.center(), terminal-aware variants of the built-in function textwrap.wrap() and method str.center()_, respectively.
  • Allows sequences to be removed from strings that contain them, using Terminal.strip_seqs()_ or sequences and whitespace using Terminal.strip()_.

Before And After

With the built-in curses_ module, this is how you would typically print some underlined text at the bottom of the screen:

.. code-block:: python

from curses import tigetstr, setupterm, tparm
from fcntl import ioctl
from os import isatty
import struct
import sys
from termios import TIOCGWINSZ

# If we want to tolerate having our output piped to other commands or
# files without crashing, we need to do all this branching:
if hasattr(sys.stdout, 'fileno') and isatty(sys.stdout.fileno()):
    setupterm()
    sc = tigetstr('sc')
    cup = tigetstr('cup')
    rc = tigetstr('rc')
    underline = tigetstr('smul')
    normal = tigetstr('sgr0')
else:
    sc = cup = rc = underline = normal = ''

# Save cursor position.
print(sc)

if cup:
    # tigetnum('lines') doesn't always update promptly, hence this:
    height = struct.unpack('hhhh', ioctl(0, TIOCGWINSZ, '\000' * 8))[0]

    # Move cursor to bottom.
    print(tparm(cup, height - 1, 0))

print('This is {under}underlined{normal}!'
      .format(under=underline, normal=normal))

# Restore cursor position.
print(rc)

The same program with Blessed is simply:

.. code-block:: python

from blessed import Terminal

term = Terminal()
with term.location(0, term.height - 1):
    print('This is ' + term.underline('underlined') + '!', end='')

.. _curses: https://docs.python.org/3/library/curses.html .. _tigetstr: http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/tigetstr.3 .. _tparm: http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/tparm.3 .. _terminfo(5): https://invisible-island.net/ncurses/man/terminfo.5.html .. _str.center(): https://docs.python.org/3/library/stdtypes.html#str.center .. _textwrap.wrap(): https://docs.python.org/3/library/textwrap.html#textwrap.wrap .. _Terminal: https://blessed.readthedocs.io/en/stable/terminal.html .. _Terminal.fullscreen(): https://blessed.readthedocs.io/en/latest/api/terminal.html#blessed.terminal.Terminal.fullscreen .. _Terminal.get_location(): https://blessed.readthedocs.io/en/latest/location.html#finding-the-cursor .. _Terminal.color_rgb(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.color_rgb .. _Terminal.hidden_cursor(): https://blessed.readthedocs.io/en/latest/api/terminal.html#blessed.terminal.Terminal.hidden_cursor .. _Terminal.on_color_rgb(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.on_color_rgb .. _Terminal.length(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.length .. _Terminal.strip(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.strip .. _Terminal.rstrip(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.rstrip .. _Terminal.lstrip(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.lstrip .. _Terminal.strip_seqs(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.strip_seqs .. _Terminal.wrap(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.wrap .. _Terminal.center(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.center .. _Terminal.rjust(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.rjust .. _Terminal.ljust(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.ljust .. _Terminal.cbreak(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.cbreak .. _Terminal.raw(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.raw .. _Terminal.inkey(): https://blessed.readthedocs.io/en/stable/api/terminal.html#blessed.terminal.Terminal.inkey .. _Colors: https://blessed.readthedocs.io/en/stable/colors.html .. _Styles: https://blessed.readthedocs.io/en/stable/terminal.html#styles .. _Location: https://blessed.readthedocs.io/en/stable/location.html .. _Keyboard: https://blessed.readthedocs.io/en/stable/keyboard.html .. _Examples: https://blessed.readthedocs.io/en/stable/examples.html .. _x11-colorpicker.py: https://blessed.readthedocs.io/en/stable/examples.html#x11-colorpicker-py .. _bounce.py: https://blessed.readthedocs.io/en/stable/examples.html#bounce-py .. _worms.py: https://blessed.readthedocs.io/en/stable/examples.html#worms-py .. _plasma.py: https://blessed.readthedocs.io/en/stable/examples.html#plasma-py .. _Voltron: https://github.com/snare/voltron .. _cursewords: https://github.com/thisisparker/cursewords .. _GitHeat: https://github.com/AmmsA/Githeat .. _Dashing: https://github.com/FedericoCeratto/dashing .. _Enlighten: https://github.com/Rockhopper-Technologies/enlighten .. _macht: https://github.com/rolfmorel/macht .. _f-strings: https://docs.python.org/3/reference/lexical_analysis.html#f-strings .. |pypi_downloads| image:: https://img.shields.io/pypi/dm/blessed.svg?logo=pypi :alt: Downloads :target: https://pypi.org/project/blessed/ .. |codecov| image:: https://codecov.io/gh/jquast/blessed/branch/master/graph/badge.svg :alt: codecov.io Code Coverage :target: https://codecov.io/gh/jquast/blessed/ .. |linux| image:: https://img.shields.io/badge/Linux-yes-success?logo=linux :alt: Linux supported .. |windows| image:: https://img.shields.io/badge/Windows-yes-success?logo=windows :alt: Windows supported .. |mac| image:: https://img.shields.io/badge/MacOS-yes-success?logo=apple :alt: MacOS supported .. |bsd| image:: https://img.shields.io/badge/BSD-yes-success?logo=freebsd :alt: BSD supported