From 2cd9bd52637daf8158a38d3aeca346b47d10f1b1 Mon Sep 17 00:00:00 2001 From: "star:Kenneth Reitz" Date: Tue, 22 Mar 2011 04:36:01 -0400 Subject: [PATCH] min/max widths in textui core configurable newlines --- clint/textui/core.py | 8 ++++++-- examples/text_width.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100755 examples/text_width.py diff --git a/clint/textui/core.py b/clint/textui/core.py index e7738bd..4300e9d 100644 --- a/clint/textui/core.py +++ b/clint/textui/core.py @@ -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) diff --git a/examples/text_width.py b/examples/text_width.py new file mode 100755 index 0000000..87e2a31 --- /dev/null +++ b/examples/text_width.py @@ -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) \ No newline at end of file