add over.text.count_leading
add indent support to over.text.Output
This commit is contained in:
parent
793d97f854
commit
5b4958e1e2
2 changed files with 26 additions and 2 deletions
26
over/text.py
26
over/text.py
|
@ -236,6 +236,22 @@ def strlen(string):
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
|
def count_leading(text, char):
|
||||||
|
"""
|
||||||
|
Returns the count of leading `char`s within `text`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not text:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
for i, c in enumerate(text):
|
||||||
|
if c != char:
|
||||||
|
return i
|
||||||
|
|
||||||
|
return i + 1
|
||||||
|
|
||||||
|
# --------------------------------------------------
|
||||||
|
|
||||||
class Output:
|
class Output:
|
||||||
class tag:
|
class tag:
|
||||||
class short:
|
class short:
|
||||||
|
@ -270,13 +286,15 @@ class Output:
|
||||||
<T> - tag
|
<T> - tag
|
||||||
<n> - name
|
<n> - name
|
||||||
<t> - supplied text
|
<t> - supplied text
|
||||||
|
<i> - indentation start marker
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, format="[%Y-%m-%d %H:%M:%S] <T> -- <n>, <t>", colors=True, end=".\n", stream=sys.stderr):
|
def __init__(self, name, format="[%Y-%m-%d %H:%M:%S] <T> -- <n>, <i><t>", colors=True, end=".\n", indent=True, stream=sys.stderr):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.format = format
|
self.format = format
|
||||||
self.colors = colors
|
self.colors = colors
|
||||||
self.end = end
|
self.end = end
|
||||||
|
self.indent = indent
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
|
|
||||||
def __call__(self, text, tag=None, format=None, colors=None, end=None):
|
def __call__(self, text, tag=None, format=None, colors=None, end=None):
|
||||||
|
@ -288,6 +306,12 @@ class Output:
|
||||||
output = datetime.datetime.now().strftime(format)
|
output = datetime.datetime.now().strftime(format)
|
||||||
output = output.replace("<T>", tag)
|
output = output.replace("<T>", tag)
|
||||||
output = output.replace("<n>", self.name)
|
output = output.replace("<n>", self.name)
|
||||||
|
|
||||||
|
if self.indent:
|
||||||
|
indent_width = render(output, colors=False).index("<i>")
|
||||||
|
text = paragraph(text, indent=indent_width)[indent_width:]
|
||||||
|
|
||||||
|
output = output.replace("<i>", "")
|
||||||
output = output.replace("<t>", text)
|
output = output.replace("<t>", text)
|
||||||
output += end
|
output += end
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
major = 0 # VERSION_MAJOR_IDENTIFIER
|
major = 0 # VERSION_MAJOR_IDENTIFIER
|
||||||
minor = 0 # VERSION_MINOR_IDENTIFIER
|
minor = 0 # VERSION_MINOR_IDENTIFIER
|
||||||
# VERSION_LAST_MM 0.0
|
# VERSION_LAST_MM 0.0
|
||||||
patch = 1 # VERSION_PATCH_IDENTIFIER
|
patch = 2 # VERSION_PATCH_IDENTIFIER
|
||||||
str = ".".join(str(v) for v in (major, minor, patch))
|
str = ".".join(str(v) for v in (major, minor, patch))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue