Decorators API¶
Visual decorator patterns for print output.
Decorator Classes¶
Line¶
pyreprint.core.decorators.Line(char='=', width=0)
dataclass
¶
A horizontal line decorator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
char
|
str
|
Character to repeat for the line. |
'='
|
width
|
int
|
Width of the line (0 = auto-detect terminal width). |
0
|
Example
line = Line('=', 40) print(line) ========================================
Header¶
pyreprint.core.decorators.Header(text, char='=', width=0, above=False)
dataclass
¶
A header with text and underline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The header text. |
required |
char
|
str
|
Character for the underline. |
'='
|
width
|
int
|
Width of the underline (0 = match text length). |
0
|
above
|
bool
|
Whether to include a line above the text. |
False
|
Example
header = Header("My Section", char='=') print(header) My Section ==========
Box¶
pyreprint.core.decorators.Box(text, char='|', corner='+', horizontal='-', padding=1, width=0)
dataclass
¶
A box around text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to box. |
required |
char
|
str
|
Character for vertical borders. |
'|'
|
corner
|
str
|
Character for corners. |
'+'
|
horizontal
|
str
|
Character for horizontal borders. |
'-'
|
padding
|
int
|
Padding inside the box. |
1
|
width
|
int
|
Width of the box (0 = auto-fit to text). |
0
|
Example
box = Box("Hello World") print(box) +-------------+ | Hello World | +-------------+
Banner¶
pyreprint.core.decorators.Banner(text, char='*', width=0, padding_lines=0)
dataclass
¶
A full-width banner with centered text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The banner text. |
required |
char
|
str
|
Character for the border. |
'*'
|
width
|
int
|
Width of the banner (0 = auto-detect terminal width). |
0
|
padding_lines
|
int
|
Number of empty lines above/below text. |
0
|
Example
banner = Banner("WELCOME", char='*', width=30) print(banner)
- WELCOME *
Convenience Functions¶
line¶
pyreprint.core.decorators.line(char='=', width=0)
¶
Create a horizontal line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
char
|
str
|
Character to repeat. |
'='
|
width
|
int
|
Width of the line (0 = auto-detect terminal width). |
0
|
Returns:
| Type | Description |
|---|---|
str
|
The line as a string. |
Example
>>> print(line('=', 40))¶
Source code in pyreprint/core/decorators.py
header¶
pyreprint.core.decorators.header(text, char='=', width=0, above=False)
¶
Create a header with underline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The header text. |
required |
char
|
str
|
Character for the underline. |
'='
|
width
|
int
|
Width of the underline (0 = match text length). |
0
|
above
|
bool
|
Whether to include a line above the text. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The header as a string. |
Example
print(header("My Section")) My Section ==========
Source code in pyreprint/core/decorators.py
box¶
pyreprint.core.decorators.box(text, char='|', corner='+', horizontal='-', padding=1, width=0)
¶
Create a box around text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to box. |
required |
char
|
str
|
Character for vertical borders. |
'|'
|
corner
|
str
|
Character for corners. |
'+'
|
horizontal
|
str
|
Character for horizontal borders. |
'-'
|
padding
|
int
|
Padding inside the box. |
1
|
width
|
int
|
Width of the box (0 = auto-fit to text). |
0
|
Returns:
| Type | Description |
|---|---|
str
|
The boxed text as a string. |
Example
print(box("Hello")) +-------+ | Hello | +-------+
Source code in pyreprint/core/decorators.py
banner¶
pyreprint.core.decorators.banner(text, char='*', width=0, padding_lines=0)
¶
Create a full-width banner with centered text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The banner text. |
required |
char
|
str
|
Character for the border. |
'*'
|
width
|
int
|
Width of the banner (0 = auto-detect terminal width). |
0
|
padding_lines
|
int
|
Number of empty lines above/below text. |
0
|
Returns:
| Type | Description |
|---|---|
str
|
The banner as a string. |
Example
print(banner("WELCOME", width=30))
- WELCOME *