import curses import array import ctypes def test(stdscr): if curses.chtype_size == 4: line = array.array('L', [0] * curses.COLS) elif curses.chtype_size == 8: # 64-bit machines line = array.array('L', [0] * curses.COLS * 2) else: raise ValueError("curses.chtype_size = %d" % curses.chtype_size) buf = ctypes.create_string_buffer(curses.chtype_size * curses.COLS) string = "Python&curses" char_attribs = [ curses.A_BOLD, curses.A_UNDERLINE, curses.A_REVERSE, curses.A_DIM, curses.A_BLINK, curses.A_ALTCHARSET, ] for y in xrange(curses.LINES): # pic attribute attr = char_attribs[y % len(char_attribs)] # setup chtype string for x in xrange(curses.COLS): if curses.chtype_size == 4: line[x] = ord(string[x % len(string)]) | attr elif curses.chtype_size == 4: line[x*2] = ord(string[x % len(string)]) | attr # put on string stdscr.addchstr(y, 2*y, line) # test ctypes buffer #buf = line.tostring() #stdscr.addchstr(y, 2*y, buf) stdscr.getch() curses.wrapper(test)