Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
grepros.common.TextWrapper Class Reference
Inheritance diagram for grepros.common.TextWrapper:
Inheritance graph
[legend]

Public Member Functions

def __init__ (self, width=80, subsequent_indent=" ", break_long_words=True, drop_whitespace=False, max_lines=None, placeholder=" ...", custom_widths=None)
 
def reserve_width (self, reserved="")
 
def strip (self, v)
 
def strlen (self, v)
 
def wrap (self, text)
 

Public Attributes

 break_long_words
 
 custom_lens
 
 custom_rgx
 
 customs
 
 disabled
 
 drop_whitespace
 
 lencache
 
 max_lines
 
 minwidth
 
 placeholder
 
 realwidth
 
 subsequent_indent
 
 width
 

Static Public Attributes

int LENCACHEMAX = 10000
 Max length of strlen cache. More...
 
 SPACE_RGX = re.compile(r"([%s]+)" % re.escape("\t\n\x0b\x0c\r "))
 Regex for breaking text at whitespace. More...
 

Private Member Functions

def _handle_long_word (self, reversed_chunks, cur_line, cur_len, width)
 
def _wrap_chunks (self, chunks)
 

Detailed Description

TextWrapper that supports custom substring widths in line width calculation.

Intended for wrapping text containing ANSI control codes.
Heavily refactored from Python standard library textwrap.TextWrapper.

Definition at line 482 of file common.py.

Constructor & Destructor Documentation

◆ __init__()

def grepros.common.TextWrapper.__init__ (   self,
  width = 80,
  subsequent_indent = "  ",
  break_long_words = True,
  drop_whitespace = False,
  max_lines = None,
  placeholder = " ...",
  custom_widths = None 
)
@param   width              default maximum width to wrap at, 0 disables
@param   subsequent_indent  string prepended to all consecutive lines
@param   break_long_words   break words longer than width
@param   drop_whitespace    drop leading and trailing whitespace from lines
@param   max_lines          count to truncate lines from
@param   placeholder        appended to last retained line when truncating
@param   custom_widths      {substring: len} to use in line width calculation

Definition at line 497 of file common.py.

Member Function Documentation

◆ _handle_long_word()

def grepros.common.TextWrapper._handle_long_word (   self,
  reversed_chunks,
  cur_line,
  cur_len,
  width 
)
private
Breaks last chunk if not only containing a custom-width string,
else adds last chunk to current line if line still empty.

Definition at line 623 of file common.py.

◆ _wrap_chunks()

def grepros.common.TextWrapper._wrap_chunks (   self,
  chunks 
)
private
Returns a list of lines joined from text chunks, wrapped to width.

Definition at line 565 of file common.py.

◆ reserve_width()

def grepros.common.TextWrapper.reserve_width (   self,
  reserved = "" 
)
Decreases the configured width by given amount (number or string).

Definition at line 547 of file common.py.

◆ strip()

def grepros.common.TextWrapper.strip (   self,
  v 
)
Returns string with custom substrings and whitespace stripped.

Definition at line 560 of file common.py.

◆ strlen()

def grepros.common.TextWrapper.strlen (   self,
  v 
)
Returns length of string, using custom substring widths.

Definition at line 553 of file common.py.

◆ wrap()

def grepros.common.TextWrapper.wrap (   self,
  text 
)
Returns a list of wrapped text lines, without linebreaks.

Definition at line 526 of file common.py.

Member Data Documentation

◆ break_long_words

grepros.common.TextWrapper.break_long_words

Definition at line 509 of file common.py.

◆ custom_lens

grepros.common.TextWrapper.custom_lens

Definition at line 516 of file common.py.

◆ custom_rgx

grepros.common.TextWrapper.custom_rgx

Definition at line 517 of file common.py.

◆ customs

grepros.common.TextWrapper.customs

Definition at line 515 of file common.py.

◆ disabled

grepros.common.TextWrapper.disabled

Definition at line 518 of file common.py.

◆ drop_whitespace

grepros.common.TextWrapper.drop_whitespace

Definition at line 510 of file common.py.

◆ lencache

grepros.common.TextWrapper.lencache

Definition at line 514 of file common.py.

◆ LENCACHEMAX

int grepros.common.TextWrapper.LENCACHEMAX = 10000
static

Max length of strlen cache.

Definition at line 494 of file common.py.

◆ max_lines

grepros.common.TextWrapper.max_lines

Definition at line 511 of file common.py.

◆ minwidth

grepros.common.TextWrapper.minwidth

Definition at line 519 of file common.py.

◆ placeholder

grepros.common.TextWrapper.placeholder

Definition at line 512 of file common.py.

◆ realwidth

grepros.common.TextWrapper.realwidth

Definition at line 522 of file common.py.

◆ SPACE_RGX

grepros.common.TextWrapper.SPACE_RGX = re.compile(r"([%s]+)" % re.escape("\t\n\x0b\x0c\r "))
static

Regex for breaking text at whitespace.

Definition at line 491 of file common.py.

◆ subsequent_indent

grepros.common.TextWrapper.subsequent_indent

Definition at line 508 of file common.py.

◆ width

grepros.common.TextWrapper.width

Definition at line 507 of file common.py.


The documentation for this class was generated from the following file:


grepros
Author(s): Erki Suurjaak
autogenerated on Sat Jan 6 2024 03:11:30