SOURCE CODE DOC

Entry Point

Package import

psprint

Prompt String-like Print

psprint.DEFAULT_PRINT = pref long short text  cont: <CUSTOM> info: INFORM i <CUSTOM> act: ACTION @ <CUSTOM> list: LIST · <CUSTOM> warn: WARNING * <CUSTOM> err: ERROR ! <CUSTOM> bug: DEBUG # <CUSTOM>

PrintSpace object created by reading defaults from various psprintrc and psprint/style.yml files

psprint.print(*args, mark=None, **kwargs)

psprint function for imports

Return type

None

PrintSpace

class psprint.printer.PrintSpace(config)[source]

Fancy Print class that also prints the type of message

Parameters

config (PathLike) – path to default configuration file (shipped)

pref_max

int: maximum length of prefix string

info_style; dict

pre-defined prefix styles

info_index

list: keys of info_style mapped to int

print_kwargs

dict : library of kwargs_accepted by print_function

switches

dict: user-customizations: pad, short, bland, disabled

pad: bool: prefix is padded to start text at the same level short: bool: display short, 1 character- prefix bland: bool: do not show ANSI color/styles for prefix/text disabled: bool: behave like python default print_function

edit_style(pref, index_int=None, mark=None, **kwargs)[source]

Edit loaded style

Parameters
  • pref (str) – str: prefix string long [length < 10 characters]

  • index_int (Optional[int]) – Index number that will call this InfoMark

  • mark (Optional[str]) – Mark string that will call this InfoMark

  • **kwargs

    • pref_s: str: prefix string short [1 character]

    • code:

      • color: {[0-15],[[l]krgybmcw],[[light] <color_name>]}

      • gloss: {[0-3],[rcdb],{reset,normal,dim,bright}}

    • for-

      • pref_color: color of of prefix

      • pref_gloss: gloss of prefix

      • pref_bgcol: background color of prefix

      • text_color: color of of text

      • text_gloss: gloss of text

      • text_bgcol: background color of text

Returns

Summary of new (updated) PrintSpace

Return type

str

psfmt(*args, mark=None, sep=None, **kwargs)[source]

Prefix String represenattion.

Parameters
  • *args – passed to print_function for printing

  • mark (Union[str, int, InfoMark, None]) –

    pre-declared InfoMark defaults:

    • cont or 0 or anything else: nothing

    • info or 1: [INFO]

    • act or 2: [ACTION]

    • list or 3: [LIST]

    • warn or 4: [WARNING]

    • error:or 5: [ERROR]

    • bug: or 6 [DEBUG]

    • Other marks defined in .psprintrc

  • sep (Optional[str]) – If not None, return *args joined by separator.

  • **kwargs

    • pref: str: prefix string long [length < 10 characters]

    • pref_s: str: prefix string short [1 character]

    • code:

      • color: {[0-15],[[l]krgybmcw],[[light] <color_name>]}

      • gloss: {[0-3],[rcdb],{reset,normal,dim,bright}}

    • for-

      • pref_color: color of of prefix

      • pref_gloss: gloss of prefix

      • pref_bgcol: background color of prefix

      • text_color: color of of text

      • text_gloss: gloss of text

      • text_bgcol: background color of text

    • pad: bool: prefix is padded to start text at the same level

    • short: bool: display short, 1 character- prefix

    • bland: bool: do not show ANSI color/styles for prefix/text

    • disabled: bool: behave like python default print_function

Raises

BadMark – mark couldn’t be interpreted

Return type

Union[List[str], str]

Returns

  • PSPRINT-like represented args. When these args is printed using standard print, PSPRINT-like output appears.

  • If a sep is provided, it is used to join args and return a string

psprint(*args, mark=None, **kwargs)[source]

Prefix String PRINT

Parameters
  • *args – passed to print_function for printing

  • mark (Union[str, int, InfoMark, None]) –

    pre-declared InfoMark defaults:

    • cont or 0 or anything else: nothing

    • info or 1: [INFO]

    • act or 2: [ACTION]

    • list or 3: [LIST]

    • warn or 4: [WARNING]

    • error:or 5: [ERROR]

    • bug: or 6 [DEBUG]

    • Other marks defined in .psprintrc

  • **kwargs

    • pref: str: prefix string long [length < 10 characters]

    • pref_s: str: prefix string short [1 character]

    • code:

      • color: {[0-15],[[l]krgybmcw],[[light] <color_name>]}

      • gloss: {[0-3],[rcdb],{reset,normal,dim,bright}}

    • for-

      • pref_color: color of of prefix

      • pref_gloss: gloss of prefix

      • pref_bgcol: background color of prefix

      • text_color: color of of text

      • text_gloss: gloss of text

      • text_bgcol: background color of text

    • pad: bool: prefix is padded to start text at the same level

    • short: bool: display short, 1 character- prefix

    • bland: bool: do not show ANSI color/styles for prefix/text

    • disabled: bool: behave like python default print_function

    • file: IO: passed to print function

    • sep: str: passed to print function

    • end: str: passed to print function

    • flush: bool: passed to print function

Raises

BadMark – mark couldn’t be interpreted

Return type

None

remove_style(mark=None, index_int=None)[source]
Parameters
  • mark (Optional[str]) – is popped out of defined styles

  • index_int (Optional[int]) – is used to locate index_str if it is not provided

Returns

Summary of new (updated) PrintSpace

Return type

str

set_opts(config=None)[source]

Configure from rcfile

Parameters

rcfile – .psprintrc file to read

Raises

BadMark

Return type

None


Base

InfoMark

Information Marker

psprint.mark_types.DEFAULT_STYLE: Dict[str, int] = {'bgcol': 16, 'color': 16, 'gloss': 1}

Terminal-determined color, black background, normal gloss

class psprint.mark_types.InfoMark(parent=None, pref_max=None, **kwargs)[source]

Prefix Mark information

pref

PrintPref: Prefix text properties

text

PrintText: Text properties

Parameters
  • parent (Optional[InfoMark]) – Inherit information from-

  • pref_max (Optional[int]) – pad prefix to reach length

  • **kwargs

    • pref: prefix string

    • pref_s: prefix short string

    • code:

      • color: {[0-15],[[l]krgybmcw],[[light] <color_name>]}

      • gloss: {[0-3],[rcdb],{reset,normal,dim,bright}}

    • for-

      • pref_color: color of of prefix

      • pref_gloss: gloss of prefix

      • pref_bgcol: background color of prefix

      • text_color: color of of text

      • text_gloss: gloss of text

      • text_bgcol: background color of text

get_info()[source]

Print information about InfoMark

Return type

str

TextTypes

Text Parts

class psprint.text_types.AnsiEffect(parent=None, color=None, gloss=None, bgcol=None)[source]

Plain text object Text to be printed to (ANSI) terminal

Parameters
  • color (Optional[str]) – color of text [0-15]

  • gloss (Optional[str]) – gloss of text {0: bland, 1:normal ,2: dim, 3: bright}

  • bgcol (Optional[str]) – color of background [0-15]

color

color of text

gloss

gloss of text

bgcol

background color

Raises
static inherit(parent)[source]

object without parent set attributes to defaults

property style: str

All style combined

Return type

str

class psprint.text_types.PrintPref(parent=None, pref=None, pref_max=0, **kwargs)[source]

Prefix that informs about Text

Parameters
  • parent – template object for style

  • pref (Optional[List[str]]) – prefix in [long, short] format

  • pref_max (int) – pad with space to length

  • **kwargs

    • code:

      • color: {[0-15],[[l]krgybmcw],[[light] <color_name>]}

      • gloss: {[0-3],[rcdb],{reset,normal,dim,bright}}

    • for-

      • color: color of of prefix

      • gloss: gloss of prefix

      • bgcol: background color of prefix

  • pref – tuple: prefix long, short

  • brackets – tuple: bool long, short

  • pad – tuple: pad long, short

  • style – AnsiEffect: color/gloss style

Raises
to_str(**kwargs)[source]

Print prefix with style

Parameters
  • short – prefix in short form?

  • pad – Pad prefix

  • bland – colorless pref

Return type

str


Errors

Error/Warnings

Errors and warnings

exception psprint.errors.BadBGCol(bgcol)[source]

Background Color Error

exception psprint.errors.BadColor(color)[source]

Color Error

exception psprint.errors.BadGloss(gloss)[source]

Gloss Error

exception psprint.errors.BadMark(mark, config)[source]

A mark supplied in config cannot be parsed

Parameters
  • mark (str) – passed mark

  • config (str) – config file that defined the mark

exception psprint.errors.BadPref(key, value)[source]

Prefix Style declared incorrectly

Parameters
  • key – key

  • value – (Bad) value supplied

exception psprint.errors.BadPrefix(prefix)[source]

Prefix string Error

exception psprint.errors.BadShortPrefix(pref_s)[source]

Prefix short string Error

exception psprint.errors.BadStyle(key, value)[source]

Style declared incorrectly

Parameters
  • key – key

  • value – (Bad) value supplied

exception psprint.errors.KeyWarning[source]

Warning that a key was wrongly passed and has been interpreted as default

exception psprint.errors.PSPrintError[source]

Base error from PSPrint

exception psprint.errors.PSPrintWarning[source]

Base warning category from PSPrint

exception psprint.errors.ValueWarning[source]

Warning that a value was wrongly passed and has been interpreted as default