本文整理汇总了Python中accessories.TestTerminal.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python TestTerminal.wrap方法的具体用法?Python TestTerminal.wrap怎么用?Python TestTerminal.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accessories.TestTerminal
的用法示例。
在下文中一共展示了TestTerminal.wrap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: child
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import wrap [as 别名]
def child(kind, lines=25, cols=80):
# set the pty's virtual window size
val = struct.pack('HHHH', lines, cols, 0, 0)
fcntl.ioctl(sys.__stdout__.fileno(), termios.TIOCSWINSZ, val)
# build a test paragraph, along with a very colorful version
t = TestTerminal(kind=kind)
pgraph = u' '.join(
('a', 'ab', 'abc', 'abcd', 'abcde', 'abcdef', 'abcdefgh',
'abcdefghi', 'abcdefghij', 'abcdefghijk', 'abcdefghijkl',
'abcdefghijklm', 'abcdefghijklmn', 'abcdefghijklmno',) * 4)
pgraph_colored = u''.join([
t.color(n % 7) + t.bold + ch
for n, ch in enumerate(pgraph)])
internal_wrapped = textwrap.wrap(pgraph, t.width,
break_long_words=False)
my_wrapped = t.wrap(pgraph)
my_wrapped_colored = t.wrap(pgraph_colored)
# ensure we textwrap ascii the same as python
assert (internal_wrapped == my_wrapped)
# ensure our first and last line wraps at its ends
first_l = internal_wrapped[0]
last_l = internal_wrapped[-1]
my_first_l = my_wrapped_colored[0]
my_last_l = my_wrapped_colored[-1]
assert (len(first_l) == t.length(my_first_l))
assert (len(last_l) == t.length(my_last_l))
assert (len(internal_wrapped[-1]) == t.length(my_wrapped_colored[-1]))