Examples ======== A few programs are provided with blessed to help interactively test the various API features, but also serve as examples of using blessed to develop applications. These examples are not distributed with the package -- they are only available in the github repository. You can retrieve them by cloning the repository, or simply downloading the "raw" file link. .. note: animations are made using the following CLI example: ffmpeg -i blessed_demo_6.mov -pix_fmt rgb8 -r 24 -f gif - \ | gifsicle --optimize=3 --delay=3 --resize-width 800 > blessed_demo_6.gif .. figure:: https://dxtz6bzwq9sxx.cloudfront.net/blessed_demo_intro.gif :alt: Animations of x11-colorpicker.py, bounce.py, worms.py, and plasma.py :ref:`x11-colorpicker.py`, :ref:`bounce.py`, :ref:`worms.py`, and :ref:`plasma.py`. .. _bounce.py: bounce.py --------- https://github.com/jquast/blessed/blob/master/bin/bounce.py This is a very brief, basic primitive non-interactive version of a "classic tennis" video game. It demonstrates basic timed refresh of a bouncing terminal cell. .. _cnn.py: cellestial.py ------------- https://github.com/jquast/blessed/blob/master/bin/cellestial.py .. note: animation using 3-pass pipeline, ffmpeg -i input.mp4 -vf "fps=12,scale=640:-1:flags=lanczos,palettegen" palette.png ffmpeg -i input.mp4 -i palette.png -f gif output.gif \ -lavfi "fps=12,scale=640:-1:flags=lanczos[x];[x][1:v]paletteuse" gifsicle --optimize=3 --lossy=50 output.gif > final.gif .. figure:: https://dxtz6bzwq9sxx.cloudfront.net/demo_cellestial.gif This is an Elementary Cellular Automata browser, of the visualizations made popular by Stephen Wolfram. A popular "rule 30" is first displayed with random initial values and can be manipulated by hotkeys, or automatic viewing with arguments, :: bin/cellestial.py --autoscroll --fullscreen cnn.py ------------------- https://github.com/jquast/blessed/blob/master/bin/cnn.py This program uses 3rd-party BeautifulSoup and requests library to fetch the cnn website and display news article titles using the :meth:`~.Terminal.link` method, so that they may be clicked. .. _detect-multibyte.py: detect-multibyte.py ------------------- https://github.com/jquast/blessed/blob/master/bin/detect-multibyte.py This program also demonstrates how the :meth:`~.get_location` method can be used to reliably test whether the terminal emulator supports utf-8 or other multibyte encoding, by rendering multibyte characters and measuring the change in cursor location. .. _editor.py: editor.py --------- https://github.com/jquast/blessed/blob/master/bin/editor.py This program demonstrates using the directional keys and noecho input mode. It acts as a (very dumb) fullscreen editor, with support for saving a file, as well as including a rudimentary line-editor. .. _keymatrix.py: keymatrix.py ------------ https://github.com/jquast/blessed/blob/master/bin/keymatrix.py This program displays a special REPL for using :meth:`~.inkey` and displaying the returned :class:`~.Keystroke` events, their names, events, and values. This also provides an interface for toggling special modes, such as any of the supported :ref:`kitty` Keyboard Protocols. .. _on_resize.py: on_resize.py ------------ https://github.com/jquast/blessed/blob/master/bin/on_resize.py This program uses in-band resize notifications when available, with a SIGWINCH signal handler as a fallback on Unix. On Windows, native console resize events are used automatically. This demonstrates how a program can react to screen resize events cross-platform. .. _plasma.py: plasma.py --------- https://github.com/jquast/blessed/blob/master/bin/plasma.py This demonstrates using only :meth:`~.Terminal.on_color_rgb` and the built-in :mod:`colorsys` module to quickly display all of the colors of a rainbow in a classic demoscene `plasma effect `_ .. _progress_bar.py: progress_bar.py --------------- https://github.com/jquast/blessed/blob/master/bin/progress_bar.py .. figure:: https://dxtz6bzwq9sxx.cloudfront.net/blessed_progress_bar.gif This program demonstrates a simple ascii progress bar along with the ``OSC 9;4`` progress bar notification sequence using :meth:`~.Terminal.progress_bar`. .. _resize.py: resize.py --------- https://github.com/jquast/blessed/blob/master/bin/resize.py This program demonstrates the :meth:`~.get_location` method, behaving similar to `resize(1) `_ : set environment and terminal settings to current window size. The window size is determined by eliciting an answerback sequence from the connecting terminal emulator. .. _tprint.py: tprint.py --------- https://github.com/jquast/blessed/blob/master/bin/tprint.py This program demonstrates how users may customize FormattingString styles. Accepting a string style, such as "bold" or "bright_red" as the first argument, all subsequent arguments are displayed by the given style. This shows how a program could provide user-customizable compound formatting names to configure a program's styling. .. _worms.py: worms.py -------- https://github.com/jquast/blessed/blob/master/bin/worms.py This program demonstrates how an interactive game could be made with blessed. It is similar to `NIBBLES.BAS `_ or "snake" of early mobile platforms. .. _x11-colorpicker.py: x11_colorpicker.py ------------------ https://github.com/jquast/blessed/blob/master/bin/x11_colorpicker.py This program shows all of the X11 colors, demonstrates a basic keyboard-interactive program and color selection, but is also a useful utility to pick colors! .. _display-modes.py: display-modes.py ---------------- https://github.com/jquast/blessed/blob/master/bin/display-modes.py Detect and report all known DEC Private Modes supported by the Terminal and display a report. .. _display-unicode.py: display-unicode.py ------------------ https://github.com/jquast/blessed/blob/master/bin/display-unicode.py Basic Unicode detection support, for Wide characters, Emojis with ZWJ, Emojis with VS-16, and Ambiguous Width as Wide or Narrow by writing effects to the screen and measuring the cursor position. .. _strip.py: strip.py ------------- https://github.com/jquast/blessed/blob/master/bin/strip.py This wrapper of the :meth:`~Terminal.strip_seqs` method reads text from standard input, "strips" away all known output sequences and writes the result to stdout. .. _bin/mouse_paint.py: mouse_paint.py -------------- https://github.com/jquast/blessed/blob/master/bin/mouse_paint.py .. figure:: https://dxtz6bzwq9sxx.cloudfront.net/mouse_paint.gif This is a basic "paint" program using :ref:`mouse input` with the :ref:`report_motion` feature. .. _scroll_region.py: scroll_region.py ---------------- https://github.com/jquast/blessed/blob/master/bin/scroll_region.py This program demonstrates the :meth:`~.Terminal.scroll_region` context manager to create a scrollable area with a fixed header and status bar. .. _text_sizing_protocol.py: text_sizing_protocol.py ----------------------- https://github.com/jquast/blessed/blob/master/bin/text_sizing_protocol.py This program demonstrates the various uses of :meth:`~.Terminal.text_sized`, the ``OSC 66`` `kitty text sizing protocol `_. .. figure:: https://dxtz6bzwq9sxx.cloudfront.net/blessed_text_sizing_demo.png .. _scroller.py: scroller.py ----------- https://github.com/jquast/blessed/blob/master/bin/scroller.py .. figure:: https://dxtz6bzwq9sxx.cloudfront.net/blessed_text_sizing.gif A classic sine-wave "demoscene" text scroller effect that uses :meth:`~.Terminal.text_sized`, the ``OSC 66`` `kitty text sizing protocol `_.