Python3 library for multimedia functions at the command terminal

Overview

TERMINEDIA

This is a Python library allowing using a text-terminal as a low-resolution graphics output, along with keyboard realtime reading, and a couple utilities enough to enable using a text terminal to run simple 2D games or simply rich terminal apps.

The "noveau" factor is that it uses Unicode quarter-character block combinations to effectivelly enable 1/4 character "pixels" in the terminal. It also makes use of 24bit "true" color for text, not limiting itself to the 80's 8 color palette for the terminal.

The development version allows loading image files and displaying those as colored block chars on the terminal, several terminal-font text effects, and rendering big-text, 4 or 8 characters tall, by rendering built-in fonts as images using block characters.

It is designed as a library, providing a discoverable and easy to use API for drawing, and upon install a few example scripts will be imediately available as stand-alone scripts with the "terminedia-" prefix.

The idea is to keep this as a lightweight install - with as little dependencies as possible.

Usage

Although targeted for programatic use, after install a few example programs exercising the library capabilities are made available in the active Python environment. Try one of several "terminedia-xxxxx" scripts installed, such as "terminedia-image" and "terminedia-snake"

Some of the features are as easy to use as the print function from Python itself:

Demonstration of terminedia.print

Other, like the drawing API which emulates pixels with unicode block characters require a couple more calls:

Messy screenshot with current capabilities Graph plot output example Image rendering and big-text

Documentation

Check the in progress documentation at: https://terminedia.readthedocs.io/en/latest/

(nb. that documentation is currently for the 0.2 version, available from pypi. The project's capabilities evolved far beyond whats is in there, but docs are still missing - the "TODO.txt" file lists implemented features or fixes (marked with a "V") and a loose roadmap. Although for useage and documentation one has to rely on the doc-strings)

Also, the examples folder have concrete snippets and some stress-testing code. The examples were moved into the main package code, and granted stand-alone scripts status when the package is pip-installed.

After install, try calling any of the "terminedia-" scripts made available to check the output.

Although incipient in options, some of these example scripts can work as command line tools. For example terminedia-image will downscale and display an image file in the terminal.

Note that the default pip install won't bring PIL, which results in limited image support - use pip install terminedia[images], or simply install PIL directly with pip install pillow, to be able to load arbitrary image files.

Compatibility

Preliminary Windows support - by using the Colorama Python package, with proper fonts configuration on the terminal, it is possible to experiment most of terminedia´s capabilities (the terminedia-snake example works). There is still work to be done, but for a better experience under Windows install the CMDER console emulator and the UNSCII fonts for rendering pseudographics (links in the FRIENDS.md file)

On Linux and other posix systems, Terminedia relies on ANSI scape sequences for all terminal manipulation. It should work in most Linux and Mac OS terminal applications (including non-X11, "native" terminals on Linux)

The output result will vary according to the terminal and font used - a nice experience can be achieved with the "Terminus" font, specially if one is using the Braille characters for drawing.

There is also an HTML backend that can output programatically created ASCII art to an HTML file, formatted with mono-spaced fonts inside a div element. The "terminedia-image" example program makes use of this feature.

License

Terminedia is licensed under GNU's LGPL 3.0 or later, meaning you are free to use it in whatver project you want, comercial or not, private or not - you are only required to contribute back any enhancements you make to this library itself. For details, please read acompanining "LICENSE" file.

Comments
  • Add support for 1/6 block characters

    Add support for 1/6 block characters

    Unicode 13.0 added 1/6 block characters at 1FB00-1FB3B in the Characters for Legacy Computing block. This would be a nice complement to the 1/4, 1/2, and 1/8 (Braille) modes.

    enhancement 
    opened by RebeccaRGB 7
  • [Question] How to limit size of image?

    [Question] How to limit size of image?

    Trying to use this library to convert images to block characters. So far it's working great.

    One point of confusion for me is how to control the size of the output. For context, I'm trying to preserve the ratio of the image, but constrain either its height or width so that it can fit within an arbitrary space.

    Here I attempt—and fail—to read in an image and constrain its output to 30 characters in width.

    import io
    
    import terminedia
    from PIL import Image
    
    screen = terminedia.Screen(backend="ANSI")
    resolution = "square"
    size = terminedia.V2(x=30, y=30)
    
    image = Image.open("Ent_Steven-Universe_SOCIAL.jpeg")
    img = terminedia.shape(
        image,
        size=size,
        promote=True,
        resolution=resolution,
    )
    output = io.StringIO()
    img.render(output=output, backend="ANSI")
    
    print(output.getvalue())
    print("-" * 30)  # Ruler to visualize 30 units across 
    
    Screen Shot 2021-08-20 at 8 08 15 PM

    It renders perfectly, but is wider than 30 characters.

    I'm trying to understand:

    1. What does the size argument actually do? The resulting image is not 30x30.
    2. What's the best way to accomplish my goal—preserving the original aspect ratio of an image while restraining the height and the width to be within a certain number of characters?

    (Again) thanks for the project!

    bug 
    opened by paw-lu 4
  • `terminedia-plot` output garbled for almost every function except the default example

    `terminedia-plot` output garbled for almost every function except the default example

    terminedia-plot without any parameters works just fine, as in the demo screenshot.

    However, trying to provide any other function results a semi garbled output with many fragments of escape characters:

    $ terminedia-plot --func x
    

    image

    I've used the latest version this repo: pip install git+https://github.com/jsbueno/terminedia.

    opened by vytas7 3
  • `redirected stdin is pseudofile, has no fileno()`

    `redirected stdin is pseudofile, has no fileno()`

    When trying to test this libary via pytest, an exception is raised: redirected stdin is pseudofile, has no fileno(). This is due to this line:

    https://github.com/jsbueno/terminedia/blob/96f44a67dd97acfd49062c7be30057c6767b2de6/terminedia/terminal.py#L92

    opened by paw-lu 3
  • `terminedia-plot` wrong axis position and selection

    `terminedia-plot` wrong axis position and selection

    It seems that terminedia-plot plots points at a wrong y coordinate.

    For instance, terminedia-plot --func x yields: image From the graph, I'm getting an impression that f(0.01) ≈ 2, which is obviously not even remotely true for f(x) = x.

    (One can also see a minor cosmetic issue, a data point seems to be missing on the graph.)

    terminedia-plot --func x*x seems to provide a roughly correct data point for (0, 0), but the choice for y range seems to be quite odd: image

    opened by vytas7 2
  • Fix display and flow of larger than 1-unit width characters

    Fix display and flow of larger than 1-unit width characters

    When rendering rich-text:

    • correctly detect if final transformed character takes more than 1 cell width after applying effects, and correctly use 2 cells for character [WIP] - retrieve last-character width after calling Shape.__setitem__ - check that last-character width works with multiple-character grapheme - allow Shape.__setitem__ to set character to the left of given position if a special attribute is set in the context (and maybe if direction==Right) - Double check and maybe extend role of "Continuation" sentinel character code (used in Shape): - Does it make sense for "Continuation" to indicate the "come from" direction, and allow continuation for custom double-height characters? - implement a dry-run extents call in TextPlane
    enhancement 
    opened by jsbueno 2
  • Double-width character printing do not trigger Marks at a position if it is skipped as character-continuation

    Double-width character printing do not trigger Marks at a position if it is skipped as character-continuation

    When printing text with the text-planes mechanism, one can embed a Mark (an object similiar to an HTML tag to dictate attributes to the text from that point on), fixed on a TextPlane position - for example, doing:

    screen.text[1].marks[5,0] = TM.Mark(attribute{"foreground"}: "red') and then rendering some text there with screen.text[1][0,0] = "ABCDEFGH" - will cause the letters EFGH (col 5 and onward) to appear red. However if the characters being printed are double-width - and column 5 ends up on the continuation of a character that started on the position (4, 0) -, the mark at (5, 0) is never "seem" by the rendering mechanim.

    Fixing strategy:

    • Anottate in an instance attribute on terminedia.text.style.StyledSequence when a double-character was printed (it will be "seen" on the .render method - right now at line 309.) -
    • Consume this attribute when checking for marks for the next character: pass it as an extra parameter to MarkMap.get_full done in the ._process_to method (the MarkMap instance is the .marks attribute in the StyledSequence instance)
    • on MarkMap.get_full include the "skipped location" in the mark-search, and return it in the return.
    opened by jsbueno 1
  • [FORMATTING] Applied black to a few files

    [FORMATTING] Applied black to a few files

    I chose not to apply black to all the lib, bc the changes would be huge. So I took a few files, applied black, checked the changes and made some tests with (and ran some examples).

    opened by chicao 1
  • Gradient transformers

    Gradient transformers

    #pybr2020 #sprints

    This was made in the Sprinting session of the PythonBrasi 2020 confence - Features developed in an hours long pair-programming session with Celestino Gomes - @tinogomes

    Add features to GradientTransforms and Gradients - making them more flexible and easier to use.

    opened by jsbueno 0
  • Text features

    Text features

    First stage of new Text features -

    This branch so far had:

    - Refactor 'text.py' into directory:[V]
        - separate 'font' code into text/fonts.py [V]
        - text_planes/big text into text/planes.py (V)
        - file with text utilities for parsing/rendering text:
            - split string into units containing a single grapheme, by grouping "combining characters" together (V)
            - Refactor code to have a core to be used by  backend.print, screen.print, text.at, shape.print [V]
    - Make assignment of string to shape or text area cell spread the text across as many cells as needed:[V]
        - correctly detect combining characters so that combined characters live on the same cell (V)
    - create markup language for embedding context changing directives inside a single string:[V]
        - make it usable by assignment, `text[x].print` and `at` methods
        - BUG: when rendering spaces from text-planes, attributes (like background) are not updated (V):
                - fixed by sprite transparency handling implementation.[V]
        - Implement a way to "stream" rich text inside these text-plane containers [WIP]:
            - TM.text.style.StyledSequence is the class used for that [v]
            - Streamed text should allow marks for changing style (color, bg, effects, direction, position)[v]
                - accept tokens in embedded square-brackets in the string ex.: "abc[color:red]def[V]
                - Accept absolute/relative movement with "[+x,+y]" tokens embedded in the string (and work as "portals")[V]
                - allow for 'pop last parameter of this type' tokens ([/color], [/effects])[V]
                - allow for default colors with [color:default] (V) (but check default-color bug)
            - Allow a call to MLToken.parse to be passed a transformers-mapping, and us it as a source for
                    transformers objects in the  markup [transformer:...] elements [wip]
    
    - create aliased string names for the text[...] text planes [V]
    - Add tests to terminedia-planes [WIP]:
        - Avoid creating a new "Text" instance on each text-plane access![V]
        - Tests for styling bases classes in progress - testing attribute changing and position
    
    opened by jsbueno 0
  • Braille resolution refactor

    Braille resolution refactor

    Refactor sub-pixel logic, hard coded to 1/4 block chars, and add Braille characters (which allow 2x4 subpixels per block) as an alternative high-resolution plane.

    St

    opened by jsbueno 0
  • Include Unicode transform effects for varios 'Mathematical *

    Include Unicode transform effects for varios 'Mathematical *" unicode symbols

    Effects currently cnatransfoprm ASCII to "mathematical sans-serif bold *" and "mathematical double-struck" however there are all these letter-families for mathematical symbols in unicode:

    {'MATHEMATICAL BOLD': ['CAPITAL', 'SMALL', 'DIGIT'], 'MATHEMATICAL ITALIC': ['CAPITAL', 'SMALL'], 'MATHEMATICAL BOLD ITALIC': ['CAPITAL', 'SMALL'], 'MATHEMATICAL SCRIPT': ['SMALL'], 'MATHEMATICAL BOLD SCRIPT': ['CAPITAL', 'SMALL'], 'MATHEMATICAL FRAKTUR': ['CAPITAL', 'SMALL'], 'MATHEMATICAL DOUBLE-STRUCK': ['CAPITAL', 'SMALL', 'DIGIT'], 'MATHEMATICAL BOLD FRAKTUR': ['CAPITAL', 'SMALL'], 'MATHEMATICAL SANS-SERIF': ['CAPITAL', 'SMALL', 'DIGIT'], 'MATHEMATICAL SANS-SERIF BOLD': ['CAPITAL', 'SMALL', 'DIGIT'], 'MATHEMATICAL SANS-SERIF ITALIC': ['CAPITAL', 'SMALL'], 'MATHEMATICAL SANS-SERIF BOLD ITALIC': ['CAPITAL', 'SMALL'], 'MATHEMATICAL MONOSPACE': ['CAPITAL', 'SMALL', 'DIGIT']}

    more:

    • LATIN LETTER SMALL CAPITAL
    opened by jsbueno 0
  • Not usable on Windows due to `fcntl`

    Not usable on Windows due to `fcntl`

    opened by paw-lu 2
  • Performance game changing refactor

    Performance game changing refactor

    I just outline thse ideas in text - for steps that could take the project to actually feature "animation speed" for most effects. These were also commited in the "TODO.txt" file:

    • BACKENDS:

      • "The One" optmization: (maybe sprint around Christmas 2020)
        • Benchmark complex rendering (with 2 more levels of sprites and 4+ levels of transformers + text effects / frame)
        • add consistent benchmarking as a script in tools
        • then proceed to revamp everything:
          • refactor as many pixel by pixel function calls to a way that can be pre-set to a retangular area and then used as a generator:
            • Rendering backend: should get a "shape", a rect and a file stream, and usr a method on the shape to setup pixel yielding for that area, and use a single "for" block for rendering.
            • (final backend rendering method should be contained in a single function, with no extra calls)
            • shapes:
              • have a method to setup an area, that will, in turn, setup areas in it's text planes, and sprites
              • use generator semantics with "send" to the sprites (so that transformers with any kind of transparency can have their data).
              • optimize storage to use arrays instead of lists. (no need to numpy - just arrays of 4 bytes and a fast way to interpret those as a single UTF-32 unicode codepoint string)
            • transformers:
              • benchmark to check if this is worth the effort:
              • (optional) have a decorator that could work on bytecode level to upgrade a normal function-based transformer to a generator: - insert a pos, pixel, source, ... = yield mydata; char, foreground, background, effects = pixel line at the start of the bytecode; - replace all "return" values for a "bytecode jump" to the line with the "yield". - since the transformer-generator will be garbage colector once its area-blitting is over, there is no problem that such a transformer becomes an "infinite size" generator
            • text-planes and text-style:
              • have blitted text-styles in teh text-plane have the combined (text-plane positional + string positional) Marks in place, ready to work as a generator for all "full pixels". Updating the shape will trigger the rendering for text planes
                • it is possible that this is hard to do for text-planes of more than one block per character (big-text): if that is the case, just leave big-text rendering as eager (as they work today(, and document that.
            • subpixel:
              • benchmark to csheck if "de-normalizing" the super-refactored code in there would make some difference.
              • (current code is super-geekie but requires 3-level calls to set/reset each subpixel)
              • if keeping elegance is a must, evolve a script in tools that will "glue together" the denormalized code inline.
              • (or check pymacro)
      • ^^ these optimizations should bring frame performance to a more reasonable value (10s of FPS expected. Currently 5 FPS is something just achiaveable for the most simple of renderings, just affecting an area of the screen). At this point the bottleneck should be the terminal emulator program (then check for Kitty and other terminals that intend to be fast)
    opened by jsbueno 0
  • Processing-like API

    Processing-like API

    A nice to have feature would be an API closer to Processing's one. Maybe we could port pyde scripts to terminedia or something similar.

    References

    opened by berinhard 0
  • Fix keyboard handling in Windows terminal

    Fix keyboard handling in Windows terminal

    Keybard handling works fine in cmd and cmder, but not on the new Windows terminal - (in an investigation a while back, I traced it to some behavior on the terminal I thought would be reversed soon - it did not happen).

    • Check if the terminal app is windows terminal, and handle keyboard properly.
    windows 
    opened by jsbueno 0
  • Fix Colors in Windows

    Fix Colors in Windows

    Current terminal backend uses the "39 SGR" Ansi sequence for 24bit color on the terminal. However, colorama wll simply strip these sequences off, resulting in no color capabilities in windows - even though windows terminal suppots 24bit color, and "cmder" supports the color sequences (and rounds the colors down to the 16 more used values).

    Find a way to detect the terminal app under windows, and only trigger "colorama" if on "cmd" - the other apps work with plainANSI sequences. Round colors down to the 16 "well known codes" if on cmd or cmder.

    windows 
    opened by jsbueno 0
Releases(0.4.2)
  • 0.4.2(Sep 24, 2021)

  • 0.4.1(Jul 25, 2021)

    Hundreds of new features, including text styling using a markup system, mouse events, an incipient widget system, unicode 13 sextant character block (1/6 block) resolution, full-color 1/2 block resolution, and more... (check DONE.txt and git log) terminedia-0.4.1.tar.gz Pending: documentation.

    Source code(tar.gz)
    Source code(zip)
Owner
Joao S. O. Bueno
Joao S. O. Bueno
Dynamically Generate GitHub Stats as like Terminal Interface

GitHub Stats Terminal Style Dynamically Generate GitHub Stats as like Terminal Interface Usage Create a New Repository using this Template or click he

YOGESHWARAN R 63 Jan 03, 2023
A terminal UI dashboard to monitor requests for code review across Github and Gitlab repositories.

A terminal UI dashboard to monitor requests for code review across Github and Gitlab repositories.

Kyle Harrison 150 Dec 14, 2022
Write Django management command using the click CLI library

Django Click Project information: Automated code metrics: django-click is a library to easily write Django management commands using the click command

Jonathan Stoppani 215 Dec 19, 2022
Generate an ASCII Art from keyword put in the cli

ascii-art-generator-cli Generate an ASCII Art from keyword put in the cli Install git clone https://github.com/Nathanlauga/ascii-art-generator-cli cd

Nathan Lauga 1 Nov 14, 2021
CLabel is a terminal-based cluster labeling tool that allows you to explore text data interactively and label clusters based on reviewing that data.

CLabel is a terminal-based cluster labeling tool that allows you to explore text data interactively and label clusters based on reviewing that

Peter Baumgartner 29 Aug 09, 2022
TermPair lets developers securely share and control terminals in real time🔒

View and control terminals from your browser with end-to-end encryption 🔒

Chad Smith 1.5k Jan 05, 2023
eBay's TSV Utilities: Command line tools for large, tabular data files. Filtering, statistics, sampling, joins and more.

Command line utilities for tabular data files This is a set of command line utilities for manipulating large tabular data files. Files of numeric and

eBay 1.4k Jan 09, 2023
A simple command line dumper written in Python 3.

A simple command line dumper written in Python 3.

ImFatF1sh 1 Oct 10, 2021
A ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line.

A ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line.

Tom Dörr 976 Jan 03, 2023
Terminal epub reader with inline images

nuber Inspired by epy, nuber is an Epub terminal reader with inline images written with Rust and Python using Überzug. Features Display images in term

Moshe Sherman 73 Oct 12, 2022
Freaky fast fuzzy Denite/CtrlP matcher for vim/neovim

Freaky fast fuzzy Denite/CtrlP matcher for vim/neovim This is a matcher plugin for denite.nvim and CtrlP.

Raghu 113 Sep 29, 2022
This is a simple Termo application in command line style

my-termo This is a simple Termo application in command line style. This app run a Linux crontab task every day to get a new word. Type termo in your t

Gustavo Soares 1 Feb 14, 2022
A Telegram Bot Written In Python To Upload Medias To telegra.ph

Telegraph-Uploader A Telegram Bot Written In Python To Upload Medias To telegra.ph DEPLOY YOU CAN SIMPLY DEPLOY ON HEROKU BY CLICKING THE BUTTON BELOW

Rithunand 31 Dec 03, 2022
Because sometimes you need to do it live

doitlive doitlive is a tool for live presentations in the terminal. It reads a file of shell commands and replays the commands in a fake terminal sess

Steven Loria 3.2k Jan 09, 2023
Spongebob-cli - Watch classic spongebob from the terminal

spongebob-cli Watch classic spongebob from the terminal! Thanks to everyone that

523 Jan 02, 2023
The WalletsNet CLI helps you connect to WalletsNet

WalletsNet CLI The WalletsNet CLI helps you connect to WalletsNet. With the CLI, you can: Trigger webhook events or resend events for easy testing Tai

WalletsClub 8 Dec 22, 2021
Tools hacking termux in the name ant-attack

Hello friends, I am ama.player0000. Web developer, software, Android command line (termux). (1)=Well, ant-attack tool is a tool to attack sites and disable them. (2)=You can use those CCTV servers, s

༺AMA.PLAYER༻ 1 Dec 17, 2021
Cek Username IG Yang Masih Bisa Dipake

Cek Username IG Cara Install $ pkg update && pkg upgrade $ pkg install python $ pkg install git $ git clone https://github.com/Dekusec/ig-checker $ cd

Deku 3 Nov 28, 2021
dsub is a command-line tool that makes it easy to submit and run batch scripts in the cloud.

Open-source command-line tool to run batch computing tasks and workflows on backend services such as Google Cloud.

Data Biosphere 233 Jan 01, 2023
Code for "Salient Deconvolutional Networks, Aravindh Mahendran, Andrea Vedaldi, ECCV 2016"

deconvnet_analysis Code for "Salient Deconvolutional Networks, Aravindh Mahendran, Andrea Vedaldi, ECCV 2016" Parts of this code Generate figures in t

Aravindh Mahendran 12 Jan 25, 2021