menu.py 文件源码

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

项目:ssha 作者: claranet 项目源码 文件源码
def addline(self, y, string, attr):
        """
        Displays a string on the screen. Handles truncation and borders.

        """

        if y >= self.max_y:
            return

        # Display the left blank border.
        self.addstr(
            y=y,
            x=0,
            string=' ' * self.offset_x,
            attr=curses.A_NORMAL,
        )

        # Remove trailing spaces so the truncate logic works correctly.
        string = string.rstrip()

        # Truncate the string if it is too long.
        if self.offset_x + len(string) + self.offset_x > self.max_x:
            string = string[:self.max_x - self.offset_x - self.offset_x - 2] + '..'

        # Add whitespace between the end of the string and the edge of the
        # screen. This is required when scrolling, to blank out characters
        # from other lines that had been displayed here previously.
        string += ' ' * (self.max_x - self.offset_x - len(string) - self.offset_x)

        # Display the string.
        self.addstr(
            y=y,
            x=self.offset_x,
            string=string,
            attr=attr,
        )

        # Display the right blank border.
        self.addstr(
            y=y,
            x=self.max_x - self.offset_x,
            string=' ' * self.offset_x,
            attr=curses.A_NORMAL,
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号