本文整理匯總了Python中Tardis.Util.getTerminalSize方法的典型用法代碼示例。如果您正苦於以下問題:Python Util.getTerminalSize方法的具體用法?Python Util.getTerminalSize怎麽用?Python Util.getTerminalSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tardis.Util
的用法示例。
在下文中一共展示了Util.getTerminalSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: computeColumnWidth
# 需要導入模塊: from Tardis import Util [as 別名]
# 或者: from Tardis.Util import getTerminalSize [as 別名]
def computeColumnWidth(names):
"""
Given a list of names, compute the columns widths
"""
if len(list(names)) == 0:
return (1, '%s')
longestName = max(list(map(len, names)), default=0)
if args.columns:
columns = args.columns
else:
if os.isatty(sys.stdout.fileno()):
(_, width) = Util.getTerminalSize()
logger.debug("Setting width to %d", width)
width -= 2 # lop a couple characters off the end to avoid annoying wraps in some cases.
columns = int(width / (longestName + 4))
if columns == 0:
columns = 1
else:
columns = 1
fmt = "%%-%ds " % (longestName + 2)
logger.debug("Setting columns to %d", columns)
return (columns, fmt)
示例2: computeColumnWidth
# 需要導入模塊: from Tardis import Util [as 別名]
# 或者: from Tardis.Util import getTerminalSize [as 別名]
def computeColumnWidth(names):
"""
Given a list of names, compute the columns widths
"""
if len(names) == 0:
return (1, '%s')
longestName = max(map(len, names))
if args.columns:
columns = args.columns
else:
if os.isatty(sys.stdout.fileno()):
_, width = Util.getTerminalSize()
width -= 2 # lop a couple characters off the end to avoid annoying wraps in some cases.
columns = width / (longestName + 4)
else:
columns = 1
fmt = "%%-%ds " % (longestName + 2)
return (columns, fmt)