class documentation

class HelpFormatter:

View In Hierarchy

This class helps with formatting text-based help pages. It's usually just needed for very special internal cases, but it's also exposed so that developers can write their own fancy outputs.

At present, it always writes into memory.

Parameters
indent​_incrementthe additional increment for each level.
widththe width for the text. This defaults to the terminal width clamped to a maximum of 78.
Method __init__ Undocumented
Method dedent Decreases the indentation.
Method getvalue Returns the buffer contents.
Method indent Increases the indentation.
Method indentation A context manager that increases the indentation.
Method section Helpful context manager that writes a paragraph, a heading, and the indents.
Method write Writes a unicode string into the internal buffer.
Method write​_dl Writes a definition list into the buffer. This is how options and commands are usually formatted.
Method write​_heading Writes a heading into the buffer.
Method write​_paragraph Writes a paragraph into the buffer.
Method write​_text Writes re-indented text into the buffer. This rewraps and preserves paragraphs.
Method write​_usage Writes a usage line into the buffer.
Instance Variable buffer Undocumented
Instance Variable current​_indent Undocumented
Instance Variable indent​_increment Undocumented
Instance Variable width Undocumented
def __init__(self, indent_increment=2, width=None, max_width=None):

Undocumented

Parameters
indent​_increment:intUndocumented
width:t.Optional[int]Undocumented
max​_width:t.Optional[int]Undocumented
def dedent(self):
Decreases the indentation.
def getvalue(self):
Returns the buffer contents.
Returns
strUndocumented
def indent(self):
Increases the indentation.
@contextmanager
def indentation(self):
A context manager that increases the indentation.
Returns
t.Iterator[None]Undocumented
@contextmanager
def section(self, name):
Helpful context manager that writes a paragraph, a heading, and the indents.
Parameters
name:strthe section name that is written as heading.
Returns
t.Iterator[None]Undocumented
def write(self, string):
Writes a unicode string into the internal buffer.
Parameters
string:strUndocumented
def write_dl(self, rows, col_max=30, col_spacing=2):
Writes a definition list into the buffer. This is how options and commands are usually formatted.
Parameters
rows:t.Sequence[t.Tuple[str, str]]a list of two item tuples for the terms and values.
col​_max:intthe maximum width of the first column.
col​_spacing:intthe number of spaces between the first and second column.
def write_heading(self, heading):
Writes a heading into the buffer.
Parameters
heading:strUndocumented
def write_paragraph(self):
Writes a paragraph into the buffer.
def write_text(self, text):
Writes re-indented text into the buffer. This rewraps and preserves paragraphs.
Parameters
text:strUndocumented
def write_usage(self, prog, args='', prefix=None):
Writes a usage line into the buffer.
Parameters
prog:strthe program name.
args:strwhitespace separated list of arguments.
prefix:t.Optional[str]The prefix for the first line. Defaults to "Usage: ".
buffer: t.List[str] =

Undocumented

current_indent: int =

Undocumented

indent_increment =

Undocumented

width =

Undocumented