{"id":19724135,"url":"https://github.com/rory660/colortext","last_synced_at":"2025-02-27T18:47:51.919Z","repository":{"id":203950637,"uuid":"169985446","full_name":"rory660/colorText","owner":"rory660","description":"Python module that handles ANSI color codes and text effects.","archived":false,"fork":false,"pushed_at":"2019-02-10T15:12:13.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-10T16:44:18.247Z","etag":null,"topics":["ansi-escape-sequences","color","module","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rory660.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-02-10T14:14:23.000Z","updated_at":"2023-06-10T14:39:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"3113e333-1b68-41ce-97a6-65b7f4df8cc3","html_url":"https://github.com/rory660/colorText","commit_stats":null,"previous_names":["rory660/colortext"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rory660%2FcolorText","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rory660%2FcolorText/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rory660%2FcolorText/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rory660%2FcolorText/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rory660","download_url":"https://codeload.github.com/rory660/colorText/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241045605,"owners_count":19899682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-escape-sequences","color","module","python3"],"created_at":"2024-11-11T23:24:37.211Z","updated_at":"2025-02-27T18:47:51.869Z","avatar_url":"https://github.com/rory660.png","language":"Python","readme":"# colorText.py\nPython module that handles ANSI color codes and text effects.\n\n## Functions\n\n### generate8BitColor\n```python\ngenerate8BitColor(colorValue, type = FOREGROUND)\n```\n\n#### Parameters:\n+ `colorValue`: Integer value between 0 and 255 (inclusive) corresponding to the color.\n+ `type = FOREGROUND`: type of colour to generate (can be `colorText.FOREGROUND` or `colorText.BACKGROUND`)\n\n#### Return:\nA string containing the color value for use in an ANSI escape sequence.\n\n---\n### generateRgbColor\n```python\ngenerateRgbColor(red, green, blue, type = FOREGROUND)\n```\n\n#### Parameters:\n+ `red`: Integer value between 0 and 255 (inclusive) corresponding to the red level.\n+ `green`: Integer value between 0 and 255 (inclusive) corresponding to the green level.\n+ `blue`: Integer value between 0 and 255 (inclusive) corresponding to the blue level.\n+ `type = FOREGROUND`: type of colour to generate (can be `colorText.FOREGROUND` or `colorText.BACKGROUND`)\n\n#### Return:\nA string containing the color value for use in an ANSI escape sequence.\n\n---\n### combineFgBgColor\n```python\ncombineFgBgColor(fg, bg)\n```\n\n#### Parameters:\n+ `fg`: Foreground color as a string (e.g. `colorText.BLUE`, `generate8BitColor(180)`, etc).\n+ `bg`: Background color as a string.\n\n#### Return:\nA string containing the combined color values for use in an ANSI escape sequence.\n\n---\n### coloriseText\n```python\ncoloriseText(text, color, effects = [])\n```\n\n#### Parameters:\n+ `text`: A string of text to have the given color and list of effects applied to.\n+ `color`: Color to be applied to the text string.\n+ `effects = []`: A list of text effects (defined as constants, e.g. colorText.BOLD).\n\n#### Return:\nA string containing the original `text` string, wrapped with escape sequences to set the color and text effects.\n\n---\n### setColorMode\n\nSets the terminal to print with the given color and set of effects.\n\n```python\nsetColorMode(color = 0, effects = [])\n```\n\n#### Parameters:\n+ `color = 0`: Color mode to set the terminal to.\n+ `effects = []`: A list of text effects (defined as constants, e.g. colorText.BOLD).\n\n#### Return:\nNone.\n\n---\n### coloriseFunction\nDecorator factory used to wrap a function with calls to `setColorMode`, allowing for the function to be ran with a given print color and set of effects.\n\n```python\ncoloriseFunction(color, effects = [])\n```\n\n#### Parameters:\n+ `color = 0`: Color mode to set the terminal to.\n+ `effects = []`: A list of text effects (defined as constants, e.g. colorText.BOLD).\n\n#### Return:\nA decorator that takes a function as an argument.\n\n#### Example:\nThe following code is used in the module to create `printRed(text, **kwargs)`:\n```python\n@coloriseFunction(RED, [BOLD])\ndef printRed(text, **kwargs):\n\tprint(text, **kwargs)\n```\n\n---\n### runFunctionColored\n\nRuns a function with calls to `setColorMode`, causing the function to be ran with a given print color and set of effects.\n\n```python\nrunFunctionColored(func, color, effects, *args, **kwargs)\n```\n\n#### Parameters:\n+ `func`: function to be ran.\n+ `color`: Color mode to set the terminal to.\n+ `effects`: A list of text effects (defined as constants, e.g. colorText.BOLD).\n+ `*args`: The anonymous arguments to be passed to `func`.\n+ `**kwargs`: The named arguments to be passed to `func`.\n\n#### Return:\nReturns the return value of `func`.\n\n---\n### printColored\n\nPrints a given string with a given color and set of text effects. Accepts the same named arguments as `print`.\n\n```python\nprintColored(text, color, effects = [], **kwargs)\n```\n\n#### Parameters:\n+ `text`: A string of text to be printed.\n+ `color`: Color for the text to be printed in.\n+ `effects`: A list of text effects (defined as constants, e.g. colorText.BOLD) to be applied to `text` when printing.\n+ `**kwargs`: Named arguments identical to those accepted by the `print` function.\n\n#### Return:\nNone.\n\n---\n### print\\\u003ccolor\\\u003e\n\nPrints the given string in the color specified in the function name.\n\n```python\nprintBlack(text, **kwargs)\nprintRed(text, **kwargs)\nprintGreen(text, **kwargs)\nprintYellow(text, **kwargs)\nprintBlue(text, **kwargs)\nprintMagenta(text, **kwargs)\nprintCyan(text, **kwargs)\nprintWhite(text, **kwargs)\n```\n\n#### Parameters:\n+ `text`: A string of text to be printed.\n+ `**kwargs`: Named arguments identical to those accepted by the `print` function.\n\n#### Return:\nNone.\n\n## Constants\n```python\n# Text effects\nDEFAULT = 0 # Reset all colors and effects\nBOLD = 1 # Make text bold / Increase color intensity\nFAINT = 2 # make text faint / Decrease color intensity\nITALIC = 3\nUNDERLINE = 4\nSLOW_BLINK = 5 # \u003c 150 per minute\nRAPID_BLINK = 6 # \u003e 150 per minute\nINVERSE = 7 # Swaps foreground and background colors\nCONCEAL = 8\nCROSSED_OUT = 9\nPRIMARY_FONT = 10 # Select primary / default font\nALT_FONT = 11 # Select alternative font\nFRAKTUR = 20 \n\n# Disable various text effects\nDISABLE_BOLD = 21\nDISABLE_BOLD_FAINT = 22\nDISABLE_ITALIC_FRAKTUR = 23\nDISABLE_UNDERLINE = 24\nDISABLE_BLINK = 25\nDISABLE_INVERSE = 27\nDISABLE_CONCEAL = 28\nDISABLE_CROSSED_OUT = 29\n\n# 4-bit foreground colors\nBLACK = 30\nRED = 31\nGREEN = 32\nYELLOW = 33\nBLUE = 34\nMAGENTA = 35\nCYAN = 36\nWHITE = 37\n\nFOREGROUND = 38 # Use in generateColor functions to set as foreground color\nDEFAULT_FOREGROUND = 39 # Reset foreground color\n\n# 4-bit background colors\nBG_BLACK = 40\nBG_RED = 41\nBG_GREEN = 42\nBG_YELLOW = 43\nBG_BLUE = 44\nBG_MAGENTA = 45\nBG_CYAN = 46\nBG_WHITE = 47\n\nBACKGROUND = 48 # Use in generateColor functions to set as background color\nDEFAULT_BACKGROUND = 49 # Reset background color\n\n# Other text effects\nFRAMED = 51\nENCIRCLED = 52\nOVERLINED = 53\nDISABLE_FRAMED_ENCIRCLED = 54\nDISABLE_OVERLINED = 55\n\n# Ideogram effects\nIDEOGRAM_UNDERLINE = 60\nIDEOGRAM_DOUBLE_UNDERLINE = 61\nIDEOGRAM_OVERLINE = 62\nIDEOGRAM_DOUBLE_OVERLINE = 63\nIDEOGRAM_STRESS_MARKING = 64\nDISABLE_IDEOGRAM_EFFECTS = 65\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frory660%2Fcolortext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frory660%2Fcolortext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frory660%2Fcolortext/lists"}