Skip to main content

curses-colors

curses-colors is a Python module that provides a simple interface for managing color pairs in a terminal using the curses library. This module allows you to easily initialize and access various color combinations for terminal applications.

Installation

To use the curses-colors module, ensure you have Python installed on your system. The curses library is included with Python on Unix-like systems. For Windows, you may need to install a compatible version of the curses library, such as windows-curses.

Usage

Importing the Module

To use the curses-colors module, you need to import it into your Python script:

import curses
from curses_colors import Colors

Initializing Colors

Before using any color pairs, you must initialize them. This is done by calling the init_colors method of the Colors class. Make sure to do this after initializing the curses screen.

def main(stdscr):
    # Initialize colors
    Colors.init_colors()
    
    # Example usage of color pairs
    stdscr.addstr(0, 0, "Hello, World!", Colors.RED_BLACK)
    stdscr.refresh()
    stdscr.getch()

curses.wrapper(main)

Accessing Color Pairs

The color pairs are defined as class attributes in the Colors class. You can access them using the format Colors.<BACKGROUND>_<FOREGROUND>. Here are the available color pairs:

  • Colors.BLACK_BLACK
  • Colors.BLACK_RED
  • Colors.BLACK_GREEN
  • Colors.BLACK_YELLOW
  • Colors.BLACK_BLUE
  • Colors.BLACK_MAGENTA
  • Colors.BLACK_CYAN
  • Colors.BLACK_WHITE
  • Colors.RED_BLACK
  • Colors.RED_RED
  • Colors.RED_GREEN
  • Colors.RED_YELLOW
  • Colors.RED_BLUE
  • Colors.RED_MAGENTA
  • Colors.RED_CYAN
  • Colors.RED_WHITE
  • Colors.GREEN_BLACK
  • Colors.GREEN_RED
  • Colors.GREEN_GREEN
  • Colors.GREEN_YELLOW
  • Colors.GREEN_BLUE
  • Colors.GREEN_MAGENTA
  • Colors.GREEN_CYAN
  • Colors.GREEN_WHITE
  • Colors.YELLOW_BLACK
  • Colors.YELLOW_RED
  • Colors.YELLOW_GREEN
  • Colors.YELLOW_YELLOW
  • Colors.YELLOW_BLUE
  • Colors.YELLOW_MAGENTA
  • Colors.YELLOW_CYAN
  • Colors.YELLOW_WHITE
  • Colors.BLUE_BLACK
  • Colors.BLUE_RED
  • Colors.BLUE_GREEN
  • Colors.BLUE_YELLOW
  • Colors.BLUE_BLUE
  • Colors.BLUE_MAGENTA
  • Colors.BLUE_CYAN
  • Colors.BLUE_WHITE
  • Colors.MAGENTA_BLACK
  • Colors.MAGENTA_RED
  • Colors.MAGENTA_GREEN
  • Colors.MAGENTA_YELLOW
  • Colors.MAGENTA_BLUE
  • Colors.MAGENTA_MAGENTA
  • Colors.MAGENTA_CYAN
  • Colors.MAGENTA_WHITE
  • Colors.CYAN_BLACK
  • Colors.CYAN_RED
  • Colors.CYAN_GREEN
  • Colors.CYAN_YELLOW
  • Colors.CYAN_BLUE
  • Colors.CYAN_MAGENTA
  • Colors.CYAN_CYAN
  • Colors.CYAN_WHITE
  • Colors.WHITE_BLACK
  • Colors.WHITE_RED
  • Colors.WHITE_GREEN
  • Colors.WHITE_YELLOW
  • Colors.WHITE_BLUE
  • Colors.WHITE_MAGENTA
  • Colors.WHITE_CYAN
  • Colors.WHITE_WHITE

Example

Here is a complete example of how to use the curses-colors module:

import curses
from curses_colors import Colors

def main(stdscr):
    # Initialize colors
    Colors.init_colors()
    
    # Clear the screen
    stdscr.clear()
    
    # Display text with different color pairs
    stdscr.addstr(0, 0, "This is black text on a white background", Colors.WHITE_BLACK)
    stdscr.addstr(1, 0, "This is red text on a black background", Colors.RED_BLACK)
    stdscr.addstr(2, 0, "This is green text on a yellow background", Colors.GREEN_YELLOW)
    
    # Refresh the screen to show changes
    stdscr.refresh()
    
    # Wait for user input
    stdscr.getch()

curses.wrapper(main)

License

This module is released under the MIT License. See the LICENSE file for more details.

Contributing

If you would like to contribute to this project, feel free to submit a pull request or open an issue for any bugs or feature requests.

Acknowledgments

This module utilizes the curses library,

Metadata

Release files for curses-colors 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for curses-colors 0.1.0
File Size Uploaded
curses_colors-0.1.0.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for curses-colors 0.1.0
File Interpreter ABI Platform
curses_colors-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / curses_colors-0.1.0.tar.gz

Download URL curses_colors-0.1.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6cdbca77d1c566a55bcfe88892c3dc32fba44283a47b385e64d303362ff5775d
BLAKE2b-256 checksum
How to use checksums
5c7567c294b2f3b913e44666bd77c8614039bbb6b1dd1f8b0cae15a123b27b93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / curses_colors-0.1.0-py3-none-any.whl

Download URL curses_colors-0.1.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1195328b43db93c20b0d8ce4b6a36587fe8a6c0d29bb6c8ebc69c87fe186f1c
BLAKE2b-256 checksum
How to use checksums
c8672a43da1c4cc55b373ce65d18284e8d86695d4b9039e4833e480ac7e9c7a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page