menu.py 文件源码

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

项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码
def _draw_notification(stdscr, message):
        """
        Draw a notification window with the provided message.

        Parameters:
            stdscr (WindowObject): the screen; handled by curses.wrapper
            message (str): the message to the user

        Returns:
            True (bool)
        """
        stdscr.clear()

        # Setup the title
        stdscr.addstr("ec2rl module configurator", curses.color_pair(2) | curses.A_BOLD)
        stdscr.chgat(-1, curses.color_pair(2))
        curses.curs_set(0)

        message_list = [message.rstrip() for message in message.split(os.linesep)]
        current_row = 1

        main_window = curses.newwin(curses.LINES - 1, curses.COLS, 1, 0)
        screen = main_window.subwin(curses.LINES - 7, curses.COLS - 4, 4, 2)
        footer = main_window.subwin(3, curses.COLS - 4, curses.LINES - 3, 2)

        # Setup background colors
        main_window.bkgd(" ", curses.color_pair(1))
        screen.bkgd(" ", curses.color_pair(2))
        footer.bkgd(" ", curses.color_pair(2))

        # Draw borders around the subwindows
        screen.box()
        footer.box()

        footer.addstr(1, 1, "Exit", curses.color_pair(1) | curses.A_BOLD)

        for message in message_list:
            if current_row < curses.LINES - 7:
                # Truncate the string, if needed
                display_str = message[:curses.COLS - 8]
                screen.addstr(current_row, 3, display_str)
                current_row += 1
            else:
                break

        # Draw the pieces of the overall screen (order matters)
        stdscr.noutrefresh()
        main_window.noutrefresh()
        screen.noutrefresh()
        curses.doupdate()

        while True:
            # Get a character from the keyboard
            key = stdscr.getch()
            # The user can exit via the enter key
            if key == ord("\n"):
                return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号