Package: pixy
pixypixy is a Python library for adding colour and style to terminal text.Getting StartedInstallationUsageDocumentationExamplesTestsLicenseTerminal output can be styled usingANSII escape code. pixy provides a simple to use yet comprehensive wrapper, abstracting away the complexities.pixy supports:3-bit, 4-bit and 8-bit colour;24-bit true colour RGB;changing the foreground and background colour;text decorators e.g. blink, underline, bold, italic, strike-through;custom fonts for compliant terminals;custom ANSII codes for development on non-spec-compliant terminals.Getting StartedInstallationpixy can be installed usingpip.$ python3 -m pip install pixyUsagepixy lets you style text straight out of the box.importpixy# Print "Hello World" in red.print(pixy.red("Hello World"))It provides the flexibility to format text as you wish.importpixy# Create a string "Hello" with bold text and blue background.s1=pixy.pring("Hello",pixy.decorators.bold+pixy.background.blue)# Concatenate the two strings, giving everything a red background (the# red background won't be applied to "Hello" because we've already# given it a blue background!)print(pixy.pring(s1+" World. Lorem ipsum dolor...",pixy.background.red))DocumentationNot all terminals support all ANSII escape codes. Please check the terminal you are testing on supports the features you are using before opening an issue.HelpersYou can create a string of a certain colour using the helper functions below:pixy.black(text)pixy.red(text)pixy.green(text)pixy.yellow(text)pixy.blue(text)pixy.magenta(text)pixy.cyan(text)pixy.white(text)Exampleimportpixy# Print "Hello World" in red.print(pixy.red("Hello World"))pixy.pring(text, style)pixy.pringallows you to generate a string with any of the styles documented below. You can use more than one style by adding them together.text- the text to apply the style to.style- the style to apply to the text.Exampleimportpixy# Print "Hello World" with green text and white background.print(pixy.pring("Hello World",pixy.foreground.green+pixy.background.white))pixy.foreground,pixy.backgroundpixy.foregroundandpixy.backgroundcontain the variables:black,red,green,yellow,blue,magenta,cyan,white.Using thepixy.foregroundvariant of the colour will apply the colour
to the foreground and thepixy.backgroundvariant will apply it to the
background.These colours are known as the 3-bit colours and almost all terminals support
them. Most terminals also let you make them bright by adding thepixy.decorators.boldstyle.Exampleimportpixy# Print "Hello World" with green text.print(pixy.pring("Hello World",pixy.foreground.green))pixy.decoratorsDecorators let you apply other styles to the text.DecoratorDescriptionSupportpixy.decorators.boldBold/brightpixy.decorators.faintFaint/dimmedpixy.decorators.italicItalicisedpixy.decorators.underlineUnderlinedpixy.decorators.slow_blinkSlow blink (less than 150 per minute)pixy.decorators.rapid_blinkRapid blink (150+ per minute)Not widely supportedpixy.decorators.invertSwap foreground and background colourspixy.decorators.concealHideNot widely supportedpixy.decorators.strikeStrike-throughpixy.decorators.frakturFrakturRarely supportedpixy.decorators.double_underlineDouble underlinepixy.decorators.framedNot widely supportedpixy.decorators.encircledNot widely supportedpixy.decorators.overlinedOverlined(Descriptions adapted fromWikipedia)Exampleimportpixy# "Hello World" underlined.print(pixy.pring("Hello World",pixy.decorators.underline))pixy.ExtendedColour(code, background=False)Withpixy.ExtendedColouryou can select from a pre-defined selection of 256
colours.code- corresponds to a colour code foundhere.background- boolean value indicating if this is a background or
foreground colour.Exampleimportpixy# Print "Hello World" in violet.print(pixy.pring("Hello World",pixy.ExtendedColour(99)))# Print "Hello World" with a violet background.print(pixy.pring("Hello World",pixy.ExtendedColour(99,True)))pixy.TrueColour(red, green, blue, background=False)Withpixy.TrueColouryou can create an RGB colour.red- value between0and255indicating the intensity of the
red component.green- value between0and255indicating the intensity of the
green component.blue- value between0and255indicating the intensity of the
blue component.background- boolean value indicating if this is a background  or
foreground colour.Exampleimportpixy# Print "Hello World" in violet.print(pixy.pring("Hello World",pixy.TrueColour(238,130,238)))# Print "Hello World" with a violet background.print(pixy.pring("Hello World",pixy.TrueColour(238,130,238,True)))pixy.Font(code)Allows you to change the font used. Most terminals do not support this.code- a number between0and8corresponding to a font.Exampleimportpixyprint(pixy.pring("Hello World",pixy.Font(3)))pixy.EscapeSequence(...)pixy.EscapeSequencecan be used in instances that you want to defined your own ANSII escape sequence.pixy.EscapeSequencetakes a variable number of arguments - each argument should be an ANSII code.Exampleimportpixy# Bright blue using ANSII code 94 supported by some terminalsprint(pixy.pring("Hello World",pixy.EscapeSequence(94)))ExamplesBlinking Textimportpixyprint(pixy.pring("Hello World",pixy.decorators.slow_blink))Concatenationimportpixy# "Hello" in red.s1=pixy.pring("Hello",pixy.foreground.red)# " World" in blue.s2=pixy.pring(" World",pixy.foreground.blue)# Concatenate the strings, add a white background and make# them bold.s3=pixy.pring(s1+s2,pixy.background.white+pixy.decorators.bold)print(s3)Colour shadesimportpixyforiinrange(0,0xFF,3):colour=pixy.TrueColour(i,0,0,background=True)print(pixy.pring(" ",colour),end="")print()foriinrange(0,0xFF,3):colour=pixy.TrueColour(0,i,0,background=True)print(pixy.pring(" ",colour),end="")print()foriinrange(0,0xFF,3):colour=pixy.TrueColour(0,0,i,background=True)print(pixy.pring(" ",colour),end="")print()Colour gradientimportpixydefgradient(colour_a,colour_b):output=[]foriinrange(0,100,2):p=i/100output.append((int(colour_a[0]+p*(colour_b[0]-colour_a[0])),int(colour_a[1]+p*(colour_b[1]-colour_a[1])),int(colour_a[2]+p*(colour_b[2]-colour_a[2]))))returnoutputred_to_green=gradient((255,0,0),(0,255,0))green_to_blue=gradient((0,255,0),(0,0,255))blue_to_red=gradient((0,0,255),(255,0,0))forcolourinred_to_green:print(pixy.pring(" ",pixy.TrueColour(*colour,background=True)),end="")print()forcolouringreen_to_blue:print(pixy.pring(" ",pixy.TrueColour(*colour,background=True)),end="")print()forcolourinblue_to_red:print(pixy.pring(" ",pixy.TrueColour(*colour,background=True)),end="")print()Licensepixy is licensed under theMIT license.