Printer API¶
The core printing functionality of PyRePrint.
reprint¶
The main function for enhanced printing.
pyreprint.core.printer.reprint(*args, sep=' ', end='\n', file=None, flush=False, before=None, after=None, surround=None, style=None, width=None, rich=None, markup=True, **kwargs)
¶
Enhanced print function with decorator and style support.
This is the main function of pyreprint, providing a drop-in replacement for the built-in print() with additional features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Values to print (same as built-in print). |
()
|
sep
|
str
|
Separator between values. |
' '
|
end
|
str
|
String to append at end. |
'\n'
|
file
|
Optional[TextIO]
|
Output file (default: sys.stdout). |
None
|
flush
|
bool
|
Whether to flush output. |
False
|
before
|
DecoratorType
|
Decorator to print before the content. |
None
|
after
|
DecoratorType
|
Decorator to print after the content. |
None
|
surround
|
DecoratorType
|
Decorator for both before and after. |
None
|
style
|
Optional[str]
|
Named style to apply. |
None
|
width
|
Optional[int]
|
Width for decorators (0 = auto). |
None
|
rich
|
Optional[bool]
|
Whether to use rich for this print. |
None
|
markup
|
bool
|
Whether to parse rich markup. |
True
|
**kwargs
|
Any
|
Additional arguments for style functions. |
{}
|
Examples:
Basic usage:
With decorators:
>>> reprint("Section", before="=", after="=", width=40)
========================================
Section
========================================
With style:
>>> reprint("Important!", style="banner")
****************************************
* Important! *
****************************************
Source code in pyreprint/core/printer.py
Printer Class¶
A configurable printer instance.
pyreprint.core.printer.Printer(width=0, use_rich=False, default_style=None)
¶
Enhanced printer with decorator and style support.
The Printer class provides a configurable print function with support for decorators (lines before/after), styles, and rich integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Default width for decorators (0 = auto-detect). |
0
|
use_rich
|
bool
|
Whether to use rich for output. |
False
|
default_style
|
Optional[str]
|
Default style to apply to all prints. |
None
|
Example
printer = Printer(width=60) printer("Hello", before="=", after="=") ============================================================ Hello ============================================================
Source code in pyreprint/core/printer.py
Functions¶
__call__(*args, sep=' ', end='\n', file=None, flush=False, before=None, after=None, surround=None, style=None, width=None, rich=None, markup=True, **kwargs)
¶
Print with optional decorators and styling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Values to print (same as built-in print). |
()
|
sep
|
str
|
Separator between values. |
' '
|
end
|
str
|
String to append at end. |
'\n'
|
file
|
Optional[TextIO]
|
Output file (default: sys.stdout). |
None
|
flush
|
bool
|
Whether to flush output. |
False
|
before
|
DecoratorType
|
Decorator to print before the content. |
None
|
after
|
DecoratorType
|
Decorator to print after the content. |
None
|
surround
|
DecoratorType
|
Decorator for both before and after. |
None
|
style
|
Optional[str]
|
Named style to apply. |
None
|
width
|
Optional[int]
|
Width for decorators. |
None
|
rich
|
Optional[bool]
|
Whether to use rich for this print. |
None
|
markup
|
bool
|
Whether to parse rich markup. |
True
|
**kwargs
|
Any
|
Additional arguments for style functions. |
{}
|
Source code in pyreprint/core/printer.py
banner(text, char='*', width=None, file=None)
¶
Print a full-width banner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Banner text. |
required |
char
|
str
|
Border character. |
'*'
|
width
|
Optional[int]
|
Width of banner (0 = auto). |
None
|
file
|
Optional[TextIO]
|
Output file. |
None
|
Source code in pyreprint/core/printer.py
box(text, char='|', corner='+', file=None)
¶
Print text in a box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to box. |
required |
char
|
str
|
Vertical border character. |
'|'
|
corner
|
str
|
Corner character. |
'+'
|
file
|
Optional[TextIO]
|
Output file. |
None
|
Source code in pyreprint/core/printer.py
header(text, char='=', width=None, above=False, file=None)
¶
Print a header with underline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Header text. |
required |
char
|
str
|
Underline character. |
'='
|
width
|
Optional[int]
|
Width of underline (0 = match text). |
None
|
above
|
bool
|
Whether to include line above. |
False
|
file
|
Optional[TextIO]
|
Output file. |
None
|
Source code in pyreprint/core/printer.py
line(char='=', width=None, file=None)
¶
Print a horizontal line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
char
|
str
|
Character for the line. |
'='
|
width
|
Optional[int]
|
Width of the line (0 = auto). |
None
|
file
|
Optional[TextIO]
|
Output file. |
None
|
Source code in pyreprint/core/printer.py
Utility Functions¶
install_print¶
pyreprint.core.printer.install_print()
¶
Replace the built-in print with reprint.
Returns:
| Type | Description |
|---|---|
Callable[..., None]
|
The original print function (for restoration if needed). |
Example
original_print = install_print() print("Now uses reprint!") # Uses reprint import builtins builtins.print = original_print # Restore
Source code in pyreprint/core/printer.py
uninstall_print¶
pyreprint.core.printer.uninstall_print(original=None)
¶
Restore the built-in print function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
Optional[Callable[..., None]]
|
The original print function to restore. If None, restores the standard print. |
None
|