API reference
snick
Conjoiner
dataclass
Conjoins text parts into a single string.
This is most useful when building multi-line strings where you want to add parts as you go and then produce a final, joined string.
__iadd__
Add a single part to the conjoiner using the += operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
part
|
str
|
A string part to add. |
required |
Returns:
| Type | Description |
|---|---|
Conjoiner
|
This conjoiner instance. |
add
add(*parts: str, should_dedent: bool = True, blanks_between: int = 0, blanks_before: int = 0, blanks_after: int = 0) -> None
Add a new part(s) to the conjoiner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts
|
str
|
One or more string parts to add. |
()
|
should_dedent
|
bool
|
If |
True
|
blanks_between
|
int
|
Number of blanks to insert between each part for multiple parts. Defaults to |
0
|
blanks_before
|
int
|
Number of blanks to insert before the first part. Defaults to |
0
|
blanks_after
|
int
|
Number of blanks to insert after the last part. Defaults to |
0
|
add_blanks
Add blanks to the conjoiner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of blank lines to add. |
required |
extend
extend(parts: Iterable[str], should_dedent: bool = True, blanks_between: int = 0, blanks_before: int = 0, blanks_after: int = 0) -> None
Add new parts to the conjoiner.
This is just a convenience method that takes a list of parts instead of variadic arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts
|
Iterable[str]
|
One or more string parts to add. |
required |
should_dedent
|
bool
|
If |
True
|
blanks_between
|
int
|
Number of blanks to insert between each part for multiple parts. Defaults to |
0
|
blanks_before
|
int
|
Number of blanks to insert before the first part. Defaults to |
0
|
blanks_after
|
int
|
Number of blanks to insert after the last part. Defaults to |
0
|
conjoin
Join strings supplied as args.
Thinly wraps str.join() without having to pack strings in an iterable and with a default joining string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
str
|
Positional arguments for strings that should be joined |
()
|
join_str
|
str
|
The string used to join the strings. Defaults to newline character. |
'\n'
|
dedent
Dedent a paragraph after removing leading and trailing whitespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to dedent |
required |
should_strip
|
bool
|
Strip leading whitespace. Useful if you you like the first line of triple-quoted text
to start on the next line after the triple-quote. Defaults to |
True
|
dedent_all
Dedent each blob supplied as an argument and then joins them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
str
|
Positional text arguments to dedent and then join. |
()
|
should_strip
|
bool
|
Passed along to each call to |
True
|
join_str
|
str
|
Passed along to the call to |
'\n'
|
enboxify
enboxify(text: str, boxchar: str = '*', hspace: int = 1, vspace: int = 0, should_strip: bool = True) -> str
Draw a box around a block of text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to enboxify |
required |
boxchar
|
str
|
The text to use for drawing the box |
'*'
|
hspace
|
int
|
Horizontal padding around text and box |
1
|
vspace
|
int
|
Vertical padding around text and box |
0
|
should_strip
|
bool
|
Strip leading whitespace. Passed on to |
True
|
indent
Wrap the textwrap.indent() method but include a default prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
The preix to pass to |
' '
|
skip_first_line
|
bool
|
If |
False
|
indent_wrap
Wrap a long string using textwrap args and indent all the lines using the same indent as the first line.
pretty_format
Pretty-format a python data structure with trailing commas and clean indentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[Any, Any]
|
The data to pretty print. |
required |
indent
|
int
|
The number of spaces per indentation level. Defaults to 2. |
2
|
pretty_print
Print to a stream (stdout by default) a data item using the pretty_format method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[Any, Any]
|
The data to pretty print. |
required |
indent
|
int
|
The number of spaces per indentation level. Defaults to 2. |
2
|
stream
|
TextIO
|
The stream to print to. Defaults to |
stdout
|
strip_ansi_escape_sequences
Strip all ansi escape sequences from a string.
To learn more about these sequences, see: https://jakob-bagterp.github.io/colorist-for-python/ansi-escape-codes/
strip_trailing_whitespace
Removes trailing whitespace on all lines of a multiline string.
unwrap
Convert a paragraph of (possibly) indented, wrapped text and unwrap it into a single line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to unwrap |
required |
should_strip
|
bool
|
If set to |
True
|
separator
|
str
|
The separator to use when joining the lines. Defaults to a single space. |
' '
|