def _runInterface(options): # initialise curses stdscr = curses.initscr() curses.noecho() curses.cbreak() stdscr.nodelay(1) stdscr.keypad(1) reactor.addSystemEventTrigger('after', 'shutdown', cleanup_curses, stdscr) # first lets sort out logging in username = '******' password = '******' hostname = 'localhost' insecure = False port = 7531 if options.username and options.password and options.hostname: username = options.username password = options.password hostname = options.hostname if options.port: try: port = int(options.port) except ValueError: pass if options.insecure: insecure = True authenticator = fpb.Authenticator(username=username, password=password) info = PBConnectionInfo(hostname, port, not insecure, authenticator) connection.connect_to_manager(stdscr, info) else: # do greeter # get recent connections greeter = AdminTextGreeter(stdscr) reactor.addReader(greeter) greeter.show()
def doRead(self): c= self.stdscr.getch() if self.state == 0: if c == curses.KEY_DOWN: if self.current_connection >= self.displayed_connections: self.current_connection = 0 else: self.current_connection = self.current_connection + 1 self.show() elif c == curses.KEY_UP: if self.current_connection == 0: self.current_connection = self.displayed_connections else: self.current_connection = self.current_connection - 1 self.show() elif c == curses.KEY_ENTER or c == 10: # if new connection, ask for username, password, hostname etc. if self.current_connection == self.displayed_connections: curses.curs_set(1) self.current_input = self.inputs[1] self.state = 1 self.display_current_input_line() else: # ok a recent connection has been selected curses.curs_set(1) c = self.connections[self.current_connection] info = c.info reactor.removeReader(self) connection.connect_to_manager(self.stdscr, info) else: if c == curses.KEY_ENTER or c == 10: if self.state < 6: self.inputs[self.state] = self.current_input if self.state < 5: self.current_input = self.inputs[self.state+1] self.state = self.state + 1 self.display_current_input_line() else: # connect reactor.removeReader(self) try: port = int(self.inputs[2]) except ValueError: port = 7531 info = PBConnectionInfo(self.inputs[1], port, self.inputs[3] == 'Yes', fpb.Authenticator( username=self.inputs[4], password=self.inputs[5])) connection.connect_to_manager(self.stdscr, info) pass elif c == curses.KEY_BACKSPACE or c == 127: self.current_input = self.current_input[:-1] self.display_current_input_line() elif c == curses.KEY_UP: if self.state > 0: self.current_input = self.inputs[self.state-1] self.state = self.state - 1 if self.state == 0: # turn off cursor curses.curs_set(0) self.display_current_input_line() elif c == curses.KEY_DOWN: pass else: self.current_input = self.current_input + chr(c) self.display_current_input_line()
def doRead(self): c = self.stdscr.getch() if self.state == 0: if c == curses.KEY_DOWN: if self.current_connection >= self.displayed_connections: self.current_connection = 0 else: self.current_connection = self.current_connection + 1 self.show() elif c == curses.KEY_UP: if self.current_connection == 0: self.current_connection = self.displayed_connections else: self.current_connection = self.current_connection - 1 self.show() elif c == curses.KEY_ENTER or c == 10: # if new connection, ask for username, password, hostname etc. if self.current_connection == self.displayed_connections: curses.curs_set(1) self.current_input = self.inputs[1] self.state = 1 self.display_current_input_line() else: # ok a recent connection has been selected curses.curs_set(1) c = self.connections[self.current_connection] info = c.info reactor.removeReader(self) connection.connect_to_manager(self.stdscr, info) else: if c == curses.KEY_ENTER or c == 10: if self.state < 6: self.inputs[self.state] = self.current_input if self.state < 5: self.current_input = self.inputs[self.state + 1] self.state = self.state + 1 self.display_current_input_line() else: # connect reactor.removeReader(self) try: port = int(self.inputs[2]) except ValueError: port = 7531 info = PBConnectionInfo( self.inputs[1], port, self.inputs[3] == 'Yes', fpb.Authenticator(username=self.inputs[4], password=self.inputs[5])) connection.connect_to_manager(self.stdscr, info) pass elif c == curses.KEY_BACKSPACE or c == 127: self.current_input = self.current_input[:-1] self.display_current_input_line() elif c == curses.KEY_UP: if self.state > 0: self.current_input = self.inputs[self.state - 1] self.state = self.state - 1 if self.state == 0: # turn off cursor curses.curs_set(0) self.display_current_input_line() elif c == curses.KEY_DOWN: pass else: self.current_input = self.current_input + chr(c) self.display_current_input_line()