tasks.py 文件源码

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

项目:bay 作者: eventbrite 项目源码 文件源码
def clear_and_output(self):
        """
        Clears the terminal up to the right line then outputs the information
        of the task.
        """
        # See if output is paused
        if self.output_paused:
            return
        # OK, print
        with console_lock:
            # Get terminal width
            terminal_width = shutil.get_terminal_size((80, 20)).columns
            # Get the output we need to print
            output = list(self.output(terminal_width))
            # Scroll the terminal down/up enough for any new lines
            needed_lines = len(output)
            new_lines = needed_lines - self.cleared_lines
            if new_lines > 0:
                print("\n" * new_lines, flush=True, end="")
            elif new_lines < 0:
                print(
                    (UP_ONE + CLEAR_LINE) * abs(new_lines),
                    flush=True,
                    end="",
                )
            self.cleared_lines = needed_lines
            # Move cursor to top of cleared section
            print(
                (UP_ONE + CLEAR_LINE) * needed_lines,
                flush=True,
                end="",
            )
            for line in output:
                print(line)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号