import curses from curses.textpad import Textbox, rectangle def draw_main_menu(stdscr): # Command is the last char the user entered. command = 0 # Clear, and refresh the screen stdscr.clear() stdscr.refresh() # Start some curses colors curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) while command != ord('q'): # Clear the screen stdscr.clear() # Get the height, and width height, width = stdscr.getmaxyx() # Temporary strings, replace these with libdocs! title = 'Untitled Adventure Game PRE ALPHA'[:width - 1] subtitle = 'Joe Sedutto'[:width - 1] statusbarstr = "Press 'q' to exit " # Centering calculations start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2) start_y = int((height // 2) - 2) # Rendering some text whstr = 'Width: {}, Height: {}'.format(width, height) stdscr.addstr(0, 0, whstr, curses.color_pair(1)) # Render status bar stdscr.attron(curses.color_pair(3)) stdscr.addstr(height - 1, 0, statusbarstr) stdscr.addstr(height - 1, len(statusbarstr), ' ' * (width - len(statusbarstr) - 1)) stdscr.attroff(curses.color_pair(3)) # Turning on attributes for title stdscr.attron(curses.color_pair(2)) stdscr.attron(curses.A_BOLD) # Rendering title stdscr.addstr(start_y, start_x_title, title) # Turning off attributes for title stdscr.attroff(curses.color_pair(2)) stdscr.attroff(curses.A_BOLD) # Print rest of text stdscr.addstr(start_y + 1, start_x_subtitle, subtitle) stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4) # Refresh the screen stdscr.refresh() # Wait for next input command = stdscr.getch() def main_textbox(stdscr): stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)") editwin = curses.newwin(5,30, 2,1) rectangle(stdscr, 1,0, 1+5+1, 1+30+1) stdscr.refresh() box = Textbox(editwin) # Let the user edit until Ctrl-G is struck. box.edit() # Get resulting contents message = box.gather() def main(): curses.wrapper(main_textbox) if __name__ == '__main__': main()