Skip to main content

Easy, practical library for making terminal apps, by providing an elegant, well-documented interface to Colors, Keyboard input, and screen Positioning capabilities.

Project description

Downloads codecov.io Code Coverage Windows supported Linux supported MacOS supported BSD supported

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.

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)))
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

animations of x11-colorpicker.py, bounce.py, worms.py, and plasma.py

x11-colorpicker.py, bounce.py, worms.py, and plasma.py demonstration programs from our repository.

colored and dimensional cellular automata in scrolling animation

cellestial.py demonstration program from our repository.

Exemplary 3rd-party examples which use blessed,

Screenshot of 'Voltron' (By the author of Voltron, from their README).

Voltron is an extensible debugger UI toolkit written in Python

Animation of 'cursewords' (By the author of cursewords, from their README).

cursewords is “graphical” command line program for solving crossword puzzles in the terminal.

Animations from 'Dashing' (By the author of Dashing, from their README)

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

Animations from 'Enlighten' (By the author of Enlighten, from their README)

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

Requirements

Blessed works with Windows, Mac, Linux, and BSD’s, on Python 3.7+.

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, which does all of the same above with the same API, as well as following enhancements:

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:

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(f'This is {underline}underlined{normal}!')

# Restore cursor position.
print(rc)

The same program with Blessed is simply:

from blessed import Terminal

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blessed-1.30.0.tar.gz (13.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blessed-1.30.0-py3-none-any.whl (98.4 kB view details)

Uploaded Python 3

File details

Details for the file blessed-1.30.0.tar.gz.

File metadata

  • Download URL: blessed-1.30.0.tar.gz
  • Upload date:
  • Size: 13.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.15.0a5

File hashes

Hashes for blessed-1.30.0.tar.gz
Algorithm Hash digest
SHA256 4d547019d7b40fc5420ea2ba2bc180fdccc31d6715298e2b49ffa7b020d44667
MD5 5c7aee07850419cbb76260edd8d5985f
BLAKE2b-256 dd19e926a0dbbf93c7aeb15d4dfff0d0e3de02653b3ba540b687307d0819c1ff

See more details on using hashes here.

File details

Details for the file blessed-1.30.0-py3-none-any.whl.

File metadata

  • Download URL: blessed-1.30.0-py3-none-any.whl
  • Upload date:
  • Size: 98.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.15.0a5

File hashes

Hashes for blessed-1.30.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4061a9f10dd22798716c2548ba36385af6a29d856c897f367c6ccc927e0b3a5a
MD5 c5dbfd81276f2d43a0bd2501addb0d19
BLAKE2b-256 64b08d87c7c8015ce8d4b2c5ee7a82a1d955f10138322c4f0cb387d7d2c1b2e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page