mirror of
https://github.com/kennethreitz/clint.git
synced 2026-06-05 23:00:18 +00:00
min/max widths in textui core
configurable newlines
This commit is contained in:
@@ -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)
|
||||
|
||||
Executable
+17
@@ -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)
|
||||
Reference in New Issue
Block a user