本文整理汇总了Python中accessories.TestTerminal.center方法的典型用法代码示例。如果您正苦于以下问题:Python TestTerminal.center方法的具体用法?Python TestTerminal.center怎么用?Python TestTerminal.center使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accessories.TestTerminal
的用法示例。
在下文中一共展示了TestTerminal.center方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: child
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import center [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)
t = TestTerminal(kind=kind)
pony_msg = 'pony express, all aboard, choo, choo!'
pony_len = len(pony_msg)
pony_colored = u''.join(
['%s%s' % (t.color(n % 7), ch,)
for n, ch in enumerate(pony_msg)])
pony_colored += t.normal
ladjusted = t.ljust(pony_colored)
radjusted = t.rjust(pony_colored)
centered = t.center(pony_colored)
assert (t.length(pony_colored) == pony_len)
assert (t.length(centered.strip()) == pony_len)
assert (t.length(centered) == len(pony_msg.center(t.width)))
assert (t.length(ladjusted.strip()) == pony_len)
assert (t.length(ladjusted) == len(pony_msg.ljust(t.width)))
assert (t.length(radjusted.strip()) == pony_len)
assert (t.length(radjusted) == len(pony_msg.rjust(t.width)))