Welcome to terminedia’s documentation!

terminedia package

Subpackages

Submodules

terminedia.context module

Internal Use - provide the default context values for the application.

This is meant to be used as a Singleton - that is instantiated when the library is first imported and lives on as “terminedia.context”. The main difference for ordinary contexts is that it is the authoritative source for the colors to be used as “DEFAULT_BG” and “DEFAULT_FG” on non-ANSI backends. ANSI backends have default values supplied by the terminal-emulator program itself, which can’t be easily guessed by running applications. (Like White or Green foreground and Black background, depending on the terminal theme).

terminedia.drawing module

class terminedia.drawing.Drawing(set_fn, reset_fn, get_fn, size_fn, context)

Bases: object

Drawing and rendering API

An instance of this class is attached to Screen and Shape instances as the draw attribute, and as the .high.draw and .braile.draw attributed for drawing with 1/4 and 1/8 block characters. All context-related information is kept on the associated screen instance, the public methods here issue pixel setting and resetting at the owner - using that owners’s context colors and other attributes.

That is - the typical usage for methods here will be screen.draw.line((0,0)-(50,20))

bezier(pos1, pos2, pos3, pos4, *extra, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)

Draws a bezier curve given the control points

Args:

pos1 (2-sequence): Fist control point pos2 (2-sequence): Second control point pos3 (2-sequence): Third control point pos4 (2-sequence): Fourth control point extra Tuple[2-sequence]: n-sets of 3 more control points to keep drawing.

blit(pos, data, *, roi=None, color_map=None, erase=False)

Blits a blocky image in the associated screen at POS

Args:
  • pos (Union[2-sequence, Rectangle]): top-left corner of where to blit, or a rectangle with extents to be blitted.

  • shape (Shape/string/list): Shape object or multi-line string or list of strings with shape to be drawn

  • roi (Optional[Rect]): (Region of interest) delimiting rectangle in source image(data) to be blitted.

    Defaults to whole image.

  • color_map (Optional mapping): palette mapping chracters in shape to a color

  • erase (bool): if True white-spaces are erased, instead of being ignored. Default is False. FIXME: under the Pixel model, erase is always True.

Shapes return specialized Pixel classes when iterated upon - what is set on the screen depends on the Pixel returned. As of version 0.3dev, Shape class returns a pixel that has a True or False value and a foreground color (or no color) - support for other Pixel capabilities is not yet implemented.

ellipse(pos1, pos2=(), *, rel=(), char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)

Draws an ellipse

Args:
  • pos1 (Union[Rectangle, 2-tuple]): top-left coordinates

  • pos2 (Optional[2-tuple]): bottom-right limit coordinates. If not given, pass “rel” instead

  • rel (Optional[2-tuple]): (width, height) of rectangle. Ignored if “pos2” is given

Public call to draw an ellipse using character blocks on the terminal. The color line is defined in the owner’s context.color attribute. In the case of high-resolution drawing, the background color is also taken from the context.

fill(*, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)

Fills the associated target with current context values Args:

The context attributes are used to fill the target area.

floodfill(pos, threshold=None, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)

Fills the associated target with context values, starting at seed “pos”.

Any different parameters for target pixels are considered boundaries “threshold” may be passed a guard callable which will take each target pixel, and should return “False” if it should be painted and “True” if it is a boundary. Args:

  • pos (V2|Sequence[2]): initial position

  • threshold (Optional[Callable[Pixel, Pixel, Pos]): callable - takes initial value at origin, and target pixel value.

    Should return ‘True’ for boundary pixels, False if pixel is to be painted.

The context attributes are used to fill the target area.

line(pos1, pos2, erase=False, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)

Draws a straight line connecting both coordinates.

Args:
  • pos1 (2-tuple): starting coordinates

  • pos2 (2-tuple): ending coordinates

  • erase (bool): Whether to draw (set) or erase (reset) pixels.

Public call to draw an arbitrary line using character blocks on the terminal. The color line is defined in the passed parameter or from the context.

rect(pos1, pos2=(), *, rel=(), erase=False, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)

Draws a rectangle

Args:
  • pos1 (Union[Rectangle, 2-tuple]): top-left coordinates

  • pos2 (Optional[2-tuple]): bottom-right limit coordinates. If not given, pass “rel” instead

  • rel (Optional[2-tuple]): (width, height) of rectangle. Ignored if “pos2” is given

  • fill (bool): Whether fill-in the rectangle, or only draw the outline. Defaults to False.

  • erase (bool): Whether to draw (set) or erase (reset) pixels.

Public call to draw a rectangle using character blocks on the terminal. The color line is defined in the owner’s context.color attribute. In the case of high-resolution drawing, the background color is also taken from the context.

size
class terminedia.drawing.HighResBase(parent, block_class=<terminedia.subpixels.BlockChars_ object>, block_width=2, block_height=2)

Bases: object

Provides a seamless mechanism to draw using unicode special characters as pixels.

This is used as a base to have the method used for drawing using 1/4 block characters, Braile characters, vintage “sextant” 1/6 blocks and possibly others to come.

Keep in mind that while it is possible to emulate the higher resolution pixels, screen colors are limited to character positions, so color on these pixels will “leak” to their block. (Users familiar with the vintage 8 bit ZX-Spectrum should feel at home)

This class should not be instanced or used directly - instead, call the Drawing methods in the associated draw class as in screen.high.draw.blit(position, image)

at_parent(pos)

Get the equivalent, rounded down, coordinates, at the parent object.

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

Returns:
  • V2 object with the equivalent object at the parent space.

get_at(pos)

Queries pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

Returns:
  • True: pixel is set

  • False: pixel is not set

  • None: Character on Screen at given coordinates is not a block character of the class

    used as pixel-characters for this instance.

get_size()

Returns the width and height available at high-resolution based on parent’s Screen size

operate(pos, operation)

Internal -

Common code to calculate the coordinates and get/reset/query a pixel at the correct sub-block resolution. Call HighRes.set_at, HighRes.reset_at or HighRes.get_at instead.

print_at(pos, text)

Positions the cursor and prints a text sequence

[DEPRECATED] - use “at_parent” to get parent coordinates and other means to

render text there.

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

  • txt: Text to render at position

The text is printed as normal full-block characters. The method is given here just to enable using the same coordinate numbers to display other characters when drawing in high resolution.

Context’s direction is respected when printing

reset_at(pos)

Resets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

To be used as a callback to .draw.reset - but there are no drawbacks in being called directly.

set_at(pos)

Sets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

To be used as a callback to .draw.set - but there are no drawbacks in being called directly.

height
size

Returns the width and height available at high-resolution based on parent’s Screen size

width
class terminedia.drawing.Square(parent, block_class=<terminedia.subpixels.HalfChars_ object>, block_width=1, block_height=2)

Bases: terminedia.drawing.HighResBase

Reimplements the sub-character block plotting to allow seamless full color in 1x2 resolution

get_at(pos)

Queries pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

Returns:
  • True: pixel is set

  • False: pixel is not set

  • None: Character on Screen at given coordinates is not a block character of the class

    used as pixel-characters for this instance.

reset_at(pos)

Resets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

To be used as a callback to .draw.reset - but there are no drawbacks in being called directly.

set_at(pos)

Sets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

To be used as a callback to .draw.set - but there are no drawbacks in being called directly.

terminedia.drawing.HighRes(parent, block_class=<terminedia.subpixels.BlockChars_ object>, block_width=2, block_height=2)

Factory method - uses specialized class if Square resolution for a shape supporting FG & BG is requested

terminedia.image module

class terminedia.image.DirtyNode(tick, untie, rect, source)

Bases: tuple

rect

Alias for field number 2

source

Alias for field number 3

tick

Alias for field number 0

untie

Alias for field number 1

class terminedia.image.FullShape(data, **kw)

Bases: terminedia.image.RasterUndo, terminedia.image.Shape

Shape class carrying all possible data plus kitchen sink

Args:
  • data: a sequence with 4 planes (sequences), each a sequence with n-rows

    sequences of m-width elements. The first one should carry character data: a unicode sequence representing a single glyph. The second and 3rd should contain color values, and the 4th an integer representing text effects according to Effects values.

PixelCls

alias of Pixel

get_raw(pos)
load_data(data_planes, size)
Sets internal data from an initial value structure.
Args:
  • data: data structure containing the elements

    that will be set to inicial pixel values. Can be a single sequence width x height in size containing all elements to be assigned as pixels, or a height-sized sequence of width-sized sequences.

  • size (V2-like): width x height.

Used to explictly set the initial values for a shape, will usually be called internally as part of the Shape initialization. If size is not given, and the passed data is 1D in nature, sie is assumed to be a single colum (1xN) shape. Strings are split at “

” and will be treated as 2D if multiline.

classmethod promote(other_shape, resolution=None)

Makes a FullShape copy of the other shape

This allows the new shape to be used with Transformers, Sprites, and other elements that might not be supported in the other shape classes

class terminedia.image.ImageShape(data, color_map=None, size=None, **kwargs)

Bases: terminedia.image.ValueShape

Relies on Python Imaging Library to load and handle image data.

The internal “data” member is a straighout PIL.Image instance, and one is free to use PIL drawing and image manipulation APIs to draw on it.

Important: on instantiating these shapes, Terminedia will try to auto-scale down/resample the image to compensate for the aspect-ratio of text imags. Pass the parameter auto_scale=False to __init__ or __new__ to preserve the exact size of the PIL Image.

PixelCls

alias of Pixel

clear(transparent=False)

Clear the shape with empty spaces.

params:

transparent (bool): whether to use special transparency values

if “transparent” is True, the shape is filled with the special TRANSPARENT value that make underlying shape characters, or existing tty content unchanged upon blitting.

get_raw(pos)
load_data(file_or_path, size=None, half_height=False)

Will load data from an image file using PIL,

If “size” is not passed, the native image size is used. Otherwise it should be a 2-sequence: if both numbers are given, that is used as final image size. If one component of “size” is “None”, the other one is used to scale the image, keeping its aspect ratio.

As due to the nature of character blocks, keeping the aspect ratio can lead to a strange 1:2 final display, pass “half_height=True” to keep the same visual aspect ratio for full blocks. (hint: you can load the full height and blit the resulting shape to a square 1/2 block drawable instead)

resize(new_size)
class terminedia.image.OrderedRegistry

Bases: object

push(node)
reset()
reset_to(node)
class terminedia.image.PGMShape(data, color_map=None, size=None, **kwargs)

Bases: terminedia.image.ValueShape

PixelCls

alias of Pixel

load_data(file_or_path, size=None)

Will load data from a PGM/PPM file. Size parameter is ignored

class terminedia.image.PalettedShape(data, color_map=None)

Bases: terminedia.image.Shape

‘Shape’ class intended to represent images, using a color-map to map characters to block colors.

Args:
  • data (multiline string or list of strings): character map to be used as pixels

  • color_map (optional mapping): maps characters to RGB colors.

This class have no special per pixel values for background or character - each block position will read as “False” or “True” depending only on the underlying character in the input data being space (0x20) or any other thing.

PixelCls

alias of Pixel

load_paletted(data)
arbitrary_chars = False
background = False
effects = False
foreground = True
class terminedia.image.Pixel

Bases: tuple

get_values(context=None, capabilities=None)

Retrieve pixel or context values, according to caller’s context and capabilities

That is, if this pixel provides value as str, fg and bg but no effects, and the target accepts value as boolean, fg, and text effects, a list with those properties set is generated.

List is choosen in order to allow further processing of values without recreating the container (for example, to replace ‘CONTEXT_COLORS’ for the actual colors.

Although passing a context is optional, if, for generating the target values any context values are needed, no further tests are done: an AttributeError on the ‘None’ default context will take place.

class terminedia.image.PixelDict(maps=None)

Bases: collections.ChainMap

Cached ChainMap

clear()

Clear maps[0], leaving maps[1:] intact.

pop()

Remove key from maps[0] and return its value. Raise KeyError if key not in maps[0].

push(map=None)
class terminedia.image.RasterUndo(*args, undo_active=False, max_undo_steps=100, **kw)

Bases: object

Controls and offer the API for raster undo-capability

redo(n=1)
undo(n=1)
undo_clear(n=1)

Merge all pixel data into base, and clear undo history

undo_group_end()
undo_group_start()
classmethod undoable(func)

Decorator - apply on functions and methods that will use Raster functions so that they automatically start an undo_group.

@FullShape.undoable

verify_and_merge_max_undo_groups()
class terminedia.image.ShalowShapeRepr(original: terminedia.image.Shape)

Bases: object

restore()

Recreates a Shape of the original class with the flattened data

class terminedia.image.Shape(*args, **kwargs)

Bases: abc.ABC, terminedia.image.ShapeApiMixin, terminedia.image.ShapeDirtyMixin

‘Shape’ is intended to represent blocks of colors/backgrounds and characters to be applied in a rectangular area of the terminal. In this sense, it is more complicated than an “Image” that just care about a foreground color and alpha value for each pixel position.

As internal data and rendering intents vary accross desired capabilities, there are subclasses to represent each intended use.

PixelCls

alias of Pixel

concat(*others, direction=Directions.RIGHT, **kwargs)

Concatenates two given shapes side by side into a larger shape.

Args:
  • other (Shape): Other shape to be concatenated.

  • direction (V2): Side which will be “enlarged” and on which the other shape

    will be placed. Most usefull values are Directions.RIGHT and Directions.DOWN

  • **kwargs: are passed down to the “new” constructor of the resulting shape.

Creates a new shape combining two or more other shapes. If Shape _allowed_types differ, the logic in Drawing.blit will try to cast pixels to the one used in self.

get_data_offset(pos)
get_raw(pos)
load_data(data, size=None)
Sets internal data from an initial value structure.
Args:
  • data: data structure containing the elements

    that will be set to inicial pixel values. Can be a single sequence width x height in size containing all elements to be assigned as pixels, or a height-sized sequence of width-sized sequences.

  • size (V2-like): width x height.

Used to explictly set the initial values for a shape, will usually be called internally as part of the Shape initialization. If size is not given, and the passed data is 1D in nature, sie is assumed to be a single colum (1xN) shape. Strings are split at “

” and will be treated as 2D if multiline.

classmethod new(size, **kwargs)

Creates an empty shape of this class.

Args:
  • size (2-sequence): width x height of the new shape

  • **kwargs: keyword arguments either to the class empty-data builder

    (cls._data_func) - e.g. “color” - or for the class’ __init__ - e.g. color_map.

Creates a new empty shape, using given size and keyword parameters, which are dispatched as appropriate to build the empty pixel values or to the class itself.

render(output=None, backend='ANSI')

Renders shape contents into a text-output. Args:

  • backend (str): currently implemented “ANSI” - output type

  • output(Optional[Union[TextIO, BytesIO]])

Output:

->Optional[Union[str, bytes]]

Renders shape contents into content that can reprsent the image outside terminedia library. That is, if the shape is rendered with “ANSI”, a text body, with the ESC encoded ANSI sequences for cursor positioning embeded will be generated. If this body is subsequnetly printed, the image in the Shape is reproduced on the terminal.

If output is given, it should be a file-like object to which the contents of the shape will be written. Binary backends require a binary file. thenmethod returns None. If no output is given, the rendered contents are returned.

resize(new_size)
isroot = False
class terminedia.image.ShapeApiMixin

Bases: object

clear(transparent=False)

Clear the shape with empty spaces.

params:

transparent (bool): whether to use special transparency values

if “transparent” is True, the shape is filled with the special TRANSPARENT value that make underlying shape characters, or existing tty content unchanged upon blitting.

get_size()
spaces_to_transparency()
braille

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

context

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

draw

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

has_sprites = False
high

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

sextant

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

size
sprites

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

square

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

text

Special Internal Use Descriptor

This creates the associated attribute in an instance only when the attribute is acessed for the first time, in a dynamic way. This allows objcts such as Shapes have specialized associated “draw”, “high”, “text”, “sprites” attributes, and still be able to be created lightweight for short uses that will use just a few, or none, of these attributes.

class terminedia.image.ShapeDirtyMixin(*args, **kwargs)

Bases: object

dirty_clear(threshold=None)
dirty_mark_pixel(index)
dirty_save_current_sprite_rects(tick)
dirty_set(rect=None)
dirty_update()
dirty_rects
class terminedia.image.ShapeView(original, roi)

Bases: terminedia.image.ShapeApiMixin

get_size()
height
isroot = False
original
roi
width
class terminedia.image.ValueShape(data, color_map=None, size=None, **kwargs)

Bases: terminedia.image.Shape

PixelCls

alias of Pixel

terminedia.image.full_pixel

alias of terminedia.image.Pixel

class terminedia.image.pixel_capabilities(value_type, has_foreground, has_background, has_effects)

Bases: tuple

has_background

Alias for field number 2

has_effects

Alias for field number 3

has_foreground

Alias for field number 1

value_type

Alias for field number 0

terminedia.image.pixel_factory(value_type=<class 'str'>, has_foreground=True, has_background=False, has_effects=False, translate_dots=True)

Returns a custom pixel class with specified capabilities

Args:

value_type(str or bool): Data type returned by the pixel has_foreground (bool): Whether pixel has a foreground color has_background (bool): Whether pixel has a background color has_effects (bool): Whether pixel has text-attribute flags

Created pixel classes or instances are not intended to be directly manipulated - instead, they are just a way to convey information from internal images/shapes to methods that will draw then.

terminedia.image.shape(data, color_map=None, promote=False, resolution=None, **kwargs)

Factory for shape objects

Args:
  • data (Filepath to image, open file, image data as text or list of strings)

  • color_map (optional mapping): color map to be used for the image - mapping characters to RGB colors.

  • promote (boolean): Whether to force resulting shape to a FullShape (defaults to False)

  • resolution (str): If promote is True, resolution namespace to use on blitting to

    FullShape (“square”, “high”, “square”)

  • **kwargs: parameters passed transparently to the selected shape class

Based on inferences on the data attribute, selects the appropriate Shape subclass to handle the “data” attribute. That is: given a string without newlines, it is interpreted as a filepath, and if PIL is installed, an RGB “ImageShape” class is used to read the image data. If text with “

is passed in, an PalettedShape is used to directly use the passed data as pixels.

Returns an instance of the selected class with the data set.

terminedia.image.SKIP_LINE = <object object>

Special value that can be sent (.send()) during interaction on Shape areas, so that the inner iterator does not go up to the end of a line in the internal buffer is those values will no longer be used. The drawing.Drawing.blit method has the code that sends this.

terminedia.keyboard module

terminedia.screen module

class terminedia.screen.Screen(size=(), clear_screen=True, backend='ansi', interactive=True)

Bases: object

Canvas class for terminal drawing.

This is the main class to interact with the terminal on Terminedia library - methods and associated instances here should be used to do all screen rendering and drawing save for low-level work.

Use this as a context manager inside which the screen is active;

For drawing primitives using full-block chars, use the instance’s Screen.draw, which contains a Drawing instance. Terminal context colors and other attributes can be set in a thread-safe way on the screen.context namespace.

To draw and position characters using 1/4 character high resolution, use the attributes and methods available at Screen.high. (High resolution drawing methods are available at screen.high.draw)

Besides the available methods and associated instances, screen contents can be set and read by using the Screen instance as a 2-dimensional mapping. For example, screen[10, 10] = "A" will set the character on that position.

Args:
  • size (optional 2-sequence): Screen size in blocks. If not given, terminal size is queried automatically. This does not resize the actual terminal - a smaller area is available to the methods instead. If given size is larger than the actual terminal, mayhen ensues.

  • clear_screen (bool): Whether to clear the terminal and hide cursor when entering the screen. Defaults to True.

  • interactive (bool): if False, do not create binding for events, or change keyboard and mouse behaviors (used by rendering to file).

    Default: True

accelerate()

makes drawing less interactive, but faster

Replaces the “self.draw” namespace to the one going through the associated shape (self.shape) - aftewrards self.update() have to be called in order to reflect any drawing on the terminal, but it gets faster as updates in large blocks.

Also, the “native” self.draw is a bit rough when it commes to drawing off the screen limits.

This is called automatically by the terminedia_main loop.

There is no “de-acellarate” converse call, once an app is already using screen.update it makes little sense to togle back, but all one have to do if needed, is to replace the attribute by a new Draw instance as created inside __init__.

blit(position, shape, **kwargs)
clear(wet_run=True)

Resets internal data, context parameters and clears the screen

Args:
  • wet_run (bool): Whether to physically clear the screen or not

Resets internal data and context parameters. The “self.data” and “self.color_data” structures are where the current character and attributes for each position are kept as characters actually just printed on the terminal can’t be “read” back. Context foreground, background and direction are reset.

In default operation, commands to clear the actual terminal and hide the cursor is also issued - the .clear_screen attribute controls that if .clear is being called as part of entering the screen context.

get_at(pos)
get_raw(pos)
line_at(pos, length, sequence='█')

Renders a repeating character sequence of given length respecting the context.direction

This is an antique method from a time when there was no drawing API. Prefer screen.draw.line for mor control. Args:

  • pos (2-sequence): coordinates where to start drawing

  • length (int): length of character sequence to render

  • sequence (str): Text to render at position - defaults to full-block character

Draws a vertical or horizontal line of characters, repeating the characteres of the sequence given, up to the specified length. Can be used to draw lines of aritrary characters or short words. The line directin is taken from the context’s direction.

print(text, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None, **kwargs)

Prints a text sequence following the last character printed

Args:
  • text: Text to render at position

Context’s attributes are respected when printing

print_at(pos, text, size=1, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None, font=None, direction=None)

Positions the cursor and prints a text sequence

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

  • text: Text to render at position

  • size: Text-size to print:

    1 or “normal”: plain text 2 or “braille”: 8x8 font rendered using 2x4 Braille characters for subpixels 3 or “sextant”: 8x8 font rendered using 2x3 Vintage Charset characters for subpixels 4 or “high”: 8x8 font rendered using 2x2 Block characters for subpixels (4,8) or “square”: 8x8 font rendered using 1x2 Half-Block characters for subpixels 8 or “block”: 8x8 font rendered using 1 Block characters as pixels

Context’s attributes are respected when printing

process_events()

Dispatches procss-wide events (like keyboard and mouse if enabled)

This will be called automatically on “self.update” - it is set as a separate method because one could call this to get input events before proceeding with the actual display update.

reset_at(pos)

Resets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

To be used as a callback to .draw.reset - but there are no drawbacks in being called directly.

set_at(pos, pixel=None)

Sets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

  • pixel (Optional[Pixel]): sets the context values according to pixel attributes prior to printing

To be used as a callback to .draw.set - but there are no drawbacks in being called directly.

update(pos1=None, pos2=None)

Main method to update the display

An interactive application or animation should call this once per frame to have th display contents updated on the terminal.

It can optionally update just a part of the output screen, if pos1 or pos2 are given.

As of pre-0.4.0 development an app should manually provide its “mainloop” and call this on each frame. Later development will probably have an optional higher level loop that will automate calling here.

Args:
  • pos1, pos2: Corners of a rectangle delimitting the area to be updated.

    (optionally, ‘pos1’ can be a Rect object)

commands = None

Namespace for low-level rendering commands, an instance of JournalingCommandsMixin. This attribute can be used as a context manager to group various output operations in a single block that is rendered at once.

context

Namespace to configure drawing and printing color and other parameters. Currently, the attributes that are used from here are color, background, direction, effects and char.

data = None

Instance contaning a mirror of the screen contents and attributes. All Screen drawing attributes are mirrored in it, but it can be updated independently and blitted to the terminal later by calling Screen.update.

draw = None

Namespace for drawing methods, containing an instance of the Drawing class

high = None

Namespace to allow high-resolution drawing using a HighRes instance One should either use the public methods in HighRes or the methods on the Drawing instance at Screen.high.draw to do 1/2, 1/4, 1/6 and 1/8 block pixel manipulation.

last_background = None

Internal: tracks last used background attribute to avoid mangling and enable optimizations

last_color = None

Internal: tracks last used foreground attribute to avoid mangling and enable optimizations

last_effects = None

Internal: tracks last used effects attribute to avoid mangling and enable optimizations

lock = <unlocked _thread.lock object>

Lock to avoid ANSI sequence mangling if used in multi-threading

terminedia.subpixels module

class terminedia.subpixels.BlockChars_

Bases: terminedia.subpixels.SubPixels

Used internally to emulate pixel setting/resetting/reading inside 1/4 block characters

Contains a listing and other mappings of all block characters used in order, so that bits in numbers from 0 to 15 will match the “pixels” on the corresponding block character.

Although this class is purposed for internal use in the emulation of a higher resolution canvas, its functions can be used by any application that decides to manipulate block chars.

The class itself is stateless, and it is used as a single-instance which uses the name BlockChars. The instance is needed so that one can use the operator in to check if a character is a block-character.

EMPTY = ' '
FULL_BLOCK = '█'
LEFT_HALF_BLOCK = '▌'
LOWER_HALF_BLOCK = '▄'
QUADRANT_LOWER_LEFT = '▖'
QUADRANT_LOWER_RIGHT = '▗'
QUADRANT_UPPER_LEFT = '▘'
QUADRANT_UPPER_LEFT_AND_LOWER_LEFT_AND_LOWER_RIGHT = '▙'
QUADRANT_UPPER_LEFT_AND_LOWER_RIGHT = '▚'
QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_LEFT = '▛'
QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_RIGHT = '▜'
QUADRANT_UPPER_RIGHT = '▝'
QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT = '▞'
QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT_AND_LOWER_RIGHT = '▟'
RIGHT_HALF_BLOCK = '▐'
UPPER_HALF_BLOCK = '▀'
block_height = 2
block_width = 2
chars = {' ', '▀', '▄', '█', '▌', '▐', '▖', '▗', '▘', '▙', '▚', '▛', '▜', '▝', '▞', '▟'}
chars_by_name = {'EMPTY': ' ', 'FULL_BLOCK': '█', 'LEFT_HALF_BLOCK': '▌', 'LOWER_HALF_BLOCK': '▄', 'QUADRANT_LOWER_LEFT': '▖', 'QUADRANT_LOWER_RIGHT': '▗', 'QUADRANT_UPPER_LEFT': '▘', 'QUADRANT_UPPER_LEFT_AND_LOWER_LEFT_AND_LOWER_RIGHT': '▙', 'QUADRANT_UPPER_LEFT_AND_LOWER_RIGHT': '▚', 'QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_LEFT': '▛', 'QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_RIGHT': '▜', 'QUADRANT_UPPER_RIGHT': '▝', 'QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT': '▞', 'QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT_AND_LOWER_RIGHT': '▟', 'RIGHT_HALF_BLOCK': '▐', 'UPPER_HALF_BLOCK': '▀'}
chars_in_order = {0: ' ', 1: '▘', 2: '▝', 3: '▀', 4: '▖', 5: '▌', 6: '▞', 7: '▛', 8: '▗', 9: '▚', 10: '▐', 11: '▜', 12: '▄', 13: '▙', 14: '▟', 15: '█'}
chars_to_name = {' ': 'EMPTY', '▀': 'UPPER_HALF_BLOCK', '▄': 'LOWER_HALF_BLOCK', '█': 'FULL_BLOCK', '▌': 'LEFT_HALF_BLOCK', '▐': 'RIGHT_HALF_BLOCK', '▖': 'QUADRANT_LOWER_LEFT', '▗': 'QUADRANT_LOWER_RIGHT', '▘': 'QUADRANT_UPPER_LEFT', '▙': 'QUADRANT_UPPER_LEFT_AND_LOWER_LEFT_AND_LOWER_RIGHT', '▚': 'QUADRANT_UPPER_LEFT_AND_LOWER_RIGHT', '▛': 'QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_LEFT', '▜': 'QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_RIGHT', '▝': 'QUADRANT_UPPER_RIGHT', '▞': 'QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT', '▟': 'QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT_AND_LOWER_RIGHT'}
chars_to_order = {' ': 0, '▀': 3, '▄': 12, '█': 15, '▌': 5, '▐': 10, '▖': 4, '▗': 8, '▘': 1, '▙': 13, '▚': 9, '▛': 7, '▜': 11, '▝': 2, '▞': 6, '▟': 14}
class terminedia.subpixels.BrailleChars_

Bases: terminedia.subpixels.SubPixels

Used internally to emulate pixel setting/resetting/reading inside 1/8 Unicode Braille characters

EMPTY = ' '
bit_size = 255
block_height = 4
block_width = 2
chars = {' ', '⠁', '⠂', '⠃', '⠄', '⠅', '⠆', '⠇', '⠈', '⠉', '⠊', '⠋', '⠌', '⠍', '⠎', '⠏', '⠐', '⠑', '⠒', '⠓', '⠔', '⠕', '⠖', '⠗', '⠘', '⠙', '⠚', '⠛', '⠜', '⠝', '⠞', '⠟', '⠠', '⠡', '⠢', '⠣', '⠤', '⠥', '⠦', '⠧', '⠨', '⠩', '⠪', '⠫', '⠬', '⠭', '⠮', '⠯', '⠰', '⠱', '⠲', '⠳', '⠴', '⠵', '⠶', '⠷', '⠸', '⠹', '⠺', '⠻', '⠼', '⠽', '⠾', '⠿', '⡀', '⡁', '⡂', '⡃', '⡄', '⡅', '⡆', '⡇', '⡈', '⡉', '⡊', '⡋', '⡌', '⡍', '⡎', '⡏', '⡐', '⡑', '⡒', '⡓', '⡔', '⡕', '⡖', '⡗', '⡘', '⡙', '⡚', '⡛', '⡜', '⡝', '⡞', '⡟', '⡠', '⡡', '⡢', '⡣', '⡤', '⡥', '⡦', '⡧', '⡨', '⡩', '⡪', '⡫', '⡬', '⡭', '⡮', '⡯', '⡰', '⡱', '⡲', '⡳', '⡴', '⡵', '⡶', '⡷', '⡸', '⡹', '⡺', '⡻', '⡼', '⡽', '⡾', '⡿', '⢀', '⢁', '⢂', '⢃', '⢄', '⢅', '⢆', '⢇', '⢈', '⢉', '⢊', '⢋', '⢌', '⢍', '⢎', '⢏', '⢐', '⢑', '⢒', '⢓', '⢔', '⢕', '⢖', '⢗', '⢘', '⢙', '⢚', '⢛', '⢜', '⢝', '⢞', '⢟', '⢠', '⢡', '⢢', '⢣', '⢤', '⢥', '⢦', '⢧', '⢨', '⢩', '⢪', '⢫', '⢬', '⢭', '⢮', '⢯', '⢰', '⢱', '⢲', '⢳', '⢴', '⢵', '⢶', '⢷', '⢸', '⢹', '⢺', '⢻', '⢼', '⢽', '⢾', '⢿', '⣀', '⣁', '⣂', '⣃', '⣄', '⣅', '⣆', '⣇', '⣈', '⣉', '⣊', '⣋', '⣌', '⣍', '⣎', '⣏', '⣐', '⣑', '⣒', '⣓', '⣔', '⣕', '⣖', '⣗', '⣘', '⣙', '⣚', '⣛', '⣜', '⣝', '⣞', '⣟', '⣠', '⣡', '⣢', '⣣', '⣤', '⣥', '⣦', '⣧', '⣨', '⣩', '⣪', '⣫', '⣬', '⣭', '⣮', '⣯', '⣰', '⣱', '⣲', '⣳', '⣴', '⣵', '⣶', '⣷', '⣸', '⣹', '⣺', '⣻', '⣼', '⣽', '⣾', '⣿'}
chars_by_name = {'BRAILLE PATTERN DOTS-1': '⠁', 'BRAILLE PATTERN DOTS-12': '⠃', 'BRAILLE PATTERN DOTS-123': '⠇', 'BRAILLE PATTERN DOTS-1234': '⠏', 'BRAILLE PATTERN DOTS-12345': '⠟', 'BRAILLE PATTERN DOTS-123456': '⠿', 'BRAILLE PATTERN DOTS-1234567': '⡿', 'BRAILLE PATTERN DOTS-12345678': '⣿', 'BRAILLE PATTERN DOTS-1234568': '⢿', 'BRAILLE PATTERN DOTS-123457': '⡟', 'BRAILLE PATTERN DOTS-1234578': '⣟', 'BRAILLE PATTERN DOTS-123458': '⢟', 'BRAILLE PATTERN DOTS-12346': '⠯', 'BRAILLE PATTERN DOTS-123467': '⡯', 'BRAILLE PATTERN DOTS-1234678': '⣯', 'BRAILLE PATTERN DOTS-123468': '⢯', 'BRAILLE PATTERN DOTS-12347': '⡏', 'BRAILLE PATTERN DOTS-123478': '⣏', 'BRAILLE PATTERN DOTS-12348': '⢏', 'BRAILLE PATTERN DOTS-1235': '⠗', 'BRAILLE PATTERN DOTS-12356': '⠷', 'BRAILLE PATTERN DOTS-123567': '⡷', 'BRAILLE PATTERN DOTS-1235678': '⣷', 'BRAILLE PATTERN DOTS-123568': '⢷', 'BRAILLE PATTERN DOTS-12357': '⡗', 'BRAILLE PATTERN DOTS-123578': '⣗', 'BRAILLE PATTERN DOTS-12358': '⢗', 'BRAILLE PATTERN DOTS-1236': '⠧', 'BRAILLE PATTERN DOTS-12367': '⡧', 'BRAILLE PATTERN DOTS-123678': '⣧', 'BRAILLE PATTERN DOTS-12368': '⢧', 'BRAILLE PATTERN DOTS-1237': '⡇', 'BRAILLE PATTERN DOTS-12378': '⣇', 'BRAILLE PATTERN DOTS-1238': '⢇', 'BRAILLE PATTERN DOTS-124': '⠋', 'BRAILLE PATTERN DOTS-1245': '⠛', 'BRAILLE PATTERN DOTS-12456': '⠻', 'BRAILLE PATTERN DOTS-124567': '⡻', 'BRAILLE PATTERN DOTS-1245678': '⣻', 'BRAILLE PATTERN DOTS-124568': '⢻', 'BRAILLE PATTERN DOTS-12457': '⡛', 'BRAILLE PATTERN DOTS-124578': '⣛', 'BRAILLE PATTERN DOTS-12458': '⢛', 'BRAILLE PATTERN DOTS-1246': '⠫', 'BRAILLE PATTERN DOTS-12467': '⡫', 'BRAILLE PATTERN DOTS-124678': '⣫', 'BRAILLE PATTERN DOTS-12468': '⢫', 'BRAILLE PATTERN DOTS-1247': '⡋', 'BRAILLE PATTERN DOTS-12478': '⣋', 'BRAILLE PATTERN DOTS-1248': '⢋', 'BRAILLE PATTERN DOTS-125': '⠓', 'BRAILLE PATTERN DOTS-1256': '⠳', 'BRAILLE PATTERN DOTS-12567': '⡳', 'BRAILLE PATTERN DOTS-125678': '⣳', 'BRAILLE PATTERN DOTS-12568': '⢳', 'BRAILLE PATTERN DOTS-1257': '⡓', 'BRAILLE PATTERN DOTS-12578': '⣓', 'BRAILLE PATTERN DOTS-1258': '⢓', 'BRAILLE PATTERN DOTS-126': '⠣', 'BRAILLE PATTERN DOTS-1267': '⡣', 'BRAILLE PATTERN DOTS-12678': '⣣', 'BRAILLE PATTERN DOTS-1268': '⢣', 'BRAILLE PATTERN DOTS-127': '⡃', 'BRAILLE PATTERN DOTS-1278': '⣃', 'BRAILLE PATTERN DOTS-128': '⢃', 'BRAILLE PATTERN DOTS-13': '⠅', 'BRAILLE PATTERN DOTS-134': '⠍', 'BRAILLE PATTERN DOTS-1345': '⠝', 'BRAILLE PATTERN DOTS-13456': '⠽', 'BRAILLE PATTERN DOTS-134567': '⡽', 'BRAILLE PATTERN DOTS-1345678': '⣽', 'BRAILLE PATTERN DOTS-134568': '⢽', 'BRAILLE PATTERN DOTS-13457': '⡝', 'BRAILLE PATTERN DOTS-134578': '⣝', 'BRAILLE PATTERN DOTS-13458': '⢝', 'BRAILLE PATTERN DOTS-1346': '⠭', 'BRAILLE PATTERN DOTS-13467': '⡭', 'BRAILLE PATTERN DOTS-134678': '⣭', 'BRAILLE PATTERN DOTS-13468': '⢭', 'BRAILLE PATTERN DOTS-1347': '⡍', 'BRAILLE PATTERN DOTS-13478': '⣍', 'BRAILLE PATTERN DOTS-1348': '⢍', 'BRAILLE PATTERN DOTS-135': '⠕', 'BRAILLE PATTERN DOTS-1356': '⠵', 'BRAILLE PATTERN DOTS-13567': '⡵', 'BRAILLE PATTERN DOTS-135678': '⣵', 'BRAILLE PATTERN DOTS-13568': '⢵', 'BRAILLE PATTERN DOTS-1357': '⡕', 'BRAILLE PATTERN DOTS-13578': '⣕', 'BRAILLE PATTERN DOTS-1358': '⢕', 'BRAILLE PATTERN DOTS-136': '⠥', 'BRAILLE PATTERN DOTS-1367': '⡥', 'BRAILLE PATTERN DOTS-13678': '⣥', 'BRAILLE PATTERN DOTS-1368': '⢥', 'BRAILLE PATTERN DOTS-137': '⡅', 'BRAILLE PATTERN DOTS-1378': '⣅', 'BRAILLE PATTERN DOTS-138': '⢅', 'BRAILLE PATTERN DOTS-14': '⠉', 'BRAILLE PATTERN DOTS-145': '⠙', 'BRAILLE PATTERN DOTS-1456': '⠹', 'BRAILLE PATTERN DOTS-14567': '⡹', 'BRAILLE PATTERN DOTS-145678': '⣹', 'BRAILLE PATTERN DOTS-14568': '⢹', 'BRAILLE PATTERN DOTS-1457': '⡙', 'BRAILLE PATTERN DOTS-14578': '⣙', 'BRAILLE PATTERN DOTS-1458': '⢙', 'BRAILLE PATTERN DOTS-146': '⠩', 'BRAILLE PATTERN DOTS-1467': '⡩', 'BRAILLE PATTERN DOTS-14678': '⣩', 'BRAILLE PATTERN DOTS-1468': '⢩', 'BRAILLE PATTERN DOTS-147': '⡉', 'BRAILLE PATTERN DOTS-1478': '⣉', 'BRAILLE PATTERN DOTS-148': '⢉', 'BRAILLE PATTERN DOTS-15': '⠑', 'BRAILLE PATTERN DOTS-156': '⠱', 'BRAILLE PATTERN DOTS-1567': '⡱', 'BRAILLE PATTERN DOTS-15678': '⣱', 'BRAILLE PATTERN DOTS-1568': '⢱', 'BRAILLE PATTERN DOTS-157': '⡑', 'BRAILLE PATTERN DOTS-1578': '⣑', 'BRAILLE PATTERN DOTS-158': '⢑', 'BRAILLE PATTERN DOTS-16': '⠡', 'BRAILLE PATTERN DOTS-167': '⡡', 'BRAILLE PATTERN DOTS-1678': '⣡', 'BRAILLE PATTERN DOTS-168': '⢡', 'BRAILLE PATTERN DOTS-17': '⡁', 'BRAILLE PATTERN DOTS-178': '⣁', 'BRAILLE PATTERN DOTS-18': '⢁', 'BRAILLE PATTERN DOTS-2': '⠂', 'BRAILLE PATTERN DOTS-23': '⠆', 'BRAILLE PATTERN DOTS-234': '⠎', 'BRAILLE PATTERN DOTS-2345': '⠞', 'BRAILLE PATTERN DOTS-23456': '⠾', 'BRAILLE PATTERN DOTS-234567': '⡾', 'BRAILLE PATTERN DOTS-2345678': '⣾', 'BRAILLE PATTERN DOTS-234568': '⢾', 'BRAILLE PATTERN DOTS-23457': '⡞', 'BRAILLE PATTERN DOTS-234578': '⣞', 'BRAILLE PATTERN DOTS-23458': '⢞', 'BRAILLE PATTERN DOTS-2346': '⠮', 'BRAILLE PATTERN DOTS-23467': '⡮', 'BRAILLE PATTERN DOTS-234678': '⣮', 'BRAILLE PATTERN DOTS-23468': '⢮', 'BRAILLE PATTERN DOTS-2347': '⡎', 'BRAILLE PATTERN DOTS-23478': '⣎', 'BRAILLE PATTERN DOTS-2348': '⢎', 'BRAILLE PATTERN DOTS-235': '⠖', 'BRAILLE PATTERN DOTS-2356': '⠶', 'BRAILLE PATTERN DOTS-23567': '⡶', 'BRAILLE PATTERN DOTS-235678': '⣶', 'BRAILLE PATTERN DOTS-23568': '⢶', 'BRAILLE PATTERN DOTS-2357': '⡖', 'BRAILLE PATTERN DOTS-23578': '⣖', 'BRAILLE PATTERN DOTS-2358': '⢖', 'BRAILLE PATTERN DOTS-236': '⠦', 'BRAILLE PATTERN DOTS-2367': '⡦', 'BRAILLE PATTERN DOTS-23678': '⣦', 'BRAILLE PATTERN DOTS-2368': '⢦', 'BRAILLE PATTERN DOTS-237': '⡆', 'BRAILLE PATTERN DOTS-2378': '⣆', 'BRAILLE PATTERN DOTS-238': '⢆', 'BRAILLE PATTERN DOTS-24': '⠊', 'BRAILLE PATTERN DOTS-245': '⠚', 'BRAILLE PATTERN DOTS-2456': '⠺', 'BRAILLE PATTERN DOTS-24567': '⡺', 'BRAILLE PATTERN DOTS-245678': '⣺', 'BRAILLE PATTERN DOTS-24568': '⢺', 'BRAILLE PATTERN DOTS-2457': '⡚', 'BRAILLE PATTERN DOTS-24578': '⣚', 'BRAILLE PATTERN DOTS-2458': '⢚', 'BRAILLE PATTERN DOTS-246': '⠪', 'BRAILLE PATTERN DOTS-2467': '⡪', 'BRAILLE PATTERN DOTS-24678': '⣪', 'BRAILLE PATTERN DOTS-2468': '⢪', 'BRAILLE PATTERN DOTS-247': '⡊', 'BRAILLE PATTERN DOTS-2478': '⣊', 'BRAILLE PATTERN DOTS-248': '⢊', 'BRAILLE PATTERN DOTS-25': '⠒', 'BRAILLE PATTERN DOTS-256': '⠲', 'BRAILLE PATTERN DOTS-2567': '⡲', 'BRAILLE PATTERN DOTS-25678': '⣲', 'BRAILLE PATTERN DOTS-2568': '⢲', 'BRAILLE PATTERN DOTS-257': '⡒', 'BRAILLE PATTERN DOTS-2578': '⣒', 'BRAILLE PATTERN DOTS-258': '⢒', 'BRAILLE PATTERN DOTS-26': '⠢', 'BRAILLE PATTERN DOTS-267': '⡢', 'BRAILLE PATTERN DOTS-2678': '⣢', 'BRAILLE PATTERN DOTS-268': '⢢', 'BRAILLE PATTERN DOTS-27': '⡂', 'BRAILLE PATTERN DOTS-278': '⣂', 'BRAILLE PATTERN DOTS-28': '⢂', 'BRAILLE PATTERN DOTS-3': '⠄', 'BRAILLE PATTERN DOTS-34': '⠌', 'BRAILLE PATTERN DOTS-345': '⠜', 'BRAILLE PATTERN DOTS-3456': '⠼', 'BRAILLE PATTERN DOTS-34567': '⡼', 'BRAILLE PATTERN DOTS-345678': '⣼', 'BRAILLE PATTERN DOTS-34568': '⢼', 'BRAILLE PATTERN DOTS-3457': '⡜', 'BRAILLE PATTERN DOTS-34578': '⣜', 'BRAILLE PATTERN DOTS-3458': '⢜', 'BRAILLE PATTERN DOTS-346': '⠬', 'BRAILLE PATTERN DOTS-3467': '⡬', 'BRAILLE PATTERN DOTS-34678': '⣬', 'BRAILLE PATTERN DOTS-3468': '⢬', 'BRAILLE PATTERN DOTS-347': '⡌', 'BRAILLE PATTERN DOTS-3478': '⣌', 'BRAILLE PATTERN DOTS-348': '⢌', 'BRAILLE PATTERN DOTS-35': '⠔', 'BRAILLE PATTERN DOTS-356': '⠴', 'BRAILLE PATTERN DOTS-3567': '⡴', 'BRAILLE PATTERN DOTS-35678': '⣴', 'BRAILLE PATTERN DOTS-3568': '⢴', 'BRAILLE PATTERN DOTS-357': '⡔', 'BRAILLE PATTERN DOTS-3578': '⣔', 'BRAILLE PATTERN DOTS-358': '⢔', 'BRAILLE PATTERN DOTS-36': '⠤', 'BRAILLE PATTERN DOTS-367': '⡤', 'BRAILLE PATTERN DOTS-3678': '⣤', 'BRAILLE PATTERN DOTS-368': '⢤', 'BRAILLE PATTERN DOTS-37': '⡄', 'BRAILLE PATTERN DOTS-378': '⣄', 'BRAILLE PATTERN DOTS-38': '⢄', 'BRAILLE PATTERN DOTS-4': '⠈', 'BRAILLE PATTERN DOTS-45': '⠘', 'BRAILLE PATTERN DOTS-456': '⠸', 'BRAILLE PATTERN DOTS-4567': '⡸', 'BRAILLE PATTERN DOTS-45678': '⣸', 'BRAILLE PATTERN DOTS-4568': '⢸', 'BRAILLE PATTERN DOTS-457': '⡘', 'BRAILLE PATTERN DOTS-4578': '⣘', 'BRAILLE PATTERN DOTS-458': '⢘', 'BRAILLE PATTERN DOTS-46': '⠨', 'BRAILLE PATTERN DOTS-467': '⡨', 'BRAILLE PATTERN DOTS-4678': '⣨', 'BRAILLE PATTERN DOTS-468': '⢨', 'BRAILLE PATTERN DOTS-47': '⡈', 'BRAILLE PATTERN DOTS-478': '⣈', 'BRAILLE PATTERN DOTS-48': '⢈', 'BRAILLE PATTERN DOTS-5': '⠐', 'BRAILLE PATTERN DOTS-56': '⠰', 'BRAILLE PATTERN DOTS-567': '⡰', 'BRAILLE PATTERN DOTS-5678': '⣰', 'BRAILLE PATTERN DOTS-568': '⢰', 'BRAILLE PATTERN DOTS-57': '⡐', 'BRAILLE PATTERN DOTS-578': '⣐', 'BRAILLE PATTERN DOTS-58': '⢐', 'BRAILLE PATTERN DOTS-6': '⠠', 'BRAILLE PATTERN DOTS-67': '⡠', 'BRAILLE PATTERN DOTS-678': '⣠', 'BRAILLE PATTERN DOTS-68': '⢠', 'BRAILLE PATTERN DOTS-7': '⡀', 'BRAILLE PATTERN DOTS-78': '⣀', 'BRAILLE PATTERN DOTS-8': '⢀', 'EMPTY': ' '}
chars_in_order = {0: ' ', 1: '⠁', 2: '⠂', 3: '⠃', 4: '⠄', 5: '⠅', 6: '⠆', 7: '⠇', 8: '⠈', 9: '⠉', 10: '⠊', 11: '⠋', 12: '⠌', 13: '⠍', 14: '⠎', 15: '⠏', 16: '⠐', 17: '⠑', 18: '⠒', 19: '⠓', 20: '⠔', 21: '⠕', 22: '⠖', 23: '⠗', 24: '⠘', 25: '⠙', 26: '⠚', 27: '⠛', 28: '⠜', 29: '⠝', 30: '⠞', 31: '⠟', 32: '⠠', 33: '⠡', 34: '⠢', 35: '⠣', 36: '⠤', 37: '⠥', 38: '⠦', 39: '⠧', 40: '⠨', 41: '⠩', 42: '⠪', 43: '⠫', 44: '⠬', 45: '⠭', 46: '⠮', 47: '⠯', 48: '⠰', 49: '⠱', 50: '⠲', 51: '⠳', 52: '⠴', 53: '⠵', 54: '⠶', 55: '⠷', 56: '⠸', 57: '⠹', 58: '⠺', 59: '⠻', 60: '⠼', 61: '⠽', 62: '⠾', 63: '⠿', 64: '⡀', 65: '⡁', 66: '⡂', 67: '⡃', 68: '⡄', 69: '⡅', 70: '⡆', 71: '⡇', 72: '⡈', 73: '⡉', 74: '⡊', 75: '⡋', 76: '⡌', 77: '⡍', 78: '⡎', 79: '⡏', 80: '⡐', 81: '⡑', 82: '⡒', 83: '⡓', 84: '⡔', 85: '⡕', 86: '⡖', 87: '⡗', 88: '⡘', 89: '⡙', 90: '⡚', 91: '⡛', 92: '⡜', 93: '⡝', 94: '⡞', 95: '⡟', 96: '⡠', 97: '⡡', 98: '⡢', 99: '⡣', 100: '⡤', 101: '⡥', 102: '⡦', 103: '⡧', 104: '⡨', 105: '⡩', 106: '⡪', 107: '⡫', 108: '⡬', 109: '⡭', 110: '⡮', 111: '⡯', 112: '⡰', 113: '⡱', 114: '⡲', 115: '⡳', 116: '⡴', 117: '⡵', 118: '⡶', 119: '⡷', 120: '⡸', 121: '⡹', 122: '⡺', 123: '⡻', 124: '⡼', 125: '⡽', 126: '⡾', 127: '⡿', 128: '⢀', 129: '⢁', 130: '⢂', 131: '⢃', 132: '⢄', 133: '⢅', 134: '⢆', 135: '⢇', 136: '⢈', 137: '⢉', 138: '⢊', 139: '⢋', 140: '⢌', 141: '⢍', 142: '⢎', 143: '⢏', 144: '⢐', 145: '⢑', 146: '⢒', 147: '⢓', 148: '⢔', 149: '⢕', 150: '⢖', 151: '⢗', 152: '⢘', 153: '⢙', 154: '⢚', 155: '⢛', 156: '⢜', 157: '⢝', 158: '⢞', 159: '⢟', 160: '⢠', 161: '⢡', 162: '⢢', 163: '⢣', 164: '⢤', 165: '⢥', 166: '⢦', 167: '⢧', 168: '⢨', 169: '⢩', 170: '⢪', 171: '⢫', 172: '⢬', 173: '⢭', 174: '⢮', 175: '⢯', 176: '⢰', 177: '⢱', 178: '⢲', 179: '⢳', 180: '⢴', 181: '⢵', 182: '⢶', 183: '⢷', 184: '⢸', 185: '⢹', 186: '⢺', 187: '⢻', 188: '⢼', 189: '⢽', 190: '⢾', 191: '⢿', 192: '⣀', 193: '⣁', 194: '⣂', 195: '⣃', 196: '⣄', 197: '⣅', 198: '⣆', 199: '⣇', 200: '⣈', 201: '⣉', 202: '⣊', 203: '⣋', 204: '⣌', 205: '⣍', 206: '⣎', 207: '⣏', 208: '⣐', 209: '⣑', 210: '⣒', 211: '⣓', 212: '⣔', 213: '⣕', 214: '⣖', 215: '⣗', 216: '⣘', 217: '⣙', 218: '⣚', 219: '⣛', 220: '⣜', 221: '⣝', 222: '⣞', 223: '⣟', 224: '⣠', 225: '⣡', 226: '⣢', 227: '⣣', 228: '⣤', 229: '⣥', 230: '⣦', 231: '⣧', 232: '⣨', 233: '⣩', 234: '⣪', 235: '⣫', 236: '⣬', 237: '⣭', 238: '⣮', 239: '⣯', 240: '⣰', 241: '⣱', 242: '⣲', 243: '⣳', 244: '⣴', 245: '⣵', 246: '⣶', 247: '⣷', 248: '⣸', 249: '⣹', 250: '⣺', 251: '⣻', 252: '⣼', 253: '⣽', 254: '⣾', 255: '⣿'}
chars_to_name = {' ': 'EMPTY', '⠁': 'BRAILLE PATTERN DOTS-1', '⠂': 'BRAILLE PATTERN DOTS-2', '⠃': 'BRAILLE PATTERN DOTS-12', '⠄': 'BRAILLE PATTERN DOTS-3', '⠅': 'BRAILLE PATTERN DOTS-13', '⠆': 'BRAILLE PATTERN DOTS-23', '⠇': 'BRAILLE PATTERN DOTS-123', '⠈': 'BRAILLE PATTERN DOTS-4', '⠉': 'BRAILLE PATTERN DOTS-14', '⠊': 'BRAILLE PATTERN DOTS-24', '⠋': 'BRAILLE PATTERN DOTS-124', '⠌': 'BRAILLE PATTERN DOTS-34', '⠍': 'BRAILLE PATTERN DOTS-134', '⠎': 'BRAILLE PATTERN DOTS-234', '⠏': 'BRAILLE PATTERN DOTS-1234', '⠐': 'BRAILLE PATTERN DOTS-5', '⠑': 'BRAILLE PATTERN DOTS-15', '⠒': 'BRAILLE PATTERN DOTS-25', '⠓': 'BRAILLE PATTERN DOTS-125', '⠔': 'BRAILLE PATTERN DOTS-35', '⠕': 'BRAILLE PATTERN DOTS-135', '⠖': 'BRAILLE PATTERN DOTS-235', '⠗': 'BRAILLE PATTERN DOTS-1235', '⠘': 'BRAILLE PATTERN DOTS-45', '⠙': 'BRAILLE PATTERN DOTS-145', '⠚': 'BRAILLE PATTERN DOTS-245', '⠛': 'BRAILLE PATTERN DOTS-1245', '⠜': 'BRAILLE PATTERN DOTS-345', '⠝': 'BRAILLE PATTERN DOTS-1345', '⠞': 'BRAILLE PATTERN DOTS-2345', '⠟': 'BRAILLE PATTERN DOTS-12345', '⠠': 'BRAILLE PATTERN DOTS-6', '⠡': 'BRAILLE PATTERN DOTS-16', '⠢': 'BRAILLE PATTERN DOTS-26', '⠣': 'BRAILLE PATTERN DOTS-126', '⠤': 'BRAILLE PATTERN DOTS-36', '⠥': 'BRAILLE PATTERN DOTS-136', '⠦': 'BRAILLE PATTERN DOTS-236', '⠧': 'BRAILLE PATTERN DOTS-1236', '⠨': 'BRAILLE PATTERN DOTS-46', '⠩': 'BRAILLE PATTERN DOTS-146', '⠪': 'BRAILLE PATTERN DOTS-246', '⠫': 'BRAILLE PATTERN DOTS-1246', '⠬': 'BRAILLE PATTERN DOTS-346', '⠭': 'BRAILLE PATTERN DOTS-1346', '⠮': 'BRAILLE PATTERN DOTS-2346', '⠯': 'BRAILLE PATTERN DOTS-12346', '⠰': 'BRAILLE PATTERN DOTS-56', '⠱': 'BRAILLE PATTERN DOTS-156', '⠲': 'BRAILLE PATTERN DOTS-256', '⠳': 'BRAILLE PATTERN DOTS-1256', '⠴': 'BRAILLE PATTERN DOTS-356', '⠵': 'BRAILLE PATTERN DOTS-1356', '⠶': 'BRAILLE PATTERN DOTS-2356', '⠷': 'BRAILLE PATTERN DOTS-12356', '⠸': 'BRAILLE PATTERN DOTS-456', '⠹': 'BRAILLE PATTERN DOTS-1456', '⠺': 'BRAILLE PATTERN DOTS-2456', '⠻': 'BRAILLE PATTERN DOTS-12456', '⠼': 'BRAILLE PATTERN DOTS-3456', '⠽': 'BRAILLE PATTERN DOTS-13456', '⠾': 'BRAILLE PATTERN DOTS-23456', '⠿': 'BRAILLE PATTERN DOTS-123456', '⡀': 'BRAILLE PATTERN DOTS-7', '⡁': 'BRAILLE PATTERN DOTS-17', '⡂': 'BRAILLE PATTERN DOTS-27', '⡃': 'BRAILLE PATTERN DOTS-127', '⡄': 'BRAILLE PATTERN DOTS-37', '⡅': 'BRAILLE PATTERN DOTS-137', '⡆': 'BRAILLE PATTERN DOTS-237', '⡇': 'BRAILLE PATTERN DOTS-1237', '⡈': 'BRAILLE PATTERN DOTS-47', '⡉': 'BRAILLE PATTERN DOTS-147', '⡊': 'BRAILLE PATTERN DOTS-247', '⡋': 'BRAILLE PATTERN DOTS-1247', '⡌': 'BRAILLE PATTERN DOTS-347', '⡍': 'BRAILLE PATTERN DOTS-1347', '⡎': 'BRAILLE PATTERN DOTS-2347', '⡏': 'BRAILLE PATTERN DOTS-12347', '⡐': 'BRAILLE PATTERN DOTS-57', '⡑': 'BRAILLE PATTERN DOTS-157', '⡒': 'BRAILLE PATTERN DOTS-257', '⡓': 'BRAILLE PATTERN DOTS-1257', '⡔': 'BRAILLE PATTERN DOTS-357', '⡕': 'BRAILLE PATTERN DOTS-1357', '⡖': 'BRAILLE PATTERN DOTS-2357', '⡗': 'BRAILLE PATTERN DOTS-12357', '⡘': 'BRAILLE PATTERN DOTS-457', '⡙': 'BRAILLE PATTERN DOTS-1457', '⡚': 'BRAILLE PATTERN DOTS-2457', '⡛': 'BRAILLE PATTERN DOTS-12457', '⡜': 'BRAILLE PATTERN DOTS-3457', '⡝': 'BRAILLE PATTERN DOTS-13457', '⡞': 'BRAILLE PATTERN DOTS-23457', '⡟': 'BRAILLE PATTERN DOTS-123457', '⡠': 'BRAILLE PATTERN DOTS-67', '⡡': 'BRAILLE PATTERN DOTS-167', '⡢': 'BRAILLE PATTERN DOTS-267', '⡣': 'BRAILLE PATTERN DOTS-1267', '⡤': 'BRAILLE PATTERN DOTS-367', '⡥': 'BRAILLE PATTERN DOTS-1367', '⡦': 'BRAILLE PATTERN DOTS-2367', '⡧': 'BRAILLE PATTERN DOTS-12367', '⡨': 'BRAILLE PATTERN DOTS-467', '⡩': 'BRAILLE PATTERN DOTS-1467', '⡪': 'BRAILLE PATTERN DOTS-2467', '⡫': 'BRAILLE PATTERN DOTS-12467', '⡬': 'BRAILLE PATTERN DOTS-3467', '⡭': 'BRAILLE PATTERN DOTS-13467', '⡮': 'BRAILLE PATTERN DOTS-23467', '⡯': 'BRAILLE PATTERN DOTS-123467', '⡰': 'BRAILLE PATTERN DOTS-567', '⡱': 'BRAILLE PATTERN DOTS-1567', '⡲': 'BRAILLE PATTERN DOTS-2567', '⡳': 'BRAILLE PATTERN DOTS-12567', '⡴': 'BRAILLE PATTERN DOTS-3567', '⡵': 'BRAILLE PATTERN DOTS-13567', '⡶': 'BRAILLE PATTERN DOTS-23567', '⡷': 'BRAILLE PATTERN DOTS-123567', '⡸': 'BRAILLE PATTERN DOTS-4567', '⡹': 'BRAILLE PATTERN DOTS-14567', '⡺': 'BRAILLE PATTERN DOTS-24567', '⡻': 'BRAILLE PATTERN DOTS-124567', '⡼': 'BRAILLE PATTERN DOTS-34567', '⡽': 'BRAILLE PATTERN DOTS-134567', '⡾': 'BRAILLE PATTERN DOTS-234567', '⡿': 'BRAILLE PATTERN DOTS-1234567', '⢀': 'BRAILLE PATTERN DOTS-8', '⢁': 'BRAILLE PATTERN DOTS-18', '⢂': 'BRAILLE PATTERN DOTS-28', '⢃': 'BRAILLE PATTERN DOTS-128', '⢄': 'BRAILLE PATTERN DOTS-38', '⢅': 'BRAILLE PATTERN DOTS-138', '⢆': 'BRAILLE PATTERN DOTS-238', '⢇': 'BRAILLE PATTERN DOTS-1238', '⢈': 'BRAILLE PATTERN DOTS-48', '⢉': 'BRAILLE PATTERN DOTS-148', '⢊': 'BRAILLE PATTERN DOTS-248', '⢋': 'BRAILLE PATTERN DOTS-1248', '⢌': 'BRAILLE PATTERN DOTS-348', '⢍': 'BRAILLE PATTERN DOTS-1348', '⢎': 'BRAILLE PATTERN DOTS-2348', '⢏': 'BRAILLE PATTERN DOTS-12348', '⢐': 'BRAILLE PATTERN DOTS-58', '⢑': 'BRAILLE PATTERN DOTS-158', '⢒': 'BRAILLE PATTERN DOTS-258', '⢓': 'BRAILLE PATTERN DOTS-1258', '⢔': 'BRAILLE PATTERN DOTS-358', '⢕': 'BRAILLE PATTERN DOTS-1358', '⢖': 'BRAILLE PATTERN DOTS-2358', '⢗': 'BRAILLE PATTERN DOTS-12358', '⢘': 'BRAILLE PATTERN DOTS-458', '⢙': 'BRAILLE PATTERN DOTS-1458', '⢚': 'BRAILLE PATTERN DOTS-2458', '⢛': 'BRAILLE PATTERN DOTS-12458', '⢜': 'BRAILLE PATTERN DOTS-3458', '⢝': 'BRAILLE PATTERN DOTS-13458', '⢞': 'BRAILLE PATTERN DOTS-23458', '⢟': 'BRAILLE PATTERN DOTS-123458', '⢠': 'BRAILLE PATTERN DOTS-68', '⢡': 'BRAILLE PATTERN DOTS-168', '⢢': 'BRAILLE PATTERN DOTS-268', '⢣': 'BRAILLE PATTERN DOTS-1268', '⢤': 'BRAILLE PATTERN DOTS-368', '⢥': 'BRAILLE PATTERN DOTS-1368', '⢦': 'BRAILLE PATTERN DOTS-2368', '⢧': 'BRAILLE PATTERN DOTS-12368', '⢨': 'BRAILLE PATTERN DOTS-468', '⢩': 'BRAILLE PATTERN DOTS-1468', '⢪': 'BRAILLE PATTERN DOTS-2468', '⢫': 'BRAILLE PATTERN DOTS-12468', '⢬': 'BRAILLE PATTERN DOTS-3468', '⢭': 'BRAILLE PATTERN DOTS-13468', '⢮': 'BRAILLE PATTERN DOTS-23468', '⢯': 'BRAILLE PATTERN DOTS-123468', '⢰': 'BRAILLE PATTERN DOTS-568', '⢱': 'BRAILLE PATTERN DOTS-1568', '⢲': 'BRAILLE PATTERN DOTS-2568', '⢳': 'BRAILLE PATTERN DOTS-12568', '⢴': 'BRAILLE PATTERN DOTS-3568', '⢵': 'BRAILLE PATTERN DOTS-13568', '⢶': 'BRAILLE PATTERN DOTS-23568', '⢷': 'BRAILLE PATTERN DOTS-123568', '⢸': 'BRAILLE PATTERN DOTS-4568', '⢹': 'BRAILLE PATTERN DOTS-14568', '⢺': 'BRAILLE PATTERN DOTS-24568', '⢻': 'BRAILLE PATTERN DOTS-124568', '⢼': 'BRAILLE PATTERN DOTS-34568', '⢽': 'BRAILLE PATTERN DOTS-134568', '⢾': 'BRAILLE PATTERN DOTS-234568', '⢿': 'BRAILLE PATTERN DOTS-1234568', '⣀': 'BRAILLE PATTERN DOTS-78', '⣁': 'BRAILLE PATTERN DOTS-178', '⣂': 'BRAILLE PATTERN DOTS-278', '⣃': 'BRAILLE PATTERN DOTS-1278', '⣄': 'BRAILLE PATTERN DOTS-378', '⣅': 'BRAILLE PATTERN DOTS-1378', '⣆': 'BRAILLE PATTERN DOTS-2378', '⣇': 'BRAILLE PATTERN DOTS-12378', '⣈': 'BRAILLE PATTERN DOTS-478', '⣉': 'BRAILLE PATTERN DOTS-1478', '⣊': 'BRAILLE PATTERN DOTS-2478', '⣋': 'BRAILLE PATTERN DOTS-12478', '⣌': 'BRAILLE PATTERN DOTS-3478', '⣍': 'BRAILLE PATTERN DOTS-13478', '⣎': 'BRAILLE PATTERN DOTS-23478', '⣏': 'BRAILLE PATTERN DOTS-123478', '⣐': 'BRAILLE PATTERN DOTS-578', '⣑': 'BRAILLE PATTERN DOTS-1578', '⣒': 'BRAILLE PATTERN DOTS-2578', '⣓': 'BRAILLE PATTERN DOTS-12578', '⣔': 'BRAILLE PATTERN DOTS-3578', '⣕': 'BRAILLE PATTERN DOTS-13578', '⣖': 'BRAILLE PATTERN DOTS-23578', '⣗': 'BRAILLE PATTERN DOTS-123578', '⣘': 'BRAILLE PATTERN DOTS-4578', '⣙': 'BRAILLE PATTERN DOTS-14578', '⣚': 'BRAILLE PATTERN DOTS-24578', '⣛': 'BRAILLE PATTERN DOTS-124578', '⣜': 'BRAILLE PATTERN DOTS-34578', '⣝': 'BRAILLE PATTERN DOTS-134578', '⣞': 'BRAILLE PATTERN DOTS-234578', '⣟': 'BRAILLE PATTERN DOTS-1234578', '⣠': 'BRAILLE PATTERN DOTS-678', '⣡': 'BRAILLE PATTERN DOTS-1678', '⣢': 'BRAILLE PATTERN DOTS-2678', '⣣': 'BRAILLE PATTERN DOTS-12678', '⣤': 'BRAILLE PATTERN DOTS-3678', '⣥': 'BRAILLE PATTERN DOTS-13678', '⣦': 'BRAILLE PATTERN DOTS-23678', '⣧': 'BRAILLE PATTERN DOTS-123678', '⣨': 'BRAILLE PATTERN DOTS-4678', '⣩': 'BRAILLE PATTERN DOTS-14678', '⣪': 'BRAILLE PATTERN DOTS-24678', '⣫': 'BRAILLE PATTERN DOTS-124678', '⣬': 'BRAILLE PATTERN DOTS-34678', '⣭': 'BRAILLE PATTERN DOTS-134678', '⣮': 'BRAILLE PATTERN DOTS-234678', '⣯': 'BRAILLE PATTERN DOTS-1234678', '⣰': 'BRAILLE PATTERN DOTS-5678', '⣱': 'BRAILLE PATTERN DOTS-15678', '⣲': 'BRAILLE PATTERN DOTS-25678', '⣳': 'BRAILLE PATTERN DOTS-125678', '⣴': 'BRAILLE PATTERN DOTS-35678', '⣵': 'BRAILLE PATTERN DOTS-135678', '⣶': 'BRAILLE PATTERN DOTS-235678', '⣷': 'BRAILLE PATTERN DOTS-1235678', '⣸': 'BRAILLE PATTERN DOTS-45678', '⣹': 'BRAILLE PATTERN DOTS-145678', '⣺': 'BRAILLE PATTERN DOTS-245678', '⣻': 'BRAILLE PATTERN DOTS-1245678', '⣼': 'BRAILLE PATTERN DOTS-345678', '⣽': 'BRAILLE PATTERN DOTS-1345678', '⣾': 'BRAILLE PATTERN DOTS-2345678', '⣿': 'BRAILLE PATTERN DOTS-12345678'}
chars_to_order = {' ': 0, '⠁': 1, '⠂': 2, '⠃': 3, '⠄': 4, '⠅': 5, '⠆': 6, '⠇': 7, '⠈': 8, '⠉': 9, '⠊': 10, '⠋': 11, '⠌': 12, '⠍': 13, '⠎': 14, '⠏': 15, '⠐': 16, '⠑': 17, '⠒': 18, '⠓': 19, '⠔': 20, '⠕': 21, '⠖': 22, '⠗': 23, '⠘': 24, '⠙': 25, '⠚': 26, '⠛': 27, '⠜': 28, '⠝': 29, '⠞': 30, '⠟': 31, '⠠': 32, '⠡': 33, '⠢': 34, '⠣': 35, '⠤': 36, '⠥': 37, '⠦': 38, '⠧': 39, '⠨': 40, '⠩': 41, '⠪': 42, '⠫': 43, '⠬': 44, '⠭': 45, '⠮': 46, '⠯': 47, '⠰': 48, '⠱': 49, '⠲': 50, '⠳': 51, '⠴': 52, '⠵': 53, '⠶': 54, '⠷': 55, '⠸': 56, '⠹': 57, '⠺': 58, '⠻': 59, '⠼': 60, '⠽': 61, '⠾': 62, '⠿': 63, '⡀': 64, '⡁': 65, '⡂': 66, '⡃': 67, '⡄': 68, '⡅': 69, '⡆': 70, '⡇': 71, '⡈': 72, '⡉': 73, '⡊': 74, '⡋': 75, '⡌': 76, '⡍': 77, '⡎': 78, '⡏': 79, '⡐': 80, '⡑': 81, '⡒': 82, '⡓': 83, '⡔': 84, '⡕': 85, '⡖': 86, '⡗': 87, '⡘': 88, '⡙': 89, '⡚': 90, '⡛': 91, '⡜': 92, '⡝': 93, '⡞': 94, '⡟': 95, '⡠': 96, '⡡': 97, '⡢': 98, '⡣': 99, '⡤': 100, '⡥': 101, '⡦': 102, '⡧': 103, '⡨': 104, '⡩': 105, '⡪': 106, '⡫': 107, '⡬': 108, '⡭': 109, '⡮': 110, '⡯': 111, '⡰': 112, '⡱': 113, '⡲': 114, '⡳': 115, '⡴': 116, '⡵': 117, '⡶': 118, '⡷': 119, '⡸': 120, '⡹': 121, '⡺': 122, '⡻': 123, '⡼': 124, '⡽': 125, '⡾': 126, '⡿': 127, '⢀': 128, '⢁': 129, '⢂': 130, '⢃': 131, '⢄': 132, '⢅': 133, '⢆': 134, '⢇': 135, '⢈': 136, '⢉': 137, '⢊': 138, '⢋': 139, '⢌': 140, '⢍': 141, '⢎': 142, '⢏': 143, '⢐': 144, '⢑': 145, '⢒': 146, '⢓': 147, '⢔': 148, '⢕': 149, '⢖': 150, '⢗': 151, '⢘': 152, '⢙': 153, '⢚': 154, '⢛': 155, '⢜': 156, '⢝': 157, '⢞': 158, '⢟': 159, '⢠': 160, '⢡': 161, '⢢': 162, '⢣': 163, '⢤': 164, '⢥': 165, '⢦': 166, '⢧': 167, '⢨': 168, '⢩': 169, '⢪': 170, '⢫': 171, '⢬': 172, '⢭': 173, '⢮': 174, '⢯': 175, '⢰': 176, '⢱': 177, '⢲': 178, '⢳': 179, '⢴': 180, '⢵': 181, '⢶': 182, '⢷': 183, '⢸': 184, '⢹': 185, '⢺': 186, '⢻': 187, '⢼': 188, '⢽': 189, '⢾': 190, '⢿': 191, '⣀': 192, '⣁': 193, '⣂': 194, '⣃': 195, '⣄': 196, '⣅': 197, '⣆': 198, '⣇': 199, '⣈': 200, '⣉': 201, '⣊': 202, '⣋': 203, '⣌': 204, '⣍': 205, '⣎': 206, '⣏': 207, '⣐': 208, '⣑': 209, '⣒': 210, '⣓': 211, '⣔': 212, '⣕': 213, '⣖': 214, '⣗': 215, '⣘': 216, '⣙': 217, '⣚': 218, '⣛': 219, '⣜': 220, '⣝': 221, '⣞': 222, '⣟': 223, '⣠': 224, '⣡': 225, '⣢': 226, '⣣': 227, '⣤': 228, '⣥': 229, '⣦': 230, '⣧': 231, '⣨': 232, '⣩': 233, '⣪': 234, '⣫': 235, '⣬': 236, '⣭': 237, '⣮': 238, '⣯': 239, '⣰': 240, '⣱': 241, '⣲': 242, '⣳': 243, '⣴': 244, '⣵': 245, '⣶': 246, '⣷': 247, '⣸': 248, '⣹': 249, '⣺': 250, '⣻': 251, '⣼': 252, '⣽': 253, '⣾': 254, '⣿': 255}
class terminedia.subpixels.HalfChars_

Bases: terminedia.subpixels.SubPixels

Used internally to emulate pixel setting/resetting/reading inside 1/2 Character Blocks

EMPTY = ' '
FULL_BLOCK = '█'
LOWER_HALF_BLOCK = '▄'
UPPER_HALF_BLOCK = '▀'
bit_size = 3
block_height = 2
block_width = 1
chars = {' ', '▀', '▄', '█'}
chars_by_name = {'EMPTY': ' ', 'FULL_BLOCK': '█', 'LOWER_HALF_BLOCK': '▄', 'UPPER_HALF_BLOCK': '▀'}
chars_in_order = {0: ' ', 1: '▀', 2: '▄', 3: '█'}
chars_to_name = {' ': 'EMPTY', '▀': 'UPPER_HALF_BLOCK', '▄': 'LOWER_HALF_BLOCK', '█': 'FULL_BLOCK'}
chars_to_order = {' ': 0, '▀': 1, '▄': 2, '█': 3}
class terminedia.subpixels.SextantChars_

Bases: terminedia.subpixels.SubPixels

Used internally to emulate pixel setting/resetting/reading inside 1/6 Unicode Legacy Computing characters

EMPTY = ' '
FULL_BLOCK = '█'
LEFT_HALF_BLOCK = '▌'
RIGHT_HALF_BLOCK = '▐'
bit_size = 63
block_height = 3
block_width = 2
chars = {' ', '█', '▌', '▐', '\U0001fb00', '\U0001fb01', '\U0001fb02', '\U0001fb03', '\U0001fb04', '\U0001fb05', '\U0001fb06', '\U0001fb07', '\U0001fb08', '\U0001fb09', '\U0001fb0a', '\U0001fb0b', '\U0001fb0c', '\U0001fb0d', '\U0001fb0e', '\U0001fb0f', '\U0001fb10', '\U0001fb11', '\U0001fb12', '\U0001fb13', '\U0001fb14', '\U0001fb15', '\U0001fb16', '\U0001fb17', '\U0001fb18', '\U0001fb19', '\U0001fb1a', '\U0001fb1b', '\U0001fb1c', '\U0001fb1d', '\U0001fb1e', '\U0001fb1f', '\U0001fb20', '\U0001fb21', '\U0001fb22', '\U0001fb23', '\U0001fb24', '\U0001fb25', '\U0001fb26', '\U0001fb27', '\U0001fb28', '\U0001fb29', '\U0001fb2a', '\U0001fb2b', '\U0001fb2c', '\U0001fb2d', '\U0001fb2e', '\U0001fb2f', '\U0001fb30', '\U0001fb31', '\U0001fb32', '\U0001fb33', '\U0001fb34', '\U0001fb35', '\U0001fb36', '\U0001fb37', '\U0001fb38', '\U0001fb39', '\U0001fb3a', '\U0001fb3b'}
chars_by_name = {'EMPTY': ' ', 'FULL_BLOCK': '█', 'LEFT_HALF_BLOCK': '▌', 'RIGHT_HALF_BLOCK': '▐', 'SEXTANT CHAR 00 PROVISIONAL)': '\U0001fb00', 'SEXTANT CHAR 01 PROVISIONAL)': '\U0001fb01', 'SEXTANT CHAR 02 PROVISIONAL)': '\U0001fb02', 'SEXTANT CHAR 03 PROVISIONAL)': '\U0001fb03', 'SEXTANT CHAR 04 PROVISIONAL)': '\U0001fb04', 'SEXTANT CHAR 05 PROVISIONAL)': '\U0001fb05', 'SEXTANT CHAR 06 PROVISIONAL)': '\U0001fb06', 'SEXTANT CHAR 07 PROVISIONAL)': '\U0001fb07', 'SEXTANT CHAR 08 PROVISIONAL)': '\U0001fb08', 'SEXTANT CHAR 09 PROVISIONAL)': '\U0001fb09', 'SEXTANT CHAR 10 PROVISIONAL)': '\U0001fb0a', 'SEXTANT CHAR 11 PROVISIONAL)': '\U0001fb0b', 'SEXTANT CHAR 12 PROVISIONAL)': '\U0001fb0c', 'SEXTANT CHAR 13 PROVISIONAL)': '\U0001fb0d', 'SEXTANT CHAR 14 PROVISIONAL)': '\U0001fb0e', 'SEXTANT CHAR 15 PROVISIONAL)': '\U0001fb0f', 'SEXTANT CHAR 16 PROVISIONAL)': '\U0001fb10', 'SEXTANT CHAR 17 PROVISIONAL)': '\U0001fb11', 'SEXTANT CHAR 18 PROVISIONAL)': '\U0001fb12', 'SEXTANT CHAR 19 PROVISIONAL)': '\U0001fb13', 'SEXTANT CHAR 20 PROVISIONAL)': '\U0001fb14', 'SEXTANT CHAR 21 PROVISIONAL)': '\U0001fb15', 'SEXTANT CHAR 22 PROVISIONAL)': '\U0001fb16', 'SEXTANT CHAR 23 PROVISIONAL)': '\U0001fb17', 'SEXTANT CHAR 24 PROVISIONAL)': '\U0001fb18', 'SEXTANT CHAR 25 PROVISIONAL)': '\U0001fb19', 'SEXTANT CHAR 26 PROVISIONAL)': '\U0001fb1a', 'SEXTANT CHAR 27 PROVISIONAL)': '\U0001fb1b', 'SEXTANT CHAR 28 PROVISIONAL)': '\U0001fb1c', 'SEXTANT CHAR 29 PROVISIONAL)': '\U0001fb1d', 'SEXTANT CHAR 30 PROVISIONAL)': '\U0001fb1e', 'SEXTANT CHAR 31 PROVISIONAL)': '\U0001fb1f', 'SEXTANT CHAR 32 PROVISIONAL)': '\U0001fb20', 'SEXTANT CHAR 33 PROVISIONAL)': '\U0001fb21', 'SEXTANT CHAR 34 PROVISIONAL)': '\U0001fb22', 'SEXTANT CHAR 35 PROVISIONAL)': '\U0001fb23', 'SEXTANT CHAR 36 PROVISIONAL)': '\U0001fb24', 'SEXTANT CHAR 37 PROVISIONAL)': '\U0001fb25', 'SEXTANT CHAR 38 PROVISIONAL)': '\U0001fb26', 'SEXTANT CHAR 39 PROVISIONAL)': '\U0001fb27', 'SEXTANT CHAR 40 PROVISIONAL)': '\U0001fb28', 'SEXTANT CHAR 41 PROVISIONAL)': '\U0001fb29', 'SEXTANT CHAR 42 PROVISIONAL)': '\U0001fb2a', 'SEXTANT CHAR 43 PROVISIONAL)': '\U0001fb2b', 'SEXTANT CHAR 44 PROVISIONAL)': '\U0001fb2c', 'SEXTANT CHAR 45 PROVISIONAL)': '\U0001fb2d', 'SEXTANT CHAR 46 PROVISIONAL)': '\U0001fb2e', 'SEXTANT CHAR 47 PROVISIONAL)': '\U0001fb2f', 'SEXTANT CHAR 48 PROVISIONAL)': '\U0001fb30', 'SEXTANT CHAR 49 PROVISIONAL)': '\U0001fb31', 'SEXTANT CHAR 50 PROVISIONAL)': '\U0001fb32', 'SEXTANT CHAR 51 PROVISIONAL)': '\U0001fb33', 'SEXTANT CHAR 52 PROVISIONAL)': '\U0001fb34', 'SEXTANT CHAR 53 PROVISIONAL)': '\U0001fb35', 'SEXTANT CHAR 54 PROVISIONAL)': '\U0001fb36', 'SEXTANT CHAR 55 PROVISIONAL)': '\U0001fb37', 'SEXTANT CHAR 56 PROVISIONAL)': '\U0001fb38', 'SEXTANT CHAR 57 PROVISIONAL)': '\U0001fb39', 'SEXTANT CHAR 58 PROVISIONAL)': '\U0001fb3a', 'SEXTANT CHAR 59 PROVISIONAL)': '\U0001fb3b'}
chars_in_order = {0: ' ', 1: '\U0001fb00', 2: '\U0001fb01', 3: '\U0001fb02', 4: '\U0001fb03', 5: '\U0001fb04', 6: '\U0001fb05', 7: '\U0001fb06', 8: '\U0001fb07', 9: '\U0001fb08', 10: '\U0001fb09', 11: '\U0001fb0a', 12: '\U0001fb0b', 13: '\U0001fb0c', 14: '\U0001fb0d', 15: '\U0001fb0e', 16: '\U0001fb0f', 17: '\U0001fb10', 18: '\U0001fb11', 19: '\U0001fb12', 20: '\U0001fb13', 21: '▌', 22: '\U0001fb14', 23: '\U0001fb15', 24: '\U0001fb16', 25: '\U0001fb17', 26: '\U0001fb18', 27: '\U0001fb19', 28: '\U0001fb1a', 29: '\U0001fb1b', 30: '\U0001fb1c', 31: '\U0001fb1d', 32: '\U0001fb1e', 33: '\U0001fb1f', 34: '\U0001fb20', 35: '\U0001fb21', 36: '\U0001fb22', 37: '\U0001fb23', 38: '\U0001fb24', 39: '\U0001fb25', 40: '\U0001fb26', 41: '\U0001fb27', 42: '▐', 43: '\U0001fb28', 44: '\U0001fb29', 45: '\U0001fb2a', 46: '\U0001fb2b', 47: '\U0001fb2c', 48: '\U0001fb2d', 49: '\U0001fb2e', 50: '\U0001fb2f', 51: '\U0001fb30', 52: '\U0001fb31', 53: '\U0001fb32', 54: '\U0001fb33', 55: '\U0001fb34', 56: '\U0001fb35', 57: '\U0001fb36', 58: '\U0001fb37', 59: '\U0001fb38', 60: '\U0001fb39', 61: '\U0001fb3a', 62: '\U0001fb3b', 63: '█'}
chars_to_name = {' ': 'EMPTY', '█': 'FULL_BLOCK', '▌': 'LEFT_HALF_BLOCK', '▐': 'RIGHT_HALF_BLOCK', '\U0001fb00': 'SEXTANT CHAR 00 PROVISIONAL)', '\U0001fb01': 'SEXTANT CHAR 01 PROVISIONAL)', '\U0001fb02': 'SEXTANT CHAR 02 PROVISIONAL)', '\U0001fb03': 'SEXTANT CHAR 03 PROVISIONAL)', '\U0001fb04': 'SEXTANT CHAR 04 PROVISIONAL)', '\U0001fb05': 'SEXTANT CHAR 05 PROVISIONAL)', '\U0001fb06': 'SEXTANT CHAR 06 PROVISIONAL)', '\U0001fb07': 'SEXTANT CHAR 07 PROVISIONAL)', '\U0001fb08': 'SEXTANT CHAR 08 PROVISIONAL)', '\U0001fb09': 'SEXTANT CHAR 09 PROVISIONAL)', '\U0001fb0a': 'SEXTANT CHAR 10 PROVISIONAL)', '\U0001fb0b': 'SEXTANT CHAR 11 PROVISIONAL)', '\U0001fb0c': 'SEXTANT CHAR 12 PROVISIONAL)', '\U0001fb0d': 'SEXTANT CHAR 13 PROVISIONAL)', '\U0001fb0e': 'SEXTANT CHAR 14 PROVISIONAL)', '\U0001fb0f': 'SEXTANT CHAR 15 PROVISIONAL)', '\U0001fb10': 'SEXTANT CHAR 16 PROVISIONAL)', '\U0001fb11': 'SEXTANT CHAR 17 PROVISIONAL)', '\U0001fb12': 'SEXTANT CHAR 18 PROVISIONAL)', '\U0001fb13': 'SEXTANT CHAR 19 PROVISIONAL)', '\U0001fb14': 'SEXTANT CHAR 20 PROVISIONAL)', '\U0001fb15': 'SEXTANT CHAR 21 PROVISIONAL)', '\U0001fb16': 'SEXTANT CHAR 22 PROVISIONAL)', '\U0001fb17': 'SEXTANT CHAR 23 PROVISIONAL)', '\U0001fb18': 'SEXTANT CHAR 24 PROVISIONAL)', '\U0001fb19': 'SEXTANT CHAR 25 PROVISIONAL)', '\U0001fb1a': 'SEXTANT CHAR 26 PROVISIONAL)', '\U0001fb1b': 'SEXTANT CHAR 27 PROVISIONAL)', '\U0001fb1c': 'SEXTANT CHAR 28 PROVISIONAL)', '\U0001fb1d': 'SEXTANT CHAR 29 PROVISIONAL)', '\U0001fb1e': 'SEXTANT CHAR 30 PROVISIONAL)', '\U0001fb1f': 'SEXTANT CHAR 31 PROVISIONAL)', '\U0001fb20': 'SEXTANT CHAR 32 PROVISIONAL)', '\U0001fb21': 'SEXTANT CHAR 33 PROVISIONAL)', '\U0001fb22': 'SEXTANT CHAR 34 PROVISIONAL)', '\U0001fb23': 'SEXTANT CHAR 35 PROVISIONAL)', '\U0001fb24': 'SEXTANT CHAR 36 PROVISIONAL)', '\U0001fb25': 'SEXTANT CHAR 37 PROVISIONAL)', '\U0001fb26': 'SEXTANT CHAR 38 PROVISIONAL)', '\U0001fb27': 'SEXTANT CHAR 39 PROVISIONAL)', '\U0001fb28': 'SEXTANT CHAR 40 PROVISIONAL)', '\U0001fb29': 'SEXTANT CHAR 41 PROVISIONAL)', '\U0001fb2a': 'SEXTANT CHAR 42 PROVISIONAL)', '\U0001fb2b': 'SEXTANT CHAR 43 PROVISIONAL)', '\U0001fb2c': 'SEXTANT CHAR 44 PROVISIONAL)', '\U0001fb2d': 'SEXTANT CHAR 45 PROVISIONAL)', '\U0001fb2e': 'SEXTANT CHAR 46 PROVISIONAL)', '\U0001fb2f': 'SEXTANT CHAR 47 PROVISIONAL)', '\U0001fb30': 'SEXTANT CHAR 48 PROVISIONAL)', '\U0001fb31': 'SEXTANT CHAR 49 PROVISIONAL)', '\U0001fb32': 'SEXTANT CHAR 50 PROVISIONAL)', '\U0001fb33': 'SEXTANT CHAR 51 PROVISIONAL)', '\U0001fb34': 'SEXTANT CHAR 52 PROVISIONAL)', '\U0001fb35': 'SEXTANT CHAR 53 PROVISIONAL)', '\U0001fb36': 'SEXTANT CHAR 54 PROVISIONAL)', '\U0001fb37': 'SEXTANT CHAR 55 PROVISIONAL)', '\U0001fb38': 'SEXTANT CHAR 56 PROVISIONAL)', '\U0001fb39': 'SEXTANT CHAR 57 PROVISIONAL)', '\U0001fb3a': 'SEXTANT CHAR 58 PROVISIONAL)', '\U0001fb3b': 'SEXTANT CHAR 59 PROVISIONAL)'}
chars_to_order = {' ': 0, '█': 63, '▌': 21, '▐': 42, '\U0001fb00': 1, '\U0001fb01': 2, '\U0001fb02': 3, '\U0001fb03': 4, '\U0001fb04': 5, '\U0001fb05': 6, '\U0001fb06': 7, '\U0001fb07': 8, '\U0001fb08': 9, '\U0001fb09': 10, '\U0001fb0a': 11, '\U0001fb0b': 12, '\U0001fb0c': 13, '\U0001fb0d': 14, '\U0001fb0e': 15, '\U0001fb0f': 16, '\U0001fb10': 17, '\U0001fb11': 18, '\U0001fb12': 19, '\U0001fb13': 20, '\U0001fb14': 22, '\U0001fb15': 23, '\U0001fb16': 24, '\U0001fb17': 25, '\U0001fb18': 26, '\U0001fb19': 27, '\U0001fb1a': 28, '\U0001fb1b': 29, '\U0001fb1c': 30, '\U0001fb1d': 31, '\U0001fb1e': 32, '\U0001fb1f': 33, '\U0001fb20': 34, '\U0001fb21': 35, '\U0001fb22': 36, '\U0001fb23': 37, '\U0001fb24': 38, '\U0001fb25': 39, '\U0001fb26': 40, '\U0001fb27': 41, '\U0001fb28': 43, '\U0001fb29': 44, '\U0001fb2a': 45, '\U0001fb2b': 46, '\U0001fb2c': 47, '\U0001fb2d': 48, '\U0001fb2e': 49, '\U0001fb2f': 50, '\U0001fb30': 51, '\U0001fb31': 52, '\U0001fb32': 53, '\U0001fb33': 54, '\U0001fb34': 55, '\U0001fb35': 56, '\U0001fb36': 57, '\U0001fb37': 58, '\U0001fb38': 59, '\U0001fb39': 60, '\U0001fb3a': 61, '\U0001fb3b': 62}
class terminedia.subpixels.SubPixels

Bases: object

Used internally to emulate pixel setting/resetting/reading inside unicode block characters

Requires that the subclasses contain a listing and other mappings of all block characters to be used in order, so that bits in numbers from 0 to bit_size will match the “pixels” on the corresponding block character.

Although this class is purposed for internal use in the emulation of a higher resolution canvas, its functions can be used by any application that decides to manipulate block chars.

The class itself is stateless, and any subclass can be used as a single-instance. The instance is needed so that one can use the operator in to check if a character is a block-character in that resolution.

(originally this code was in the BlockChars class - and was refactored to include the other sub-block pixel resolutions. This class is used as base, and depends mostly of declaring the pixel-representing characters in order in the subclass.)

classmethod get_at(pos, data)

Retrieves whether a pixel in a block character is set

Args:
  • pos (2-sequence): The pixel coordinate

  • data (character): The character were to look at blocks.

Raises KeyError if an invalid character is passed in “data”.

classmethod reset(pos, data)

“resets” a pixel in a block character

Args:
  • pos (2-sequence): coordinate of the pixel inside the character (0,0) is top-left corner, and so on)

  • data: initial character to be composed with the bit to be reset.

classmethod set(pos, data)

“Sets” a pixel in a block character

Args:
  • pos (2-sequence): coordinate of the pixel inside the character (0,0) is top-left corner, (1,1) bottom-right corner and so on)

  • data: initial character to be composed with the bit to be set. Use space (” “) to start with an empty block.

bit_size = 15
terminedia.subpixels.sextant_name_picker(char)
terminedia.subpixels.BlockChars = <terminedia.subpixels.BlockChars_ object>

BlockChars_ single instance: enables __contains__:

terminedia.subpixels.SextantChars = <terminedia.subpixels.SextantChars_ object>

U+25E2 ◢ e2 97 a2 BLACK LOWER RIGHT TRIANGLE U+25E3 ◣ e2 97 a3 BLACK LOWER LEFT TRIANGLE U+25E4 ◤ e2 97 a4 BLACK UPPER LEFT TRIANGLE U+25E5 ◥ e2 97 a5 BLACK UPPER RIGHT TRIANGLE

terminedia.terminal module

class terminedia.terminal.JournalingScreenCommands(**kwargs)

Bases: terminedia.backend_common.JournalingCommandsMixin, terminedia.terminal.ScreenCommands

Internal use class to optimize writting ANSI-Sequence commands to the terminal

class terminedia.terminal.ScreenCommands(absolute_movement=True, force_newlines=False)

Bases: terminedia.backend_common.BackendColorContextMixin

Low level functions to execute ANSI-Sequence-related tasks on the terminal.

Although not private, this class is meant to be used internally by the higher level Screen and Drawing classes. One might use these functions directly if there is no interest in the other functionalities of the library, though, or, to make use of a custom ANSI sequence which is not available in the higher level API.

CSI(*args, file=None)

Writes a CSI command to the terminal

Args:
  • *args: Sequence of parameters to the command, including the last

    one that should be a letter specifying the command

Just a fancy way to print the ANSI “CSI” (Control Sequence Introducer”) commands These are commads stated with the “<ESC>[” sequence.

Check https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences for available commands

RCP(file=None)

Restores saved cursor position (in the TTY software)

SCP(file=None)

Saves the current cursor position (in the TTY software)

SGR(*args, file=None)

Writes a SGR command (Select Graphic Rendition)

Args:
  • *args: Sequence of parameters to the SGR command,

This function calls .CSI with the command fixed as “m”

which is “SGR”.

apply_unicode_effects(txt, effects=None)
clear(file=None)

Writes ANSI Sequence to clear the screen

cursor_hide(file=None)

Writes ANSI Sequence to hide the text cursor

cursor_show(file=None)

Writes ANSI Sequence to show the text cursor

down(amount=1, file=None)

Writes ANSI Sequence to move cursor down

fast_render(data, rects=None, file=None)
home(file=None)
left(amount=1, file=None)

Writes ANSI Sequence to move cursor left

moveto(pos, file=None)

Writes ANSI Sequence to position the text cursor

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

Please note that ANSI commands count screen coordinates from 1, while in this project, coordinates start at 0 to conform to graphic display expected behaviors

print(*texts, pos=None, context=None, color=None, background=None, effects=None, file=None, flush=False, sep=' ', end='\n')

Method to print a straightforward rich-text string to the terminal

Params:

*texts: List[str]: strings to print pos: Optional[Tuple[int, int]]: Terminal position to print to context: Optional[terminedia.Context instance] color: Union[terminedia.Color, str, Tuple[int, int, int], Tuple[float, float, float]] : foreground color to use background: Union[terminedia.Color, str, Tuple[int, int, int], Tuple[float, float, float]] : background color to use effects: terminedia.Effects : effect or effect combination to apply to characters before printing file, flush, sep, end: The same as standard Python’s print

print_at(pos, text, file=None)

Positions the cursor and prints a text sequence

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

  • txt: Text to render at position

There is an optimization that avoids re-issuing cursor-positioning ANSI sequences for repeated calls of this function - this uses a class attribute so that different Screen instances won’t clash, but might yield concurrency problems if appropriate locks are not in place in concurrent code.

reset_colors(file=None)

Writes ANSI sequence to reset terminal colors to the default

restore_cursor_position(file=None)

Restores saved cursor position (in the TTY software)

right(amount=1, file=None)

Writes ANSI Sequence to move cursor right

save_cursor_position(file=None)

Saves the current cursor position (in the TTY software)

set_bg_color(color, file=None)

Writes ANSI sequence to set the background color color: RGB 3-sequence (0.0-1.0 or 0-255 range) or color constant

set_effects(effects, *, reset=True, turn_off=False, update_active_only=False, file=None)

Writes ANSI sequence to set text effects (bold, blink, etc…)

When using the high-level drawing functions, each time a text-effect attribute is changed, all text effects are reset. The turn_off and reset parameters are suplied for low-level use of this function.

  • Args: effects (terminedia.Effects): enum specifying which text effects should be affected reset (bool): When True, all effect attributes on the screen are reset to match

    the passed effects description. (i.e. if blinking is currently on, and effects == Effect.underline, blinking will be turned off, and only underline will be active). If reset is False, only the underline terminal property will be affected by this call

    turn_off (bool): Only used when “reset” is False: meant to indicate

    the specified effects should be turnned off instead of on.

    update_active_only (bool): if set, won’t issue any commands to terminal, just

    modify internal state so that effetcs that trigger character translations are activated.

set_fg_color(color, file=None)

Writes ANSI sequence to set the foreground color color: RGB 3-sequence (0.0-1.0 or 0-255 range) or color constant

toggle_buffer(file=None)
up(amount=1, file=None)

Writes ANSI Sequence to move cursor up

last_pos = None
locks = {}
class terminedia.terminal.UnblockTTY

Bases: object

When changing the terminal to raw mode, stdin and stdout it become “unblocking” meaning that a large amount of output might raise an IO Error (BlockingIOError) when refreshing the output.

Any code using realtime keyboard reading (using “with terminedia.keyboard:”, or the main_loop) make this change to raw mode. (code for that is on the terminedia.input file)

This allows screen refreshing code to temporarily disable the non-blocking nature of the files to avoid this error

terminedia.terminal.cls()

Clears the output terminal.

(if using Screen prefer “Screen.clear()”)

terminedia.terminal.effect_double_off = {<Effects.bold: 1>: {<Effects.faint: 32>}, <Effects.italic: 2>: {<Effects.fraktur: 8192>}, <Effects.underline: 4>: {<Effects.double_underline: 512>}, <Effects.blink: 16>: {<Effects.fast_blink: 64>}, <Effects.faint: 32>: {<Effects.bold: 1>}, <Effects.fast_blink: 64>: {<Effects.blink: 16>}, <Effects.double_underline: 512>: {<Effects.underline: 4>}, <Effects.framed: 1024>: {<Effects.encircled: 2048>}, <Effects.encircled: 2048>: {<Effects.framed: 1024>}, <Effects.fraktur: 8192>: {<Effects.italic: 2>}}

Helper mapping to avoid automatically turning off text attributes that happen to use the same code to switch off than others

terminedia.terminal.effect_on_map = {<Effects.bold: 1>: 1, <Effects.italic: 2>: 3, <Effects.underline: 4>: 4, <Effects.reverse: 8>: 7, <Effects.blink: 16>: 5, <Effects.faint: 32>: 2, <Effects.fast_blink: 64>: 6, <Effects.conceal: 128>: 8, <Effects.crossed_out: 256>: 9, <Effects.double_underline: 512>: 21, <Effects.framed: 1024>: 51, <Effects.encircled: 2048>: 52, <Effects.overlined: 4096>: 53, <Effects.fraktur: 8192>: 20}

Inner mappings with actual ANSI codes to turn on and off text effects. These are defined on module escope to avoid re-parsing of the dict bodies at each invocation of set_effects

terminedia.text.fonts module

terminedia.text.fonts.list_fonts()

List font-files available with installed terminedia.

Compliant fonts can be used and rendered if their full-file-path is supplied in target.context.font (current implementation uses human-readable, one glyph per line, hex font files as made available by the UNSCII project).

Fonts can be used by their aliases: default unscii-8-font is used if font is the empty string “”. unscii-16, if the name includes “16”, and unscii 8 variants need only their distinct infix like “fantasy”, “mcr” or “thin”.

terminedia.text.fonts.load_font(font_path, font_is_resource, page=0, ch1=' ', ch2='#')
terminedia.text.fonts.render(text, font=None, shape_cls=<class 'terminedia.image.PalettedShape'>, direction=Directions.RIGHT)

terminedia.text.style module

Tokenizer and tree-structure for style-applying in text.

Allows one to encode in a single string style changes instead of having to chunk pieces of text to change the context for color, effects and transform changes

Also, [future] enable the parsing of more than one markup style - for example, allowing terminedia to extract color and movement information from ANSI text streams generated by other apps.

TMMarkup example:

here comes some text [color:blue] with apples [background:red] infinite [/color /background effect:blink]in joy and blink[/effect] [direction:up]happy[effect:bold]new year[/effect][direction:left]there we go[/direction]up again[direction: right] the end.

Markup description:

any text outside of a […] block is treated as plain text double use of square brackets - [[…]] escape on single bracket pair(wip) the tag name inside squares can be any of:

  • “color”: sets the text foreground color. The color can be spelled as

    a CSS color name (‘red’, ‘yellow’, etc…) or using a numeric notation with a numeric triplet inside parenthesis (this will be parsed as if it were a Pythn tuple. Besides that the special color names “transparent” and “default” can also be used. The first ignores color and uses the correspondent color already set in the underlying character cell.

  • “foreground”: the same as “color”

  • “background”: Sets the text foreground color

  • “effect”: any effect name from those listed in the “terminedia.effects” enum.

    more than one effect can be activated in the same markup - separate the effect names with a “|”. Example: “[effect: blink|underline]”. Some of th provided effects rely on terminal capabilities, such as underline, while others depend on an actual character replacing for unicode characters providing the visual effect named. The later are not meant to be cumullative, as characters can only be replaced once; ex.: “[effect: encircled]”. Besides all existing effets, the special value “transparent” is also affected, and should preserve the effects active in the cell the character will be rendered to.

  • “effects”: an alias for “effect”

  • “font” - the font to be used to render the text. Only works for multi-block sized text,

    and for the embedded UNSCII fonts: “fantasy”,”mcr” and “thin”. Ex: “[font; thin]”, “[font]”

  • “char”: replaces all characters inside this tag with the givern one.

  • “direction”: One of the 4 directions for text flow: up, down, right and left

    instead of “[direction: left]” , the direction names can be used as tag names., so these are valid: “[left]abcd[up]efgh[right]ijklm”

  • “transformers”: one of the Transformer instances listed in “terminedia.transformers.library” (wip)

  • tag name starting with an “/”: pops the last corresponding tag and drops its modifications to

the text flow. ex. “[/color]” (wip) - Two comma separated numbers: “teleports” the text the text for that coordinate in

  • the target rendering area. ex. “Hello[5, 3]World”, prints ‘world” at the 5,3 coordinates.

  • Using the “+” and “-” characers as a numeric prefix will use those numbrs as relative positions

ex.: “[0, +1]” will move the beginning of text the next line.

If tags are not closed, styles are not “popped”, but this is no problem (no memory laks or such) the closing styles feature is just a matter of convenience to return to previous values of the same attribute. Also, unlike XML, there is no problem crossing tags; This is valid input: “[color: blue] hello [background: #ddd] world [/color] for you [/background]!!”

class terminedia.text.style.ANSITokenizer

Bases: terminedia.text.style.Tokenizer

class terminedia.text.style.MLTokenizer(initial='')

Bases: terminedia.text.style.Tokenizer

classmethod escape(text)
expand()

Transform special control characters into full tokens, so that parsing is uniform

parse()

Parses the raw_text in the instance, and sets setting a stripped “parsed_text” attribute along a “.mark_sequence” attribute containing the described marks embedded in the text as Mark instances.

update(text)
class terminedia.text.style.Mark(attributes=None, pop_attributes=None, moveto=None, rmoveto=None, color=None, foreground=None, background=None, effects=None, direction=None, transformer=None, new_line=None)

Bases: object

Control object to be added to a text_plane or StyledStream

The object indicate which context attributes or text position enter in effect at that point in the stream.

Instances of this are to be automatically created on parsing markup strings or or other input - but can be hand-crafted for special effects.

classmethod merge(m1, m2)
affects_text_flow
attributes
context
moveto
pop_attributes
pos
rmoveto
class terminedia.text.style.MarkMap(parent=None)

Bases: collections.abc.MutableMapping

Mapping attached to each text plane -

TL;DR: this is a mapping used to control rich text rendering and flow. An instance is attached to each text_plane and can be reached at shape.text[size].marks This instance can be directly used by Text object users to place marks that will change the behavior of printed text at that point and beyond.

It contains Mark objects that are “virtually” hidden in the plane and can change the attributes or position of a text sequence in the point one character will (or would) be printed were they are located. The attribute change takes effect for the rich-text stream been rendered from that point on.

In plain code, that means doing: ` myshape.text[1].marks[3,0] = TM.Mark(attributes={"color": "red"}) myshape.text[1][0,0] = "123456" ` will render ‘123’ in the current context color, and ‘456’ in red.

The positional Marks can also be “virtual” in a sense one can set a rectangle of special marks in a single call: this is used to setup the “teleporter” marks at text-plane boundaries that enable text to continue on the next line, when printing left-to-right.

A third Mark category can be added, consisting of Marks which index will change overtime: the “special” index can receive “SpecialMark” instances: those are Mark objects that have an “index” method - this method receives two parameters a “tick” number and the length of the sequence being rendered, and returns a 1D index - which is used to place the mark inside the sequence of text being rendered, or a 2D index, that is used as a location on the grid.

The instances of MarkMap are consumed by StyledSequence objects when rendering, and those will set the 1D positional-mark mapping embedded in the text-stream into a shallow copy of a MarkMap instance, combining both 2D fixed Marks bound to the text plane with the marks embedded n the sequence. The StyledSequence instance then consumes marks when iterating itself for rendering, retrieving both marks in the text stream (1D positional marking), Marks fixed on the text plane, and special marks with time-variant position. When retrieving the Marks at a given position, the location on the 2D plane, and tick number are available to be consumed by callables on special Mark objects

A caracteristic of the contents of MarkMap cells is that a cell may contain either a Mark object, or a list of MarkObjects

  • Lists and Marks can be created freely and assigned

to indexes in MarkMap instances. Marks that are placed in absolute cell addresses are merged with ones stored in relative cell address upon reading (addressing from the left or from the bottom of a text plane). The mechanism for that is too complicated to be something to be proud off - but seems to work when a text-area changes size in a nice way.

(Relative indices are numbers added (or rather, subtracted from), the special enumeration values in the RelativeMarkIndex class - so that when the underlying text-plane change size, the negative indices are translated along with it.)

abs_get(index, default=None)

Usually negative values for indexes coordinates will subtract those values from the width or height of the textplane, so “-1” is actually at “WIDTH - 1” == last column.

But sometimes actually need to get the mark at the [-1] hard index. When that is needed, the mark should be retrieved through here, rather than through __getitem__ directly.

For setting, since negative indexes will not depend on the width and height of the text plane (they are on the opposite side of these dynamic indexes: column -1 is the equivalent on the left-side of column WIDTH + 1 on the right side), assignment of marks can be done directly on the “self.data” attribute

clear() → None. Remove all items from D.
concretize_relative_marks()
concretize_special_marks()
get_full(sequence_index, pos, skipped=None)
move_along_marks(pos, direction)

Used to track flow of text in a plane, without needing a concrete sequence to be rendered.

Given a plane position and direction, will check all Marks that can modify the text flow, and return the position for the next character.

Is used in order to compute distances to the next and previous breaks on the flow - these are used as line boundaries for printing and editing text.

Not Implemented: handling of “special” marks or marks embedded in a text string.

new_line_start(index, direction)
prepare(seq_data, tick=0, parsed_text: Union[str, terminedia.unicode.GraphemeIter] = '', context=None)
class terminedia.text.style.SpecialMark(index, *args, **kwargs)

Bases: terminedia.text.style.Mark

index
class terminedia.text.style.StyledSequence(text, mark_sequence, text_plane=None, context=None, starting_point=None)

Bases: object

render()
class terminedia.text.style.Tokenizer

Bases: object

terminedia.text.style.get_relative_variants(pos, size=None)

Given a position and a size, yields all possible ways of ‘spelling’ the given position expresing Vector with relative-to-the-end indexes

terminedia.text.style.index_is_relative(index)
terminedia.text.style.normalize_relative_index(index)

terminedia.text.planes module

class terminedia.text.planes.CharPlaneData(size)

Bases: dict

2D Data structure to hold the text contents of a text plane.

Indices should be a V2 (or 2 sequence) within width and height ranges

active
height
size
width
class terminedia.text.planes.CtxData(foreground, background, effects)

Bases: tuple

background

Alias for field number 1

effects

Alias for field number 2

foreground

Alias for field number 0

class terminedia.text.planes.Layouts

Bases: object

static normal(text_plane)
class terminedia.text.planes.RenderData(char, pos, tick, ctx)

Bases: tuple

char

Alias for field number 0

ctx

Alias for field number 3

pos

Alias for field number 1

tick

Alias for field number 2

class terminedia.text.planes.TextPlane(owner)

Bases: object

Text handling API

An instance of this class is attached to Screen and Shape instances as the text attribute. All context-related information is kept on the associated owner instance. , Prior to issuing any text command, one should select a character “plane”. Planes refer to the number of text blocks used for plotting each character on the final rendering target (Shape or Screen). Thus, the values 1 - for normal text, 2 for text rendered with Braille unicode chars, 4 for characters rendered with 1/4 block, 3 for values rendered with the Unicode 13.0 sextant chars,

characters and 8 for characters rendered by block characters as pixels, are implemented with the default fonts. (as in screen.text[4].at((3,4), “hello”) ) the public methods here issue commands directly to the owner’s draw. high.draw and braille.draw drawing namespaces - or the owner’s values for the text[1] plane.

add_border(transform=None, context=None)

Adds a text-frame. Increases padding and updates the content.

The parameter passed should be a transformer - and is primarily thought to be one of terminedia.transformers.library.box_transforms.* or another one that will use nice unicode line characters for the borders. Without a Transformer, a block-char is used for the borders.

Any transformer can be used, though - the frame is them rendered as a solid block-outline

if context is given: uses given context to render the border, otherwise the context for the owner shape is used.

at(pos, text, transformerlib=None, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None, font=None, direction=None)

Renders text at position.

Args:
  • pos (2-sequence): Coordinates at which to start the text

  • text (str): Text to render. May include special markup

  • transformerlib (Mapping[str:terminedia.Transformer]): updates

    the internal transformers library and become available to use from the markup

  • “context-args” (color, background, effects, font, direction):

    context values to be used to render passed text.

Returns:

V2: with the last printed position.

Text is rendered same as using the “=” attribution like in screen.text[1][0,0] = “My text” - but this method returns the postion of the last character printed, allows context attributes to be passed as parameters.

The Transformers parameter accepts a “transformers” dictionary that will be incorporated into the local “transformers” available to be used by name from markup in the text, like in: `screen.text[1].at((0,0), “[transformers: upper]My text”,

transformers={“upper”: Transformer(char=lambda char: char.upper())}

)`

Note that “transformers” set in a call to this will update the internal dictionary for the “text” instance associated with a Shape in all resolutions, and remain available after the call.

For fine-grained control of available transformers, the Text.transformers_map attribute is a plain dictionary that can be changed at will.

blit(index, target=None, clear=True)

Actual function that renders given character to the selected backend. Reserved for internal use, but could be called by lower level code, explicitly rendering a character at another target.

clear(layout=None)
clear_recording()

Clear recording of where each character was printed

draw_border(transform=<object object>, context=None, pad_level=1)

Draws an existing border, without changing the shape pattern call this just to redraw the border; A new border should be created by calling “add_border”

extents(pos, text, final_pos=True, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None, font=None, direction=None)

Return the last position where text would be printed -

This is a “dry-run” call, equivalent to “.at” but doesn’t render anything in owner. It won’t take a ‘transformerslib’ parameter - if the text that needs to be measured will need special transformers set in this TextPlane, they should be created beforehand, either with an emptu call to .at or by updating the .transformers_lib dictionary directly.

Args:
  • pos (2-sequence): Coordinates at which to start the text

  • text (str): Text to render. May include special markup

  • final_pos (bool): return position is the positin for the next insertion,

    not of the last character inserted. (default: True)

  • “context-args” (color, background, effects, font, direction):

    context values to be used to render passed text.

Returns:

V2: with the last printed position.

pos_to_text_cell(pos)

Given a 1-block coordinate on screen, return the cordinate of the matchng text cell on the current plane, taking in account padding.

print(text, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)
refresh(clear=True, *, preserve_attrs=False, rect=None, target=None)

Render entire text buffer to the owner shape

Args:
  • clear (bool): whether to render empty spaces. Default=True

  • preserve_attrs: whether to keep colors and effects on the rendered cells,

    or replace all attributes with those in the current context

  • rect (Optional[Rect]): area to render. Defaults to whole text plane

  • target (Optional[Shape]): where to render to. Defaults to owner shape.

render_styled_sequence(styled)

Render an instance of terminedia.text.style.StyledSequence directly

Usually, will be called automatically by assignments to a position in the text plane or by the “.at()” method, but a styled_sequence can be crafted with SpecialMarks in a way automatic assignment would not work.

Also, called internally to update StyledSequences that contain animations.

reset_marks(layout=None)

Clear all custom positional marks in the text plane (attribute .marks) - and, applies the specified text-flow layout. The layout is a callback, which should take the text-plane as sole parameter - it can then fill in Mark objects (usually containing “moveto” and “rmoveto” tags) in specific positions so that text will flow in the desired directions when reaching the mark (the default “normal” layout places marks so that at the end of a line the text flows in to the beggining (absoulte move) of the next (relative move) text line.

The “Layouts” class in this module is meant to be a namespace for a library with popular layouts.

reset_padding()
start_recording()
update()

Re-render any writting on the plane that was done using SpecialMarks

height
pad_bottom

This puts the “R’ in Reactive

pad_left

This puts the “R’ in Reactive

pad_name = 'pad_bottom'
pad_right

This puts the “R’ in Reactive

pad_top

This puts the “R’ in Reactive

padding

This puts the “R’ in Reactive

size
width

terminedia.text module

terminedia.transformers module

class terminedia.transformers.GradientTransformer(gradient, direction=Directions.RIGHT, size=None, channel='foreground', repeat='saw', offset=0, gradient_cls=<class 'terminedia.utils.gradient.ColorGradient'>, **kwargs)

Bases: terminedia.transformers.Transformer

get_gradient_pos(pos, target_size)
class terminedia.transformers.KernelTransformer(kernel, mask_diags=True, **kwargs)

Bases: terminedia.transformers.Transformer

char(source, pos)
kernel_match(source, pos)
policy = 'abyss'
class terminedia.transformers.Transformer(pixel=None, char=None, foreground=None, background=None, effects=None)

Bases: object

background = None
channels = ['pixel', 'char', 'foreground', 'background', 'effects']
char = None
effects = None
foreground = None
pixel = None
class terminedia.transformers.TransformersContainer(*args)

Bases: terminedia.utils.collections.HookList

bake(shape, target=None, offset=(0, 0))

Apply the transformation stack for each pixel in the given shape

Args:
  • shape: Source shape object to be processed

  • target [Optional]: optional target where final pixels are blitted into.

    If target is not given, ‘shape’ is modified inplace. Defaults to None.

  • offset: pixel-offset to blit the data to. Most useful with the target

option.

Returns:

the affected Shape object

insert_hook(item)
process(source, pos, pixel)

Called automatically by FullShape.__getitem__

Only implemented for pixels with all attributes (used by fullshape)

remove(tr)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

stack

terminedia.transformers.library module

Ready to use Transformer classes

These should be appended to a Sprite’s “transformers” list, to generate several effects.

Over time, more ‘transformers’ should be made available here.

‘Table’ transformers

The transformers with “table” in the name will use a convolution operation on a 3x3 matrix around any displayed character and replace those by Unicode line drawing characters.

```python import terminedia as TM block = TM.shape((10,10)) block.draw.rect((1,1, 9, 9)) sc = TM.Screen() sp1 = sc.data.sprites.add(block, active=True) sp1.transformers.append(TM.transformers.library.box_light_table_transformer) block.draw.line((1, 4),(8, 4)) sc.update()

for variant_name, trans in TM.transformers.library.box_transformers.items():

sp1.transformers.clear() sp1.transformers.append(trans) sc.text[1].at((0, 15), variant_name + ” “) sc.update() TM.pause()

```

class terminedia.transformers.library.ThresholdTransformer(threshold=0.5, invert=True, foreground=<Color 'DEFAULT_FG'>, **kwargs)

Bases: terminedia.transformers.Transformer

char(char, foreground)

terminedia.unicode_transforms module

unicode_transforms creates text effects based on UNICODE character transformations. Those effects depends on the fonts available in the system

terminedia.unicode_transforms.text_to_circled(text, convert=True)
terminedia.unicode_transforms.text_to_double_struck(text, convert=True)
terminedia.unicode_transforms.text_to_fullwidth(text, convert=True)
terminedia.unicode_transforms.text_to_modifier_letter(text, convert=True)
terminedia.unicode_transforms.text_to_negative_circled(text, convert=True)
terminedia.unicode_transforms.text_to_negative_squared(text, convert=True)
terminedia.unicode_transforms.text_to_parenthesized(text, convert=True)
terminedia.unicode_transforms.text_to_regional_indicator_symbol(text, convert=True)
terminedia.unicode_transforms.text_to_san_serif_bold(text, convert=True)
terminedia.unicode_transforms.text_to_san_serif_bold_italic(text, convert=True)
terminedia.unicode_transforms.text_to_squared(text, convert=True)
terminedia.unicode_transforms.text_to_upside_down(text, convert=True)

Use a table of custom characters to find aproximate upside-down glyphs

terminedia.unicode_transforms.translate_chars(text, unicode_effects, convert=True)

Apply a sequence of character-translating effects to given text. Args:

  • text(str): text to be transformed

  • unicode_effects (iterable[Terminedia.Effects]): Effects to be applied

terminedia.utils module

terminedia.utils.combine_signatures(func, wrapper=None, include=None)

Adds keyword-only parameters from wrapper to signature

Args:
  • func: The ‘user’ func that is being decorated and replaced by ‘wrapper’

  • wrapper: The ‘traditional’ decorator which keyword-only parametrs should be added to the

    wrapped-function (‘func’)’s signature

  • include: optional list of keyword parameters that even not being present

    on the wrappers signature, will be included on the final signature. (if passed, these named arguments will be part of the kwargs)

Use this in place of functools.wraps It works by creating a dummy function with the attrs of func, but with extra, KEYWORD_ONLY parameters from ‘wrapper’. To be used in decorators that add new keyword parameters as the “__wrapped__”

Usage:

def decorator(func):

@combine_signatures(func) def wrapper(*args, new_parameter=None, **kwargs):

… return func(*args, **kwargs)

return wrapper

terminedia.utils.contextkwords(func=None, context_path=None, text_attrs=False)

Decorator to automatically add drawing-context related parameters to a function

The decorated function “context” will be automatically updated to accept “char, color, background, effects, fill and context” as optional parameters, and this change is reflected in its signature, in an iPython and IDE friendly way.

The passed in optional parameters are not forwarded to the target function - instead, this decorator guesses the context used by the function, and updates that for the duration of the call.

(the rules for retrieveing the context for the function are:

if it is a method, or otherwise the first positional argument to it is a class with a “context” attribute, that context is used.

if “context_path” is set, then it is assumed the decorated function is a method and the first positional parameter is “self” - “context_path” should be a dotted name with the attribute components to reach the context - example context_path=’parent.context’ will pick the context as `self.parent.context

otherwise, terminedia’s “root_context” is updated.

‘)

terminedia.utils.get_current_tick()

use a counter in the root context

increased on calls to screen.update()

terminedia.utils.size_in_blocks(size, resolution='')

Given a shape size using a specific resolution, returns the size in blocks needed to acommodate that

terminedia.utils.size_in_pixels(size, resolution='')

Given a number of blocks return the available pixels in a specific resolution

terminedia.utils.tick_forward()
terminedia.utils.wrapcoro(ctx, coro)

terminedia.values module

class terminedia.values.Directions

Bases: object

Direction vector constants.

These are used directly as text-printing direction on a Screen context, and are free for general use in user applications

DOWN

Vector meant to be used as constant, with a string-repr name

LEFT

Vector meant to be used as constant, with a string-repr name

RIGHT

Vector meant to be used as constant, with a string-repr name

UP

Vector meant to be used as constant, with a string-repr name

class terminedia.values.Effects

Bases: terminedia.utils.collections.OrableByNameEnumMixin, terminedia.utils.collections.IterableFlag

Text effect Enums

Some of these are implemented in most terminal programs - the codes used here are so that their value can be ORed. (The “real” codes for terminal rendering are issued in terminal.py).

The somewhat arbitrary order tries to put first the most supported/most useful attributes.

bold = 1
conceal = 128
crossed_out = 256
double_struck = 16777216
double_underline = 512
encircled = 2048
faint = 32
fraktur = 8192
framed = 1024
fullwidth = 262144
italic = 2
math_bold = 524288
math_bold_italic = 1048576
negative_circled = 65536
negative_squared = 32768
none = 0
overlined = 4096
parenthesized = 131072
reverse = 8
squared = 16384
super_bold = 2097152
super_script = 4194304
underline = 4
upside_down = 8388608
class terminedia.values.IterableNS

Bases: type

class terminedia.values.RelativeMarkIndex(name)

Bases: object

These are used for creating Marks on terminedia.text.Text objects that are relative to the width and height of the object. Needed for Marks that should automatically be moved when the padding area of those planes is reassigned

evaluate(size)
classmethod evaluate_position(pos, old_pos, size)
class terminedia.values.SpecialColors

Bases: enum.Enum

An enumeration.

CONTEXT_COLORS = <Color 'CONTEXT_COLORS'>
DEFAULT_BG = <Color 'DEFAULT_BG'>
DEFAULT_FG = <Color 'DEFAULT_FG'>
TRANSPARENT = <Color 'TRANSPARENT'>
terminedia.values.CONTEXT_COLORS = <Color 'CONTEXT_COLORS'>

Constant used as color to mean keep the current context colors

terminedia.values.CONTINUATION = 'CONT'

Special value used in character data maps to indicate the cell continues a double width character to the left

terminedia.values.DEFAULT_BG = <Color 'DEFAULT_BG'>

Constant used as color to mean the default terminal background

terminedia.values.DEFAULT_FG = <Color 'DEFAULT_FG'>

Constant used as color to mean the default terminal foreground (Currently all other color values should be RGB)

terminedia.values.EMPTY = ' '

Character to denote an empty-space on images and drawing contexts

terminedia.values.FULL_BLOCK = '█'

Character to denote a filled-pixel on images and drawing contexts

terminedia.values.NOP = 'NOP'

Special value to mean no transformation to a given channel on context-transforms. (See terminedia.utils.create_transformer)

terminedia.values.TRANSPARENT = <Color 'TRANSPARENT'>

Constant to mean keep the current value on setting a pixel, used as char, fg, bg or effect

Module contents

Terminedia is a library providing utilities to control and draw on the text terminal

Usage: import terminedia main classes and constants and control the terminal is if it is a multi-functional canvas. Drawing primitives that operate with block chars are provided, as well as non-blocking keyboard reading.

Indices and tables

Terminedia is meant to be a lightweight terminal library to provide color output, positioned text, and use block characters for displaying low-resolution graphics in the terminal itself.

Simple example:

from terminedia import Screen, pause

with Screen() as scr:
    scr.context.color = 1, 0, 0
    scr.high.draw.rect((5, 5), (30, 20))

    pause()

This will draw a rougly square rectangle (due to character block non square aspect-ratio) using 1/4 block unicode characters to draw lines. The output is:

_images/example_00.png

Text-rectangle drawn on terminal by simple example.

(spacing between blocks will depend on the terminal program, font, and window

size)

Besides allowing positioning text and graphics, there are resources that allow non blocking keyboard reading, and capability to read keypresses from the Arrow Keys, Escape and Function keys- which enables building rich, keyboard based, interfaces directly in the terminal, as well as simulating a vintage “8-bitish” personal computer era style games and apps.

The “examples” folder in the project source have other simple examples.

Bellow you will find all the documentation for the library, including some low-level and internal use modules. Unless you need to do something too specific, you can make use of the higher level Screen class.

It should be used as a context manager, and within the managed block, you can use the Screen’s instance public methods, as well as its Screen.context attribute to select colors and text-direction, and it’s Screen.draw attribute to access drawing primitives, which are the methods avaliable on the Drawing class. Last but not least, the attribute Screen.high on the Screen instance enables the use of 1/4 character “pixels” to draw in a seamless way. Just use the .high.draw namespace to access the drawing primitives the same way the .draw namespace allows drawing with full-block characters.

For input, the available functionalities are the keyboard context manager, which enables non-blocking use of the keyboard, and the inkey and pause functions which make use of this feature.

Terminedia

Terminedia is a library providing utilities to control and draw on the text terminal

Usage: import terminedia main classes and constants and control the terminal is if it is a multi-functional canvas. Drawing primitives that operate with block chars are provided, as well as non-blocking keyboard reading.

class terminedia.Color(value: Union[Color, Sequence[numbers.Real], str] = None, hsv=None)

One Color class to Rule then all

Args:
  • value: 3-sequence with floats in 0-1.0 range, or int in 0-255 range, or a string with

    color in HTML hex notation (3 or 6 digits) or HTML (css) color name

__getitem__(index)
__init__(value: Union[Color, Sequence[numbers.Real], str] = None, hsv=None)

Initialize self. See help(type(self)) for accurate signature.

__setitem__(index, value)
isclose(other: Union[Color, Sequence[numbers.Real], str], abs_tol=3) → bool

Returns True if the other color components are close to this color.

The RGB components are compared, using the 0-255 number range

classmethod normalize_color(components)

Converts RGB colors to use 0-255 integers.

Args:
  • color: Either a color constant or a 3-sequence,

    with float components on the range 0.0-1.0, or integer components in the 0-255 range.

returns: Color constant, or 3-sequence normalized to 0-255 range.

alpha
blue
components
green
hsv
html
hue
name
normalized
red
saturation
special
value
class terminedia.ColorGradient(stops: Sequence[Tuple[float, Any]])
BASE_TYPE

alias of terminedia.utils.colors.Color

interpolate(c_previous, c_next, weight_from_previous, weight_from_next)

Interpolation that works for linear numeric values

class terminedia.Context(**kw)

Context class for Screen and Shape objects. Instances should live as “.context” on those

Args: - **kw: initial keyword arguments for a context

The drawing and printing operations on terminedia will set a graphic element on a target. Depending on the function it will either write an arbitrary character or just set/reset a pixel in the desired color.

All the other attributes for the element being drawn are picked from its “.context” attribute which is an instance of this.

The attributes here are set independently for each thread, and these are the ones currently used by the drawing functions:

  • color: color special value or RGB sequence for foreground color - either int 0-255 or float 0-1 based.

  • background: color special value or RGB sequence sequence for background color

  • direction: terminedia.Directions Enum value with writting direction

  • effects: terminedia.Effects Enum value with combination of text effects

  • char: Char to be plotted when setting a single color.

  • transformer: Callback that will change in-place each attribute of

a graphic element immediately before actually setting then on the target.

Also, if used as a context-manager, this pushes all current attributes in a stack, providing a practical way for a sub-routine to draw things to the target without messing with the callee’s expected drawing context. Otherwise one would have to manually save and restore the context colors for each operation. When entering a Context as a context manager, the original attributes are retained, but any changes to it in the corresponding with block are reverted on __exit__.

__enter__()
__exit__(exc_name, traceback, frame)
__init__(**kw)

Initialize self. See help(type(self)) for accurate signature.

background
char
color
direction
effects
fill
font
foreground
pretransformers
transformers
class terminedia.Directions

Direction vector constants.

These are used directly as text-printing direction on a Screen context, and are free for general use in user applications

DOWN

Vector meant to be used as constant, with a string-repr name

LEFT

Vector meant to be used as constant, with a string-repr name

RIGHT

Vector meant to be used as constant, with a string-repr name

UP

Vector meant to be used as constant, with a string-repr name

class terminedia.Effects

Text effect Enums

Some of these are implemented in most terminal programs - the codes used here are so that their value can be ORed. (The “real” codes for terminal rendering are issued in terminal.py).

The somewhat arbitrary order tries to put first the most supported/most useful attributes.

bold = 1
conceal = 128
crossed_out = 256
double_struck = 16777216
double_underline = 512
encircled = 2048
faint = 32
fraktur = 8192
framed = 1024
fullwidth = 262144
italic = 2
math_bold = 524288
math_bold_italic = 1048576
negative_circled = 65536
negative_squared = 32768
none = 0
overlined = 4096
parenthesized = 131072
reverse = 8
squared = 16384
super_bold = 2097152
super_script = 4194304
underline = 4
upside_down = 8388608
class terminedia.EventTypes

An enumeration.

Custom = 1024
KeyPress = 2
MouseClick = 64
MouseDoubleClick = 128
MouseMove = 8
MousePress = 16
MouseRelease = 32
Phrase = 4
QuitLoop = 2048
TerminalSizeChange = 256
Tick = 1
WidgetResize = 512
class terminedia.FullShape(data, **kw)

Shape class carrying all possible data plus kitchen sink

Args:
  • data: a sequence with 4 planes (sequences), each a sequence with n-rows

    sequences of m-width elements. The first one should carry character data: a unicode sequence representing a single glyph. The second and 3rd should contain color values, and the 4th an integer representing text effects according to Effects values.

PixelCls

alias of Pixel

__getitem__(pos)

Values for each pixel are: character, fg_color, bg_color, effects.

__init__(data, **kw)

Initialize self. See help(type(self)) for accurate signature.

__setitem__(pos, value)

Values set for each pixel are: character - only spaces (0x20) or “non-spaces” are taken into account for PalettedShape

get_raw(pos)
load_data(data_planes, size)
Sets internal data from an initial value structure.
Args:
  • data: data structure containing the elements

    that will be set to inicial pixel values. Can be a single sequence width x height in size containing all elements to be assigned as pixels, or a height-sized sequence of width-sized sequences.

  • size (V2-like): width x height.

Used to explictly set the initial values for a shape, will usually be called internally as part of the Shape initialization. If size is not given, and the passed data is 1D in nature, sie is assumed to be a single colum (1xN) shape. Strings are split at “

” and will be treated as 2D if multiline.

classmethod promote(other_shape, resolution=None)

Makes a FullShape copy of the other shape

This allows the new shape to be used with Transformers, Sprites, and other elements that might not be supported in the other shape classes

class terminedia.Gradient(stops: Sequence[Tuple[float, Any]])
BASE_TYPE

alias of builtins.float

__getitem__(position)
__init__(stops: Sequence[Tuple[float, Any]])

Define a gradient. Args:

stops: list where each component is a 2-tuple - the first item is a 0<= numbr <= 1, the second is a value of the type to be interpolated. The base Gradient class works with float numbers. Subclasses like ColorGradient interpolate other kind of values.

use __getitem__ (i.e. gradient[0.3]) to get the value at that point.

__setitem__(position, value, *args)
interpolate(previous, next_, weight_from_previous, weight_from_next)

Interpolation that works for linear numeric values

scale(scale_factor) → terminedia.utils.gradient.Gradient
root
class terminedia.GradientTransformer(gradient, direction=Directions.RIGHT, size=None, channel='foreground', repeat='saw', offset=0, gradient_cls=<class 'terminedia.utils.gradient.ColorGradient'>, **kwargs)
__init__(gradient, direction=Directions.RIGHT, size=None, channel='foreground', repeat='saw', offset=0, gradient_cls=<class 'terminedia.utils.gradient.ColorGradient'>, **kwargs)

A Transformer that will take in a gradient object and return its value based on the position of each pixel

Params:
  • gradient: The gradient to use. An instance of terminedia.utils.Gradient

    will work for the color channels. A custom object that will return the desired value when used with a value from 0 to 1 on __getitem__ can be used for non-color channels. If a list of 2-tuples containing the a stop point and a color is passed, a Gradient object will be constructed automatically.

  • direction: The direction in which the gradient should flow

  • channel: To which channel apply the gradient. By default to “foreground”, but

    can be “background”, “effects”, “char” and “pixel” (the last three will require a custom “gradient” object returning values of the appropriate type)

  • size: By default, the gradient size is adjusted to the width or height (depending on direction)

    of the source being transformed. Optionally the size can be constrained, and the gradient will be repeated from that point on. If a “scaled” gradient is passed and no size is given, the scale-factor of the gradient is used as size for the transformer.

  • repeat: the repeat mode for the gradient when the position being printed is past its “size”:
    • “saw” Gradient flows from 0 to size and then starts over from 0

    • “triangle” Gradient flows from 0 to size and then back to towards 0

    • “none” Target output positions out of range [offset, size] are filled with the fixed

      colors at the boundary of the gradient

    • “truncate” Target output positions out of range [offset, size] are not changed

  • offset: value that will be considered the “point 0” from which the gradient is applied

    (most usefull in repeat modes “none” and “trunct”

get_gradient_pos(pos, target_size)
class terminedia.ImageShape(data, color_map=None, size=None, **kwargs)

Relies on Python Imaging Library to load and handle image data.

The internal “data” member is a straighout PIL.Image instance, and one is free to use PIL drawing and image manipulation APIs to draw on it.

Important: on instantiating these shapes, Terminedia will try to auto-scale down/resample the image to compensate for the aspect-ratio of text imags. Pass the parameter auto_scale=False to __init__ or __new__ to preserve the exact size of the PIL Image.

PixelCls

alias of Pixel

clear(transparent=False)

Clear the shape with empty spaces.

params:

transparent (bool): whether to use special transparency values

if “transparent” is True, the shape is filled with the special TRANSPARENT value that make underlying shape characters, or existing tty content unchanged upon blitting.

get_raw(pos)
load_data(file_or_path, size=None, half_height=False)

Will load data from an image file using PIL,

If “size” is not passed, the native image size is used. Otherwise it should be a 2-sequence: if both numbers are given, that is used as final image size. If one component of “size” is “None”, the other one is used to scale the image, keeping its aspect ratio.

As due to the nature of character blocks, keeping the aspect ratio can lead to a strange 1:2 final display, pass “half_height=True” to keep the same visual aspect ratio for full blocks. (hint: you can load the full height and blit the resulting shape to a square 1/2 block drawable instead)

resize(new_size)
class terminedia.JournalingScreenCommands(**kwargs)

Internal use class to optimize writting ANSI-Sequence commands to the terminal

terminedia.KeyCodes

alias of terminedia.input._posix_KeyCodes

class terminedia.Mark(attributes=None, pop_attributes=None, moveto=None, rmoveto=None, color=None, foreground=None, background=None, effects=None, direction=None, transformer=None, new_line=None)

Control object to be added to a text_plane or StyledStream

The object indicate which context attributes or text position enter in effect at that point in the stream.

Instances of this are to be automatically created on parsing markup strings or or other input - but can be hand-crafted for special effects.

__init__(attributes=None, pop_attributes=None, moveto=None, rmoveto=None, color=None, foreground=None, background=None, effects=None, direction=None, transformer=None, new_line=None)

Initialize self. See help(type(self)) for accurate signature.

classmethod merge(m1, m2)
affects_text_flow
attributes
context
moveto
pop_attributes
pos
rmoveto
class terminedia.PalettedShape(data, color_map=None)

‘Shape’ class intended to represent images, using a color-map to map characters to block colors.

Args:
  • data (multiline string or list of strings): character map to be used as pixels

  • color_map (optional mapping): maps characters to RGB colors.

This class have no special per pixel values for background or character - each block position will read as “False” or “True” depending only on the underlying character in the input data being space (0x20) or any other thing.

PixelCls

alias of Pixel

__getitem__(pos)

Values for each pixel are: character, fg_color, bg_color, effects.

__init__(data, color_map=None)

Initialize self. See help(type(self)) for accurate signature.

__setitem__(pos, value)

Values set for each pixel are: character - only spaces (0x20) or “non-spaces” are taken into account for PalettedShape

load_paletted(data)
arbitrary_chars = False
background = False
effects = False
foreground = True
class terminedia.Rect(left_or_corner1=None, top_or_corner2=None, right=None, bottom=None, *, width_height=None, width=None, height=None, center=None)
__contains__(other)

Verify if a point or rectangle is contained in ‘self’.

Python’s convention of open-intervals on the upper boundaries applies: a point on the right or bottom values of the rectangle is not considered to be inside.

__init__(left_or_corner1=None, top_or_corner2=None, right=None, bottom=None, *, width_height=None, width=None, height=None, center=None)

An abstract geometric rectangular area. Mostly used for object sizes.

It will take any form you get of four numbers representing the 2D coordinates of 2 corners of the rectangle to be instantiated - one can pass a 4-number sequence as the first parameter, two sequences of 2 pairs as the first 2 parameters, or 4 separate numbers representing “x1, y1, x2, y2” as the first 4 parameters. If no coordinate is passed at all, a “null rectangle” with coordinates (0, 0, 0, 0) is created;

If “width_height” as a 2-Sequence or, separately, “witdh” or “height” are passed, these are used to compute the second corner of the rectangle.

If “center” is passed, it is used to translate both corners accordingly.

This can be used as a parameter almost anywhere a rectangle makes sense in terminedia: to define a shape size, to draw an actual rectangle with .draw.rect, as an index for a shape, to retrieve a sub-shape. For convenience, those places will also take in other Rectangle representing numbers, like a sequence of 4 numbers.

Rect is a versatile class, with several writable properties that will translate or resize the instance as appropriate.

collide(other)
intersection(other)
iter_cells()
area
as_int
as_tuple
bottom
c1
c2
center
height
left
right
top
width
width_height
class terminedia.Screen(size=(), clear_screen=True, backend='ansi', interactive=True)

Canvas class for terminal drawing.

This is the main class to interact with the terminal on Terminedia library - methods and associated instances here should be used to do all screen rendering and drawing save for low-level work.

Use this as a context manager inside which the screen is active;

For drawing primitives using full-block chars, use the instance’s Screen.draw, which contains a Drawing instance. Terminal context colors and other attributes can be set in a thread-safe way on the screen.context namespace.

To draw and position characters using 1/4 character high resolution, use the attributes and methods available at Screen.high. (High resolution drawing methods are available at screen.high.draw)

Besides the available methods and associated instances, screen contents can be set and read by using the Screen instance as a 2-dimensional mapping. For example, screen[10, 10] = "A" will set the character on that position.

Args:
  • size (optional 2-sequence): Screen size in blocks. If not given, terminal size is queried automatically. This does not resize the actual terminal - a smaller area is available to the methods instead. If given size is larger than the actual terminal, mayhen ensues.

  • clear_screen (bool): Whether to clear the terminal and hide cursor when entering the screen. Defaults to True.

  • interactive (bool): if False, do not create binding for events, or change keyboard and mouse behaviors (used by rendering to file).

    Default: True

__enter__()

Enters a fresh screen context

__exit__(exc_type, exc_value, traceback)

Leaves the screen context and reset terminal colors.

__getitem__(pos)

Retrieves character data at pos

Args:
  • pos (2-sequence): coordinate to retrieve data from.

__init__(size=(), clear_screen=True, backend='ansi', interactive=True)

Initialize self. See help(type(self)) for accurate signature.

__setitem__(pos, value)

Writes character data at pos

Args:
  • pos (2-sequence): coordinate where to set character

  • value (length 1 string): Character to set.

This is mostly used internally by all other drawing and printing methods, although it can be used directly, by using Python’s object-key notation with [ ] and assignment. All text or graphics that go to the terminal are directed through this method - it is a “single point” where all data is sent - and any user code that writes to the terminal with a Screen class should use this method. Valus set on Screen are imediately updated on the screen. To issue a command batch that should be updated at once, use the Screen.commands attribute as a context manager: (`with sc.commands: …code with lots of drawing calls … `)

If it is desired to draw/write in an in-memory buffer in order to update everything at once, one can issue the drawing class to affect the Screen.data attribute instead of Screen directly. The Screen contents can be updated by calling Screen.update afterwards. Screen.data is a terminedia.FullShape object with a .draw, .high and .text interfaces offering the same APIs available to Screen.

accelerate()

makes drawing less interactive, but faster

Replaces the “self.draw” namespace to the one going through the associated shape (self.shape) - aftewrards self.update() have to be called in order to reflect any drawing on the terminal, but it gets faster as updates in large blocks.

Also, the “native” self.draw is a bit rough when it commes to drawing off the screen limits.

This is called automatically by the terminedia_main loop.

There is no “de-acellarate” converse call, once an app is already using screen.update it makes little sense to togle back, but all one have to do if needed, is to replace the attribute by a new Draw instance as created inside __init__.

blit(position, shape, **kwargs)
clear(wet_run=True)

Resets internal data, context parameters and clears the screen

Args:
  • wet_run (bool): Whether to physically clear the screen or not

Resets internal data and context parameters. The “self.data” and “self.color_data” structures are where the current character and attributes for each position are kept as characters actually just printed on the terminal can’t be “read” back. Context foreground, background and direction are reset.

In default operation, commands to clear the actual terminal and hide the cursor is also issued - the .clear_screen attribute controls that if .clear is being called as part of entering the screen context.

get_at(pos)
get_raw(pos)
line_at(pos, length, sequence='█')

Renders a repeating character sequence of given length respecting the context.direction

This is an antique method from a time when there was no drawing API. Prefer screen.draw.line for mor control. Args:

  • pos (2-sequence): coordinates where to start drawing

  • length (int): length of character sequence to render

  • sequence (str): Text to render at position - defaults to full-block character

Draws a vertical or horizontal line of characters, repeating the characteres of the sequence given, up to the specified length. Can be used to draw lines of aritrary characters or short words. The line directin is taken from the context’s direction.

print(text, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None, **kwargs)

Prints a text sequence following the last character printed

Args:
  • text: Text to render at position

Context’s attributes are respected when printing

print_at(pos, text, size=1, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None, font=None, direction=None)

Positions the cursor and prints a text sequence

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

  • text: Text to render at position

  • size: Text-size to print:

    1 or “normal”: plain text 2 or “braille”: 8x8 font rendered using 2x4 Braille characters for subpixels 3 or “sextant”: 8x8 font rendered using 2x3 Vintage Charset characters for subpixels 4 or “high”: 8x8 font rendered using 2x2 Block characters for subpixels (4,8) or “square”: 8x8 font rendered using 1x2 Half-Block characters for subpixels 8 or “block”: 8x8 font rendered using 1 Block characters as pixels

Context’s attributes are respected when printing

process_events()

Dispatches procss-wide events (like keyboard and mouse if enabled)

This will be called automatically on “self.update” - it is set as a separate method because one could call this to get input events before proceeding with the actual display update.

reset_at(pos)

Resets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

To be used as a callback to .draw.reset - but there are no drawbacks in being called directly.

set_at(pos, pixel=None)

Sets pixel at given coordinate

Args:
  • pos (2-sequence): pixel coordinate

  • pixel (Optional[Pixel]): sets the context values according to pixel attributes prior to printing

To be used as a callback to .draw.set - but there are no drawbacks in being called directly.

update(pos1=None, pos2=None)

Main method to update the display

An interactive application or animation should call this once per frame to have th display contents updated on the terminal.

It can optionally update just a part of the output screen, if pos1 or pos2 are given.

As of pre-0.4.0 development an app should manually provide its “mainloop” and call this on each frame. Later development will probably have an optional higher level loop that will automate calling here.

Args:
  • pos1, pos2: Corners of a rectangle delimitting the area to be updated.

    (optionally, ‘pos1’ can be a Rect object)

commands = None

Namespace for low-level rendering commands, an instance of JournalingCommandsMixin. This attribute can be used as a context manager to group various output operations in a single block that is rendered at once.

context

Namespace to configure drawing and printing color and other parameters. Currently, the attributes that are used from here are color, background, direction, effects and char.

data = None

Instance contaning a mirror of the screen contents and attributes. All Screen drawing attributes are mirrored in it, but it can be updated independently and blitted to the terminal later by calling Screen.update.

draw = None

Namespace for drawing methods, containing an instance of the Drawing class

high = None

Namespace to allow high-resolution drawing using a HighRes instance One should either use the public methods in HighRes or the methods on the Drawing instance at Screen.high.draw to do 1/2, 1/4, 1/6 and 1/8 block pixel manipulation.

last_background = None

Internal: tracks last used background attribute to avoid mangling and enable optimizations

last_color = None

Internal: tracks last used foreground attribute to avoid mangling and enable optimizations

last_effects = None

Internal: tracks last used effects attribute to avoid mangling and enable optimizations

lock = <unlocked _thread.lock object>

Lock to avoid ANSI sequence mangling if used in multi-threading

class terminedia.ScreenCommands(absolute_movement=True, force_newlines=False)

Low level functions to execute ANSI-Sequence-related tasks on the terminal.

Although not private, this class is meant to be used internally by the higher level Screen and Drawing classes. One might use these functions directly if there is no interest in the other functionalities of the library, though, or, to make use of a custom ANSI sequence which is not available in the higher level API.

CSI(*args, file=None)

Writes a CSI command to the terminal

Args:
  • *args: Sequence of parameters to the command, including the last

    one that should be a letter specifying the command

Just a fancy way to print the ANSI “CSI” (Control Sequence Introducer”) commands These are commads stated with the “<ESC>[” sequence.

Check https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences for available commands

RCP(file=None)

Restores saved cursor position (in the TTY software)

SCP(file=None)

Saves the current cursor position (in the TTY software)

SGR(*args, file=None)

Writes a SGR command (Select Graphic Rendition)

Args:
  • *args: Sequence of parameters to the SGR command,

This function calls .CSI with the command fixed as “m”

which is “SGR”.

__init__(absolute_movement=True, force_newlines=False)

Initialize self. See help(type(self)) for accurate signature.

apply_unicode_effects(txt, effects=None)
clear(file=None)

Writes ANSI Sequence to clear the screen

cursor_hide(file=None)

Writes ANSI Sequence to hide the text cursor

cursor_show(file=None)

Writes ANSI Sequence to show the text cursor

down(amount=1, file=None)

Writes ANSI Sequence to move cursor down

fast_render(data, rects=None, file=None)
home(file=None)
left(amount=1, file=None)

Writes ANSI Sequence to move cursor left

moveto(pos, file=None)

Writes ANSI Sequence to position the text cursor

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

Please note that ANSI commands count screen coordinates from 1, while in this project, coordinates start at 0 to conform to graphic display expected behaviors

print(*texts, pos=None, context=None, color=None, background=None, effects=None, file=None, flush=False, sep=' ', end='\n')

Method to print a straightforward rich-text string to the terminal

Params:

*texts: List[str]: strings to print pos: Optional[Tuple[int, int]]: Terminal position to print to context: Optional[terminedia.Context instance] color: Union[terminedia.Color, str, Tuple[int, int, int], Tuple[float, float, float]] : foreground color to use background: Union[terminedia.Color, str, Tuple[int, int, int], Tuple[float, float, float]] : background color to use effects: terminedia.Effects : effect or effect combination to apply to characters before printing file, flush, sep, end: The same as standard Python’s print

print_at(pos, text, file=None)

Positions the cursor and prints a text sequence

Args:
  • pos (2-sequence): screen coordinates, (0, 0) being the top-left corner.

  • txt: Text to render at position

There is an optimization that avoids re-issuing cursor-positioning ANSI sequences for repeated calls of this function - this uses a class attribute so that different Screen instances won’t clash, but might yield concurrency problems if appropriate locks are not in place in concurrent code.

reset_colors(file=None)

Writes ANSI sequence to reset terminal colors to the default

restore_cursor_position(file=None)

Restores saved cursor position (in the TTY software)

right(amount=1, file=None)

Writes ANSI Sequence to move cursor right

save_cursor_position(file=None)

Saves the current cursor position (in the TTY software)

set_bg_color(color, file=None)

Writes ANSI sequence to set the background color color: RGB 3-sequence (0.0-1.0 or 0-255 range) or color constant

set_effects(effects, *, reset=True, turn_off=False, update_active_only=False, file=None)

Writes ANSI sequence to set text effects (bold, blink, etc…)

When using the high-level drawing functions, each time a text-effect attribute is changed, all text effects are reset. The turn_off and reset parameters are suplied for low-level use of this function.

  • Args: effects (terminedia.Effects): enum specifying which text effects should be affected reset (bool): When True, all effect attributes on the screen are reset to match

    the passed effects description. (i.e. if blinking is currently on, and effects == Effect.underline, blinking will be turned off, and only underline will be active). If reset is False, only the underline terminal property will be affected by this call

    turn_off (bool): Only used when “reset” is False: meant to indicate

    the specified effects should be turnned off instead of on.

    update_active_only (bool): if set, won’t issue any commands to terminal, just

    modify internal state so that effetcs that trigger character translations are activated.

set_fg_color(color, file=None)

Writes ANSI sequence to set the foreground color color: RGB 3-sequence (0.0-1.0 or 0-255 range) or color constant

toggle_buffer(file=None)
up(amount=1, file=None)

Writes ANSI Sequence to move cursor up

last_pos = None
locks = {}
class terminedia.Sprite(shapes, pos=(0, 0), active=True, tick_cycle=1, anchor='topleft', alpha=True)

Sprites are meant to be associated with Shapes

They themselves contain a collection of shapes, a position relative to the top-left or center location of the base shape on the host shape.

When the base shape is rendered (using blit or screen.update), if the sprite is active, corresponding pixels are picked from the sprite. Thus, a sprite can be moved around the host shape by changes to its .pos attribute, without interfering with the host’s contents.

If more than one shape is in the collection, there is always one active shape selected by the current “tick” mod self.tick_cycle: this provides a descomplicated way to have an animated shape; (“tick” is a global value increased by one each time Screen.update() is called)

(Each shape on a sprite can, in turn, be host to text planes, and other sprites as needed)

__init__(shapes, pos=(0, 0), active=True, tick_cycle=1, anchor='topleft', alpha=True)

Initialize self. See help(type(self)) for accurate signature.

get_at(pos=None, container_pos=None, pixel=None)
kill()
owner_coords(rect, where=None)
absrect
active
dirty_rects
pos
rect
shape
class terminedia.Transformer(pixel=None, char=None, foreground=None, background=None, effects=None)
__init__(pixel=None, char=None, foreground=None, background=None, effects=None)

Class implementing a generic filter to be applied on a shape’s pixels when their value is read.

The parameters for __init__ are slots that will generate or transform the corresponding value on the final pixel

Each slot can be None, a static value, or a callable.

Each of these callables can have in the signature named parameters with any combination of

“self, “value”, “char”, “foreground”, “background”, “effects”, “pixel”, “pos”, “source”, “context”, “tick” Each of these named parameters will be injected as an argument when the it is called.

  • “self”: Transformer instance (it is, as the others, optional)

  • “value”: the current value for this channel

  • “char, foreground, background, effects”: the content of the respective channel

  • “pos”: the pixel position,

  • “pixel” meaning the source pixel as transformed to this point on the pipeline ,

  • “source” meaning

    the whole source shape. The callable should be careful to read the shape with “get_raw”, and not using __getitem__ to avoid an infinite loop (an evolution of this may give a ‘transformed down to here’ view of the shape, or a 3x3 and 5x5 kernel options)

  • “tick” meaning the “frame number” from app start, and in the future

    will be used for animations.

Depending where the transformers are used, more input parameters may be available - they have to be set as instance attributes in the Transformer instance prior to rendering. For rich-text rendering embedded transformers (see terminedia.text.planes and terminedia.txt.sprites), for example, the following attribute are available:

  • “sequence_index”: index of the current character inside the string

    affected by the Transformer

  • “sequence_len”: length of the string affected by the Transformer

  • “sequence”: actual text spam affected by the Transformer

  • “sequence_absolute_start”: index in the text being rendered the transformer was made active

It should return the value to be used downstream of the named channel.

background = None
channels = ['pixel', 'char', 'foreground', 'background', 'effects']
char = None
effects = None
foreground = None
pixel = None
class terminedia.TransformersContainer(*args)
__init__(*args)

Initialize self. See help(type(self)) for accurate signature.

bake(shape, target=None, offset=(0, 0))

Apply the transformation stack for each pixel in the given shape

Args:
  • shape: Source shape object to be processed

  • target [Optional]: optional target where final pixels are blitted into.

    If target is not given, ‘shape’ is modified inplace. Defaults to None.

  • offset: pixel-offset to blit the data to. Most useful with the target

option.

Returns:

the affected Shape object

insert_hook(item)
process(source, pos, pixel)

Called automatically by FullShape.__getitem__

Only implemented for pixels with all attributes (used by fullshape)

remove(tr)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

stack
class terminedia.V2(*args, **kw)

2-component Vector class to ease drawing

Works as a 2-sequence, but offers “x” and “y” properties to the coordinates as well as basic operations. As V2 inherits from Python’s tuple, it is imutable and can be used as dictionary keys, among other common sequence operations.

Args:

x (number or 2-sequence): 1st vector coordinate or 2-sequence with coordinates y (number): 2nd vector coordinate. Ignored if x is a sequence

Suported ops:
    • (__add__): Adds both components of 2 vectors

    • (__sub__): Subtracts both components of 2 vectors.

    • (__mul__): Multiplies vector components by a scalar

  • abs (__abs__): Returns vector length

__init__(*args, **kw)

Initialize self. See help(type(self)) for accurate signature.

max(other)
min(other)
area
as_int
x
y
class terminedia.ValueShape(data, color_map=None, size=None, **kwargs)
PixelCls

alias of Pixel

__getitem__(pos)

Composes a Pixel object for the given coordinates.

__init__(data, color_map=None, size=None, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__setitem__(pos, value)

Values set for each pixel are 3-sequences with an RGB color value

terminedia.ainput(prompt='', maxwidth=None, insert=True, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)
terminedia.cls()

Clears the output terminal.

(if using Screen prefer “Screen.clear()”)

terminedia.getch(timeout=0) → str

Enters non-blocking keyboard mode and returns the first keypressed Args:

  • timeout (float): time in seconds to wait. If 0 (default), waits forever

terminedia.pause(timeout=0) → None

Enters non-blocking keyboard mode and waits for any keypress Args:

  • timeout (float): time in seconds to wait. If 0 (default), waits forever

terminedia.render(text, font=None, shape_cls=<class 'terminedia.image.PalettedShape'>, direction=Directions.RIGHT)
terminedia.shape(data, color_map=None, promote=False, resolution=None, **kwargs)

Factory for shape objects

Args:
  • data (Filepath to image, open file, image data as text or list of strings)

  • color_map (optional mapping): color map to be used for the image - mapping characters to RGB colors.

  • promote (boolean): Whether to force resulting shape to a FullShape (defaults to False)

  • resolution (str): If promote is True, resolution namespace to use on blitting to

    FullShape (“square”, “high”, “square”)

  • **kwargs: parameters passed transparently to the selected shape class

Based on inferences on the data attribute, selects the appropriate Shape subclass to handle the “data” attribute. That is: given a string without newlines, it is interpreted as a filepath, and if PIL is installed, an RGB “ImageShape” class is used to read the image data. If text with “

is passed in, an PalettedShape is used to directly use the passed data as pixels.

Returns an instance of the selected class with the data set.

terminedia.sinput(prompt='', maxwidth=None, insert=True, *, char=None, color=None, foreground=None, background=None, effects=None, fill=None, context=None)
terminedia.terminedia_main(screen=None, context=None)

Terminedia mainloop - Framework support for interactive applications and animations

Usage: … import asyncio from terminedia import terminedia_main

## setup screen, elements and event callback functions screen = terminedia.Screen() …

asyncio.run(terminedia_main, screen) #EOF

Any code can dispatch an events.EndLoop event to exit the automatic mainloop update.

(history: up to now (4/2021) anyne developing using terminedia was suppsed to code their own loop, and call screen.update() on each frame)