Installing and Testing UniCurses

UniCurses is useful for taking control of the console, to obtain the functionality of the Pascal crt unit (and more besides). The original name curses was a pun on cursor optimization. We supply directions here for installation and testing on Windows.

  1. Download the UniCurses setup executable from sourceforge and double click on the filename to start the installation (which is quick and painless).
  2. Download pdcurses.dll and move it to your main Python folder (such as C:\Python33)
  3. Use this script to test the installation. See the comments that describe the instructions.
    # Script to test the installation of UniCurses
    from unicurses import *
    stdscr = initscr() # initializes the standard screen
    addstr('Hello World!\n')
    addch(ord('A') | A_BOLD)
    addstr(' single bold letter\n')
    attron(A_BOLD) # Turns on attribute
    addstr('\n\nBold string')
    addstr("\nNot bold now")
    mvaddch(7, 10, 66); #B at row 7, col 10
    addstr(' - single letter at row 7, col 10')
    init_pair(1, COLOR_RED, COLOR_GREEN) # Specifies foreground and background pair 1
    init_pair(2, COLOR_YELLOW, COLOR_RED)
    mvaddstr(15, 12, 'Red on green at row 15, col 12')	
    addstr('\n\nYellow on red')
    addstr('\n\nPress up arrow!')
    cbreak() # Gets raw key inputs but allows CRTL+C to work
    keypad(stdscr, True)  # Get arrow keys etc.
    noecho() # Do not display automatically characters for key presses
    a = getch() # Gets the key code
    if a == KEY_UP:
        addstr('Beep! Any key to quit.')    
    a = getch()
  4. Test it also with Snake, which might give you ideas for console games of your own.

As necessary, consult further information about UniCurses for Python and about the underlying NCURSES library (with instructions in C code).

Programming - a skill for life!

Converting from Python to Pascal