Package: blessed
IntroductionBlessed is an easy, practicallibraryfor makingterminalapps, by providing an elegant,
well-documented interface toColors,Keyboardinput, and screen position andLocationcapabilities.fromblessedimportTerminalterm=Terminal()print(term.home+term.clear+term.move_y(term.height//2))print(term.black_on_darkkhaki(term.center('press any key to continue.')))withterm.cbreak(),term.hidden_cursor():inp=term.inkey()print(term.move_down(2)+'You pressed '+term.bold(repr(inp)))It’s meant to befunandeasy, to do basic terminal graphics and styling with Python usingblessed.Terminalis 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,blessedshould 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 athttps://blessed.readthedocs.io/en/latest/Examplesx11-colorpicker.py,bounce.py,worms.py, andplasma.py, from our repository.Exemplary 3rd-party examples which useblessed,Voltronis an extensible debugger UI toolkit written in Pythoncursewordsis “graphical” command line program for solving crossword puzzles in the terminal.GitHeatbuilds an interactive heatmap of git history.Dashingis a library to quickly create terminal-based dashboards.Enlightenis a console progress bar library that allows simultaneous output without redirection.machtis a clone of the (briefly popular) puzzle game, 2048.RequirementsBlessedworks with Windows, Mac, Linux, and BSD’s, on Python 2.7, 3.4, 3.5, 3.6, 3.7, and 3.8.Brief OverviewBlessedis more than just a Python wrapper aroundcurses:Styles,Colors, and maybe a little positioning without necessarily clearing the whole screen
first.Works great with Python’s newf-stringsor any other kind of string formatting.Provides up-to-the-momentLocationand 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 asStringIO, files, pipes or sockets.Usesterminfo(5)so it works with any terminal type and capability: No more C-like calls totigetstrandtparm.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 managersTerminal.fullscreen()andTerminal.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.Blessedis a fork ofblessings, which does all of
the same above with the same API, as well as followingenhancements: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, usingTerminal.color_rgb()andTerminal.on_color_rgb()and all X11Colorsby name, and not by number.Determine cursor location usingTerminal.get_location(), enter key-at-a-time input mode usingTerminal.cbreak()orTerminal.raw()context managers, and read timed key presses usingTerminal.inkey().Allows theprintable lengthof strings that contain sequences to be determined byTerminal.length(), supporting additional methodsTerminal.wrap()andTerminal.center(),
terminal-aware variants of the built-in functiontextwrap.wrap()and methodstr.center(),
respectively.Allows sequences to be removed from strings that contain them, usingTerminal.strip_seqs()or
sequences and whitespace usingTerminal.strip().Before And AfterWith the built-incursesmodule, this is how you would typically
print some underlined text at the bottom of the screen:fromcursesimporttigetstr,setupterm,tparmfromfcntlimportioctlfromosimportisattyimportstructimportsysfromtermiosimportTIOCGWINSZ# If we want to tolerate having our output piped to other commands or# files without crashing, we need to do all this branching:ifhasattr(sys.stdout,'fileno')andisatty(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)ifcup:# 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 withBlessedis simply:fromblessedimportTerminalterm=Terminal()withterm.location(0,term.height-1):print('This is '+term.underline('underlined')+'!',end='')