def handle_mypython(): """ This function handles the post requests. It retrieves an input-code from the web-interface and calls the feeline- function() with it. It then updates the web-interface by retrieving all data (history) from feedline and returns a updated page. Returns: updated_page: The updated and rendered webpage. Raises: TemplateNotFound: If templates/console.html. ImportError: If feedline.py is not in directory. """ # retrieves text from input (web interface) code = request.form["code"] feedline(code) # retrieves data stored in feedline (history) input_list = get_input() output_list = get_output() # updates and renders the data in the web insterface updated_page = render_template("console.html", outp=output_list, inp=input_list) return updated_page
def handle_input(): """ Handles input from user in the form. Uses the feedline function to execute the commands. """ assert request.method == 'POST' # make sure it's the right method input = request.form["input"] # get the form-input a=feedline(input,namespace) # send to the feedline function history.append(input) # put input into the history list if a: # if a is not an empty string, append that too. history.append(a) # render page again. return render_template("post.html",buffer=history)
def prompt(): """ Asks for user input using getchar(). If enter is pressed the function calls the feedline()-function with the user input. If arrow up/down are used the function retrieves history information. The program terminates if ctrl+d is pressed in an empty-line. """ global counter global length typing = True line = "" cn = length-1 # TODO handling ctrl+d and arrow keys could possible be # moved to their own functions for better readability. while typing: char = getchar() sys.stdout.write(char) # Handles CTRL+D to exit. if char in "\x04": if not line == "": sys.stdout.write("\nKeyboardInterupt") line = "" sys.stdout.write(feedline(line)) typing = False else: print"\nKthankxbye!" exit(0) # Handles arrows keys and command history # Iterates over a history list (hist_list) with a counter (cn) if char in "\x1b": key = sys.stdin.read(2) sys.stdout.write("\r" + " "*(len(line)+20) + "\r" + "in [%d]: "%counter) # Checks if arrow up or arrow down is pressed if key == "[A" and len(hist_list)>0: line = hist_list[cn] sys.stdout.write(line) cn -= 1 if cn == -1: cn = length-1 elif key == "[B" and len(hist_list)>0: cn += 1 if cn == length: cn = 0 line = hist_list[cn] sys.stdout.write(line) continue # Stop cycle if newline if char in "\r\n": hist_list.append(line) # save input in list length += 1 # Check for magic commands if is_magic(line) == True: output = feedline("") sys.stdout.write(output) #To print new promt out_list.append(output) else: output = feedline(line) sys.stdout.write(output) out_list.append(output) output = "" counter += 1 return # Else, simply add char to line. else: line += char
def prompt(): """ Asks for user input using getchar(). If enter is pressed the function calls the feedline()-function with the user input. If arrow up/down are used the function retrieves history information. The program terminates if ctrl+d is pressed in an empty-line. """ global counter global length typing = True line = "" cn = length - 1 # TODO handling ctrl+d and arrow keys could possible be # moved to their own functions for better readability. while typing: char = getchar() sys.stdout.write(char) # Handles CTRL+D to exit. if char in "\x04": if not line == "": sys.stdout.write("\nKeyboardInterupt") line = "" sys.stdout.write(feedline(line)) typing = False else: print "\nKthankxbye!" exit(0) # Handles arrows keys and command history # Iterates over a history list (hist_list) with a counter (cn) if char in "\x1b": key = sys.stdin.read(2) sys.stdout.write("\r" + " " * (len(line) + 20) + "\r" + "in [%d]: " % counter) # Checks if arrow up or arrow down is pressed if key == "[A" and len(hist_list) > 0: line = hist_list[cn] sys.stdout.write(line) cn -= 1 if cn == -1: cn = length - 1 elif key == "[B" and len(hist_list) > 0: cn += 1 if cn == length: cn = 0 line = hist_list[cn] sys.stdout.write(line) continue # Stop cycle if newline if char in "\r\n": hist_list.append(line) # save input in list length += 1 # Check for magic commands if is_magic(line) == True: output = feedline("") sys.stdout.write(output) #To print new promt out_list.append(output) else: output = feedline(line) sys.stdout.write(output) out_list.append(output) output = "" counter += 1 return # Else, simply add char to line. else: line += char