Пример #1
0
 def get_user_string(self, xpos=3, ypos=15, filterfunc=str.isalnum, completer=None):
     # filter allowed characters using filterfunc, alphanumeric by default
     user_string = ""
     user_input = 0
     if completer:
         completer = completer(self)
     while user_input != 10:
         user_input = self.screen.getch()
         if user_input == -1: # Input comes from pipe/file and is closed
             raise IOError
         self.screen_lock.acquire()
         # osx and unix backspace chars...
         if user_input == 127 or user_input == 263:
             if len(user_string) > 0:
                 user_string = user_string[:-1]
                 if completer:
                     completer.update_input(user_string)
                 self.screen.addstr(ypos, xpos, " " * (self.maxx-xpos-1))
         elif user_input in [ord('\t'), curses.KEY_BTAB] and completer:
             direction = 1 if user_input == ord('\t') else -1
             user_string = completer.complete(direction)
             self.screen.addstr(ypos, xpos, " " * (self.maxx-xpos-1))
         elif user_input < 256 and user_input != 10:
             if filterfunc(chr(user_input)):
                 user_string += chr(user_input)
                 if completer:
                     completer.update_input(user_string)
         self.screen.addstr(ypos, xpos, str(user_string))
         self.screen.refresh()
         self.screen_lock.release()
     return user_string
Пример #2
0
 def get_user_string(self,
                     xpos=3,
                     ypos=15,
                     filterfunc=str.isalnum,
                     completer=None):
     # filter allowed characters using filterfunc, alphanumeric by default
     user_string = ""
     user_input = 0
     if completer:
         completer = completer(self)
     while user_input != 10:
         user_input = self.screen.getch()
         self.screen_lock.acquire()
         # osx and unix backspace chars...
         if user_input == 127 or user_input == 263:
             if len(user_string) > 0:
                 user_string = user_string[:-1]
                 if completer:
                     completer.update_input(user_string)
                 self.screen.addstr(ypos, xpos,
                                    " " * (self.maxx - xpos - 1))
         elif user_input in [ord('\t'), curses.KEY_BTAB] and completer:
             direction = 1 if user_input == ord('\t') else -1
             user_string = completer.complete(direction)
             self.screen.addstr(ypos, xpos, " " * (self.maxx - xpos - 1))
         elif user_input < 256 and user_input != 10:
             if filterfunc(chr(user_input)):
                 user_string += chr(user_input)
                 if completer:
                     completer.update_input(user_string)
         self.screen.addstr(ypos, xpos, str(user_string))
         self.screen.refresh()
         self.screen_lock.release()
     return user_string