text stringlengths 0 828 |
|---|
:param text: the text to indent |
:param nb_tabs: number of tabs to add |
:param tab_str: type of tab (could be, for example ""\t"", default: 2 spaces |
:param linebreak_input: linebreak on input |
:param linebreak_output: linebreak on output |
:param wrap: wethever to apply smart text wrapping. |
(by means of wrap_text_in_a_box) |
:return: indented text as string |
"""""" |
if not wrap: |
lines = text.split(linebreak_input) |
tabs = nb_tabs * tab_str |
output = """" |
for line in lines: |
output += tabs + line + linebreak_output |
return output |
else: |
return wrap_text_in_a_box(body=text, style='no_border', |
tab_str=tab_str, tab_num=nb_tabs)" |
4198,"def wrap_text_in_a_box(body='', title='', style='double_star', **args): |
r""""""Return a nicely formatted text box. |
e.g. |
****************** |
** title ** |
**--------------** |
** body ** |
****************** |
Indentation and newline are respected. |
:param body: the main text |
:param title: an optional title |
:param style: the name of one of the style in CFG_WRAP_STYLES. By default |
the double_star style is used. |
You can further tune the desired style by setting various optional |
parameters: |
:param horiz_sep: a string that is repeated in order to produce a |
separator row between the title and the body (if needed) |
or a tuple of three characters in the form (l, c, r) |
:param max_col: the maximum number of coulmns used by the box |
(including indentation) |
:param min_col: the symmetrical minimum number of columns |
:param tab_str: a string to represent indentation |
:param tab_num: the number of leveles of indentations |
:param border: a tuple of 8 element in the form |
(tl, t, tr, l, r, bl, b, br) of strings that represent the |
different corners and sides of the box |
:param prefix: a prefix string added before the box |
:param suffix: a suffix string added after the box |
:param break_long: wethever to break long words in order to respect |
max_col |
:param force_horiz: True in order to print the horizontal line even when |
there is no title |
e.g.: |
print wrap_text_in_a_box(title='prova', |
body=' 123 prova.\n Vediamo come si indenta', |
horiz_sep='-', style='no_border', max_col=20, tab_num=1) |
prova |
---------------- |
123 prova. |
Vediamo come |
si indenta |
"""""" |
def _wrap_row(row, max_col, break_long): |
""""""Wrap a single row."""""" |
spaces = _RE_BEGINNING_SPACES.match(row).group() |
row = row[len(spaces):] |
spaces = spaces.expandtabs() |
return textwrap.wrap(row, initial_indent=spaces, |
subsequent_indent=spaces, width=max_col, |
break_long_words=break_long) |
def _clean_newlines(text): |
text = _RE_LONELY_NEWLINES.sub(' \n', text) |
return _RE_NEWLINES_CLEANER.sub(lambda x: x.group()[:-1], text) |
body = unicode(body, 'utf-8') |
title = unicode(title, 'utf-8') |
astyle = dict(CFG_WRAP_TEXT_IN_A_BOX_STYLES['__DEFAULT']) |
if style in CFG_WRAP_TEXT_IN_A_BOX_STYLES: |
astyle.update(CFG_WRAP_TEXT_IN_A_BOX_STYLES[style]) |
astyle.update(args) |
horiz_sep = astyle['horiz_sep'] |
border = astyle['border'] |
tab_str = astyle['tab_str'] * astyle['tab_num'] |
max_col = max(astyle['max_col'] - |
len(border[3]) - len(border[4]) - len(tab_str), 1) |
min_col = astyle['min_col'] |
prefix = astyle['prefix'] |
suffix = astyle['suffix'] |
force_horiz = astyle['force_horiz'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.