Code Monkey home page Code Monkey logo

blessed's Introduction

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

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

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

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

Exemplary 3rd-party examples which use blessed,

Voltron is an extensible debugger UI toolkit written in Python

Voltron is an extensible debugger UI toolkit written in Python

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

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

GitHeat builds an interactive heatmap of git history.

GitHeat builds an interactive heatmap of git history.

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

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

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

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

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

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, 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('This is {under}underlined{normal}!'
      .format(under=underline, normal=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='')

blessed's People

Contributors

jquast avatar avylove avatar erikrose avatar dlax avatar thomasballinger avatar vitek avatar croepha avatar jwezel avatar msabramo avatar fishermans-friend avatar mwchase avatar neob91 avatar dflock avatar sbraz avatar lowks avatar maybetree avatar elmiko avatar numerlor avatar olen avatar stefanholek avatar liquiddandruff avatar vegarsti avatar pyfisch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.