Skip to main content

Extension of terminalio.Terminal that supports ANSI color escapes for subsets of the text

Project description

Introduction

Documentation Status Discord Build Status Code Style: Ruff

Extension of supports ANSI color escapes for subsets of text

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-color-terminal

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-color-terminal

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .env/bin/activate
pip3 install adafruit-circuitpython-color-terminal

Installing to a Connected CircuitPython Device with Circup

Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:

pip3 install circup

With circup installed and your CircuitPython device connected use the following command to install:

circup install adafruit_color_terminal

Or the following command to update an existing version:

circup update

Usage Example

import supervisor
from displayio import Group
from terminalio import FONT

from adafruit_color_terminal import ColorTerminal

main_group = Group()
display = supervisor.runtime.display
font_bb = FONT.get_bounding_box()
screen_size = (display.width // font_bb[0], display.height // font_bb[1])

terminal = ColorTerminal(FONT, screen_size[0], screen_size[1])
main_group.append(terminal.tilegrid)

black = chr(27) + "[30m"
red = chr(27) + "[31m"
green = chr(27) + "[32m"
yellow = chr(27) + "[33m"
blue = chr(27) + "[34m"
magenta = chr(27) + "[35m"
cyan = chr(27) + "[36m"
white = chr(27) + "[37m"
reset = chr(27) + "[0m"


message = f"Hello {green}World{reset} {yellow}ANSI\n"
terminal.write(message)
print(message, end="")

message = f"{magenta}Terminal {red}Colors{reset}"
terminal.write(message)
print(message)

display.root_group = main_group

print(terminal.cursor_x, terminal.cursor_y)

move_cursor = chr(27) + "[10;10H"
terminal.write(f" Something {move_cursor}{cyan} Else{reset}")
print(f" Something {move_cursor}{cyan} Else{reset}")

while True:
    pass

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adafruit_circuitpython_color_terminal-0.2.2.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file adafruit_circuitpython_color_terminal-0.2.2.tar.gz.

File metadata

File hashes

Hashes for adafruit_circuitpython_color_terminal-0.2.2.tar.gz
Algorithm Hash digest
SHA256 975cf25dfa6c3d6509056204885ee9817c87e8616cc080f667407c07aa960d54
MD5 e54bd0e920bf52bc2a991c1a2f93b31d
BLAKE2b-256 1ae1779b58cb79bcb83d635b2bdad14734bb2954a337b5adcfc718790c8776da

See more details on using hashes here.

File details

Details for the file adafruit_circuitpython_color_terminal-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for adafruit_circuitpython_color_terminal-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 edfef4c70e4113b125bdeb3d5279ada19d38b3f1c98c08a5adb8e48950aab1d2
MD5 62e0e4bdd130781f391dc8b86f18a991
BLAKE2b-256 97b237fa76f21b71fe647720d738fd06c9426e26a7c130395e3901e38af7e85f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page