Package: fancyprint
Fancy PrintAn aesthetic replacement to print()Development Status:Early Development/UsableAboutFancyPrint is a python package, making it easier for developers to get beautiful CLI with responsiveness in regards to terminal size.UsageInstalling FancyPrintTo install fancyprint use the following command:pipinstallfancyprintThis will install all dependencies needed as well.Getting StartedTo start using Fancy Print, first import it.importfancyprintThis will import all the necessary functions required.BasicsPrintingThepretty_print()function is for printing text to the terminal. Here is an example:pretty_print("This is some text",align=Align.LEFT)It is using the default preset, which can be changed by using presets or changing argument values.
There are two ways one customize and use it, and they can be
used interchangeably:Using presets (recommended)Using keyword argumentsUsing PresetsPresets allow you to customize the printer and the separator, and they can belocalpresets orglobalpresets.
Presets are local when they are created for one part only(i.e Printer) and are global when they can be used anywhere
(both in the Separator and the Printer).Using Local PresetsThere are two types of local presets you can use:PrinterPresetSeparatorPresetPrinterPresetThePrinterPresetis used to customize thepretty_print()function. To use it, you need to import it first.
Here is an example of declaring aPrinterPreset:fromfancyprint.ftypesimportPrinterPresetfromfancyprint.ftypesimportColormy_custom_printer_preset=PrinterPreset(delimiter_left="<",delimiter_left_color=Color.RED,delimiter_right=">",delimiter_right_color=Color.RED,delimiter_space_amount=10,delimiter_space_symbol=" ",hyphenation=False)Here's the preset in action:[...]pretty_print("Hi this is some text",preset=my_custom_printer_preset)This will print the following:That looks awful right now. That is because we have a custom printer preset, but the separator is using
the default preset. Let's make it more good-looking by using a custom separator preset!SeparatorPresetTheSeperatorPresetis used to customize the separator, whether it is used alone or with the printer. To use it, it
needs to be imported first. Here is an example of declaring one:fromfancyprint.ftypesimportSeparatorPreset,Colormy_custom_separator_preset=SeparatorPreset(delimiter_left="<",delimiter_left_color=Color.RED,delimiter_right=">",delimiter_right_color=Color.RED,delimiter_space_symbol=" ",delimiter_space_amount=10,separator_symbol="-",separator_color=Color.BLUE,)Now let's use this preset, in the previous example:[...]pretty_print("Hi, this is some text!",preset=my_custom_printer_preset,separator_preset=my_custom_separator_preset)The above will print the following:It's starting to look good now, but since we are going to use one preset everywhere,in this example,
we should create a global preset.Using the Global PresetThePresetclass is used to create a global preset, and can be given to both the separator and the printer, which
makes it useful if the whole program is to follow a simple theme. To use it you need to import thePreset, along
with the local presets, which make it easy to declare a global Preset. Here's an example of declaring a global preset,
using our previously declared local presets:[...]fromfancyprint.ftypesimportPresetglobal_preset=Preset(printer_preset=my_custom_printer_preset,separator_preset=my_custom_separator_preset,)The previous example, but with a global preset would like:[...]pretty_print("Hi, this is some text!",preset=global_preset,separator_preset=global_preset)This will print:Using Keyword ArgumentsIf you want to have different customizations, you could use presets, but if you only want to change some aspects of the
printer, you might want to use the function's keyword arguments instead. Here's a list of available customizations you
can do with arguments:align | Align(Enum): Changes the alignment of the textdelimiter_left | str: Symbol for the left delimiterdelimiter_left_color | Color: Color for the left delimiterenable_left_delimiter | bool: Whether to print the left delimiter or notdelimiter_right | str: Symbol for the right delimiterdelimiter_right_color | Color: Color to be used for the right delimiterenable_right_delimiter | bool: Whether to print the right delimiterdelimiter_space_amount | int: Amount of space to print after/before the delimitersdelimiter_space_symbol | str: Symbol to be used for the delimiter space (" " is the default and is useful for most cases)separator_left_delimiter | str: Symbol for the left delimiter of the separatorsseparator_left_delimiter_color | Color: Color for the left delimiters of the separatorsenable_left_separator_delimiter | bool: Whether to print the left delimiter in the separatorsseparator_right_delimiter | str: Symbol for the right delimiter of the separatorsseparator_right_delimiter_color | Color: Color for the right separator delimitersenable_right_separator_delimiter | bool: Whether to print the right delimiter in the separatorsseparator_symbol | str: Symbol for the separatorseparator_color | Color: Color for the separator symbolenable_separator_symbol | bool: Whether to print the separator symbol, if false then " " will be printedseparator_delimiter_space_amount | int: Amount of delimiter space in the separatorseparator_delimiter_space_symbol | str: Symbol for the delimiter space in the separatorenable_back_separator | bool: Whether to print the back separatorenable_front_separator | bool: Whether to print the front separatortest_mode | bool: If you want to mess with the alignment calculationstesting_terminal_width | int: Artificial terminal width to use, for testing or for making something beautiful ;)AlignmentThere are three alignment options available at the moment. They are left, right and center. To use alignments, you need
to import the Align enum from the ftypes subpackage. Here are examples of using the different alignments:[...]fromfancyprint.ftypesimportAlignpretty_print("Hi, this is some text!",align=Align.LEFT)pretty_print("Hi, this is some text!",align=Align.CENTER)pretty_print("Hi, this is some text!",align=Align.RIGHT)The above gives the following results:Doesn't look too nice, let's remove some separators:[...]pretty_print("Hi, this is some text!",align=Align.LEFT)pretty_print("Hi, this is some text!",align=Align.CENTER,enable_back_separator=False)pretty_print("Hi, this is some text!",align=Align.RIGHT,enable_back_separator=False)Much better. You might also want some "padding", which is called "delimiter space" in the function. Let's add some
delimiter space to the print statements![...]pretty_print("Hi, this is some text!",align=Align.LEFT,delimiter_space_amount=10)pretty_print("Hi, this is some text!",align=Align.CENTER,enable_back_separator=False,delimiter_space_amount=10)pretty_print("Hi, this is some text!",align=Align.RIGHT,enable_back_separator=False,delimiter_space_amount=10)Everything looks good to this point. But you might want to see where the spaces are. You might do something like this:[...]pretty_print("Hi, this is some text!",align=Align.LEFT,delimiter_space_amount=10,delimiter_space_symbol="=")pretty_print("Hi, this is some text!",align=Align.CENTER,enable_back_separator=False,delimiter_space_amount=10,delimiter_space_symbol="=")pretty_print("Hi, this is some text!",align=Align.RIGHT,enable_back_separator=False,delimiter_space_amount=10,delimiter_space_symbol="=")SeparationOther than being used in the print function, you can also use theseparater_line()function to print a separator line.
As in like in printing, you can also use the separator with both a preset or keyword arguments. We already covered the
separator preset inUsing Local Presets, so it will not be in this section.
The following keyword arguments are available for customizations:preset | Preset, SeparatorPreset: If you want to use a presetdelimiter_left | str: Symbol for the left delimiterdelimiter_left_color | Color: Color for the left delimiterenable_left_delimiter | bool: Whether to print the left delimiterdelimiter_right | str: Symbol for the right delimiterdelimiter_right_color | Color: Color for the right delimiterenable_delimiter_right | bool: Whether to print the right delimiterdelimiter_space_amount | int: Amount of delimiter space to printdelimiter_space_symbol | str: Symbol for the delimiter spaceseparator_symbol | str: Symbol for the seperatorseparator_color | Color: Color for the separatorenable_separator | bool: Whether to print the separator symbol, else " " will be usedtest_mode | bool: Whether to use test modetesting_terminal_width | int: Artificial terminal width for testing or for making separator more customized ;)Here's an example of using the separate_line() function:fromfancyprint.printerimportseparate_lineseparate_line(delimiter_left="(",separator_symbol="*")This will print:It looks pretty bad, but remember making a preset is recommended for most cases.ContributingThanks for considering contributing to Fancy Print. You can read Contributing.md for further information!Remember to keep your apps fancy ;)