Ejemplo n.º 1
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    try:
        stdscr.addstr("Hello ")
        curses.attron(curses.A_BOLD)
        stdscr.addstr("World! (Bold)")
        curses.attroff(curses.A_BOLD)

        stdscr.addstr("\nHello ")
        curses.attron(curses.A_REVERSE)
        stdscr.addstr("World! (Reverse)")
        curses.attroff(curses.A_REVERSE)

        stdscr.addstr("\nHello World! (Inline Bold)", curses.A_BOLD)
        stdscr.addstr("\nHello World! (Inline Reverse)", curses.A_REVERSE)

        stdscr.addstr("\nHello World! (Inline Underline)", curses.A_UNDERLINE)
        stdscr.addstr("\nHello World! (Inline BLINK!)", curses.A_BLINK)
        stdscr.addstr("\nHello World! (Inline RED)", curses.COLOR_RED)

        stdscr.getch()
    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Ejemplo n.º 2
0
def printHeaderMessage():
    """Print the header message at the top of the terminal."""

    unicurses.init_pair(1, unicurses.COLOR_RED, unicurses.COLOR_BLACK)
    unicurses.attron(unicurses.COLOR_PAIR(1))
    unicurses.mvaddstr(1, 24, "Conway's game of life")
    unicurses.mvaddstr(4, 24, "Python implementation by: CodingBeagle")
    unicurses.mvaddstr(7, 24, "Press 'q' to terminate the application")
    unicurses.attroff(unicurses.COLOR_PAIR(1))
Ejemplo n.º 3
0
def printGameBoardFrame():
    """Draw a frame in the terminal which surrounds the game of life board."""

    unicurses.init_pair(2, unicurses.COLOR_GREEN, unicurses.COLOR_BLACK)
    unicurses.attron(unicurses.COLOR_PAIR(2))

    for frameWidthCoordinate in range(GAME_BOARD_COLUMNS+2):
        unicurses.mvaddstr(BOARD_FRAME_Y_OFFSET - 1, (frameWidthCoordinate + BOARD_FRAME_X_OFFSET) - 1, "@")
        unicurses.mvaddstr(BOARD_FRAME_Y_OFFSET + GAME_BOARD_ROWS, (frameWidthCoordinate + BOARD_FRAME_X_OFFSET) - 1, "@")

    for frameHeightCoordinate in range(GAME_BOARD_ROWS+2):
        unicurses.mvaddstr((BOARD_FRAME_Y_OFFSET - 1) + frameHeightCoordinate, BOARD_FRAME_X_OFFSET - 1, "@")
        unicurses.mvaddstr((BOARD_FRAME_Y_OFFSET -1) + frameHeightCoordinate, BOARD_FRAME_X_OFFSET + GAME_BOARD_COLUMNS, "@")

    unicurses.attroff(unicurses.COLOR_PAIR(2))
Ejemplo n.º 4
0
def main():

    if not curses.has_colors():
        print("Your terminal emulator needs to have colors.")
        return 0

    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        avatar = Player(stdscr, "@", curses.COLOR_RED, curses.COLOR_BLACK,
                        curses.A_BOLD)

        curses.attron(curses.color_pair(1))
        curses.vline("|", 10)
        curses.hline("-", 10)
        curses.attroff(curses.color_pair(1))

        while True:
            key = curses.getch()

            avatar.move(key)

            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Ejemplo n.º 5
0
uni.init_pair(3, uni.COLOR_BLUE, uni.COLOR_BLACK)
uni.init_pair(4, uni.COLOR_CYAN, uni.COLOR_BLACK)

init_wins(my_wins, 3)

my_panels[0] = uni.new_panel(my_wins[0])
my_panels[1] = uni.new_panel(my_wins[1])
my_panels[2] = uni.new_panel(my_wins[2])

uni.set_panel_userptr(my_panels[0], my_panels[1])
uni.set_panel_userptr(my_panels[1], my_panels[2])
uni.set_panel_userptr(my_panels[2], my_panels[0])

uni.update_panels()

uni.attron(uni.COLOR_PAIR(4))
uni.mvaddstr(0,
             int(NCOLS / 2) - 2,
             "Use tab to browse through the windows (Q to Exit)")
uni.attroff(uni.COLOR_PAIR(4))
uni.doupdate()

top = my_panels[2]

ch = -1
while ((ch != uni.CCHAR('q')) and (ch != uni.CCHAR('Q'))):
    ch = uni.getch()
    if ch == 9:
        top = uni.panel_userptr(top)
        uni.top_panel(top)
    uni.update_panels()