Text
provide.foundation.formatting.text
¶
TODO: Add module docstring.
Functions¶
indent
¶
Indent text lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to indent |
required |
spaces
|
int
|
Number of spaces to indent |
2
|
first_line
|
bool
|
Whether to indent the first line |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Indented text |
Examples:
Source code in provide/foundation/formatting/text.py
pluralize
¶
Get singular or plural form based on count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Item count |
required |
singular
|
str
|
Singular form |
required |
plural
|
str | None
|
Plural form (default: singular + 's') |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Appropriate singular/plural form with count |
Examples:
>>> pluralize(1, "file")
'1 file'
>>> pluralize(5, "file")
'5 files'
>>> pluralize(2, "child", "children")
'2 children'
Source code in provide/foundation/formatting/text.py
strip_ansi
¶
truncate
¶
Truncate text to maximum length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to truncate |
required |
max_length
|
int
|
Maximum length including suffix |
required |
suffix
|
str
|
Suffix to append when truncated |
'...'
|
whole_words
|
bool
|
Truncate at word boundaries |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Truncated text |
Examples:
>>> truncate("Hello world", 8)
'Hello...'
>>> truncate("Hello world", 8, whole_words=False)
'Hello...'
Source code in provide/foundation/formatting/text.py
wrap_text
¶
Wrap text to specified width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to wrap |
required |
width
|
int
|
Maximum line width |
80
|
indent_first
|
int
|
Spaces to indent first line |
0
|
indent_rest
|
int
|
Spaces to indent remaining lines |
0
|
Returns:
| Type | Description |
|---|---|
str
|
Wrapped text |