Example #1
0
def _completer(prefix, index):
    # 获取当前行
    line = readline.get_line_buffer().decode(_encoding)
    cmd, args = manager.parse_input(line)
    words = []
    if cmd is None:
        # 自动提示命令
        words = manager.get_command_names()
        words = map(lambda x: '%s ' % x, words)
        words = filter(lambda x: x.startswith(prefix), words)
    else:
        # 自动提示参数
        arg_prefix = args[-1] if len(args) > 0 else ''
        words = cmd.get_completer_words(arg_prefix)
    return words[index] if words and index < len(words) else None
Example #2
0
def _completer(prefix, index):
    # 获取当前行
    line = readline.get_line_buffer().decode(_encoding)
    cmd, args = manager.parse_input(line)
    words = []
    if cmd is None:
        # 自动提示命令
        words = manager.get_command_names()
        words = map(lambda x:'%s ' % x, words)
        words = filter(lambda x:x.startswith(prefix), words)
    else:
        # 自动提示参数
        arg_prefix = args[-1] if len(args) > 0 else ''
        words = cmd.get_completer_words(arg_prefix)
    return words[index] if words and index < len(words) else None
Example #3
0
 def run(self):
     if context.client.is_login:
         print 'login user: %s' % context.client.user_name
     while context.is_alive():
         try:
             prompt = ('BaiduPan:%s> ' % context.get_rwd()).encode(_encoding)
             # 获取输入
             line = raw_input(prompt).strip().decode(_encoding)
             # 跳过空行
             if len(line) == 0: continue
             # 解析命令和参数
             cmd, args = manager.parse_input(line)
             if cmd is None:
                 print 'No such command'
                 continue
             if cmd.need_login and not context.client.is_login:
                 print 'You MUST login before use %s' % cmd.name
                 continue
             cmd.execute(args)
         except KeyboardInterrupt:
             print
         except:
             traceback.print_exc()
Example #4
0
 def run(self):
     if context.client.is_login:
         print 'login user: %s' % context.client.user_name
     while context.is_alive():
         try:
             prompt = ('BaiduPan:%s> ' %
                       context.get_rwd()).encode(_encoding)
             # 获取输入
             line = raw_input(prompt).strip().decode(_encoding)
             # 跳过空行
             if len(line) == 0: continue
             # 解析命令和参数
             cmd, args = manager.parse_input(line)
             if cmd is None:
                 print 'No such command'
                 continue
             if cmd.need_login and not context.client.is_login:
                 print 'You MUST login before use %s' % cmd.name
                 continue
             cmd.execute(args)
         except KeyboardInterrupt:
             print
         except:
             traceback.print_exc()