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)
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)