Skip to main content

`curses-colors` is a Python module that provides a simple interface for managing color pairs in a terminal using the `curses` library.

Project description

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,

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

curses_colors-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

curses_colors-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file curses_colors-0.1.0.tar.gz.

File metadata

  • Download URL: curses_colors-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for curses_colors-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6cdbca77d1c566a55bcfe88892c3dc32fba44283a47b385e64d303362ff5775d
MD5 5d40fa3a19346df0be0808fa56c1c554
BLAKE2b-256 5c7567c294b2f3b913e44666bd77c8614039bbb6b1dd1f8b0cae15a123b27b93

See more details on using hashes here.

File details

Details for the file curses_colors-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: curses_colors-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for curses_colors-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1195328b43db93c20b0d8ce4b6a36587fe8a6c0d29bb6c8ebc69c87fe186f1c
MD5 4afa8ceed8be2a671181cfd190277583
BLAKE2b-256 c8672a43da1c4cc55b373ce65d18284e8d86695d4b9039e4833e480ac7e9c7a3

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