cwrapper.py 文件源码

python
阅读 60 收藏 0 点赞 0 评论 0

项目:taskhud 作者: usefulthings 项目源码 文件源码
def _get_column_widths(self):
        """
        returns a dict keyed by column name, values are column widths
        """
        column_widths = {}

        # Calculate widths for columns
        # TODO: cache these values if records don't change between renders
        for column in self.columns:
            record_max_width = 0

            for record in self.records:
                if column in record:
                    r_value = record[column]
                    if column in self.translations:
                        r_value = self.translations[column](r_value)
                    else:
                        r_value = str(r_value)

                    record_max_width = max(record_max_width, len(r_value))

            record_max_width += 3

            # len(column) + 3:
            #   len(column): space for column header
            #   +2: left border + space
            #   +1: space on right of header
            column_width = max(record_max_width, len(column) + 3)

            column_widths[column] = column_width

        # Shrink columns until all fits on screen
        # TODO: handling when there's too many columns to render happily
        if sum(column_widths.values()) >= curses.COLS:
            while sum(column_widths.values()) >= curses.COLS:
                key_largest = max(column_widths, key=column_widths.get)
                column_widths[key_largest] -= 1

        return column_widths
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号