min/max widths in textui core

configurable newlines
This commit is contained in:
star:Kenneth Reitz
2011-03-22 04:36:01 -04:00
parent 76bee9c4ba
commit 2cd9bd5263
2 changed files with 23 additions and 2 deletions
+6 -2
View File
@@ -14,15 +14,19 @@ from __future__ import absolute_import
import sys
from .progress import progressbar
from .formatters import max_width, min_width
from ..utils import tsplit
__all__ = ('puts', 'puts_err', 'indent', 'progressbar')
__all__ = ('puts', 'puts_err', 'indent', 'progressbar', 'max_width', 'min_width')
STDOUT = sys.stdout.write
STDERR = sys.stderr.write
NEWLINES = ('\n', '\r', '\r\n')
class Writer(object):
"""WriterUtilized by context managers."""
@@ -60,7 +64,7 @@ class Writer(object):
def __call__(self, s, newline=True, stream=STDOUT):
if newline:
s = tsplit(s, ('\n', '\r', '\r\n'))
s = tsplit(s, NEWLINES)
indent = ''.join(self.shared['indent_strings'])
s = ('\n' + indent).join(s)
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
sys.path.insert(0, os.path.abspath('..'))
from clint.textui import puts, max_width, min_width
lorem = 'Lorem ipsum dolor sit amet, consehdfhdfhdfhdfhdfhctetur adi pisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
if __name__ == '__main__':
# puts(min_width('test\nit', 20) + ' me')
# puts(min_width(lorem, 20) + ' me')
print max_width(lorem, 20)