#!/usr/bin/env python ## CURSES BASIC-MAIL GUI # This is the Basic-Mail program, a basic email client written in python # with a curses interface. # # To Run: Go to the Basic-Mail directory and type "python Basic-Mail.py", # without the quotes. ## ## chat.py ## # This is file includes the functions related to editing text. ## ## IMPORTS ## import curses, curses.ascii, curses.panel # Curses imports import traceback, os, sys, select, string # Random imports # Initializes and Globalizes (?) the Menus, Tabs, and Title within the # chat file def initialize_chat_variables(menu_array,tabs_array,program_title_import): global menu, tabs, program_title menu = menu_array tabs = tabs_array program_title = program_title_import ## Function: Clears away part of a line def redraw_line(window, width, height, x_after_question, y): x = width-1 while (x > x_after_question): window.delch(y, x) x -= 1 window.delch(y, x) ## CHAT MODULES ## # Chat (Window1, Window2, Window Width, Window Height, Question to Ask) def chat(window,output_s_win,menu_bar,stdscr,width,height,question): ## Asks the user a question, returns the response # Initializes Chat Variables window.keypad(1) # Allows for special keys, e.g. backspace y = height/2 orig_x = 2 response = '' next_line = 0 window.addstr(y, orig_x, question, curses.color_pair(1)) window.addch(' ') x_after_question = orig_x + len(question) x = x_after_question # Moves x past the question redraw_line(window,width,height,x_after_question,y) while(1): window.addch(y, width-1, '|') window.move(y,x) input = window.getch(y, x) if input == ord('\n') and x > x_after_question: redraw_line(window,width,height,x_after_question,y) draw_borders(window,width,height) x = x_after_question break elif x == width-3: redraw_line(window,width,height,x_after_question,y) draw_borders(window,width,height) x = x_after_question window.addch(y, x_after_question-1,'/',curses.color_pair(1)) next_line = 1 elif input == curses.KEY_BACKSPACE and x > x_after_question: x -= 1 # Moves input to last space response = response[0:-1] # Removes the last char window.delch(y, width-1) # Deletes right border window.delch(y, x) window.vline(1,width-1,'|',1) # Redraws Border elif next_line == 1 and \ input == curses.KEY_BACKSPACE and x == x_after_question: window.addstr(response) x += len(response) window.addch(y, x_after_question-1,' ') next_line = 0 elif curses.ascii.unctrl(input) == "^R": draw_screen() elif curses.ascii.unctrl(input) == "^F": draw_screen() hightlight_menu_option(menu_bar,0,2,option1) menu_bar.refresh() elif curses.ascii.unctrl(input) == "^E": draw_screen() hightlight_menu_option(menu_bar,0,2+len(option1)+2,option2) menu_bar.refresh() elif curses.ascii.unctrl(input) == "^H": draw_screen() hightlight_menu_option(menu_bar,0,2+len(option1)+2+len(option2)+2\ ,option3) menu_bar.refresh() elif curses.ascii.isctrl(input): pass elif input > 255 or input == 10: # Ignores non-ASCII keys and newline window.delch(y,x) window.delch(y,width-2) draw_borders(window,width,height) else: x += 1 # Moves to next space response += curses.ascii.unctrl(input) window.addch(input) next_line = 0 return response