当前位置: 首页>>代码示例>>Python>>正文


Python history.FileHistory方法代码示例

本文整理汇总了Python中prompt_toolkit.history.FileHistory方法的典型用法代码示例。如果您正苦于以下问题:Python history.FileHistory方法的具体用法?Python history.FileHistory怎么用?Python history.FileHistory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prompt_toolkit.history的用法示例。


在下文中一共展示了history.FileHistory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: refresh_completions

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def refresh_completions(self, history=None, persist_priorities="all"):
        """ Refresh outdated completions

        :param history: A prompt_toolkit.history.FileHistory object. Used to
                        load keyword and identifier preferences

        :param persist_priorities: 'all' or 'keywords'
        """

        callback = functools.partial(
            self._on_completions_refreshed, persist_priorities=persist_priorities
        )
        self.completion_refresher.refresh(
            self.pgexecute,
            self.pgspecial,
            callback,
            history=history,
            settings=self.settings,
        )
        return [
            (None, None, None, "Auto-completion refresh started in the background.")
        ] 
开发者ID:dbcli,项目名称:pgcli,代码行数:24,代码来源:main.py

示例2: main

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def main():
    settings = Settings()
    bindings = get_bindings(settings)
    executor = Executor(settings)
    toolbar = Toolbar(settings)
    completer = KafkaCompleter(settings) if settings.enable_auto_complete else None
    suggester = AutoSuggestFromHistory() if settings.enable_auto_suggest else None
    history = ThreadedHistory(FileHistory(get_user_history_path())) if settings.enable_history else InMemoryHistory()
    session = PromptSession(completer=completer, style=style, bottom_toolbar=toolbar.handler,
                            key_bindings=bindings, history=history, include_default_pygments_style=False)
    while True:
        try:
            command = session.prompt([("class:operator", "> ")], auto_suggest=suggester)
        except KeyboardInterrupt:
            continue
        except EOFError:
            break
        else:
            executor.execute(command)

    settings.save_settings() 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:23,代码来源:main.py

示例3: open_shell

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def open_shell(ctx):
    for idx, param in enumerate(ctx.parent.command.params):
        if param.name == "app_path":
            del ctx.parent.command.params[idx]

    for cmd in NON_SHELL_CMDS:
        del ctx.parent.command.commands[cmd]

    settings = dict(
        color_depth=config.PROMPT_COLOR_DEPTH,
        style=config.PROMPT_STYLE,
        history=FileHistory(".aioli.history"),
        message=[
            ("class:prompt-name", f"[{ctx.obj.app_path}]"),
            ("class:prompt-marker", u"> "),
        ],
        # completer=ContextualCompleter()
    )

    while True:
        try:
            if not repl(ctx, prompt_kwargs=settings):
                break
        except Exception as e:
            utils.echo(f"err> {str(e)}") 
开发者ID:aioli-framework,项目名称:aioli,代码行数:27,代码来源:root.py

示例4: cli_ads_search

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def cli_ads_search(args):
    """Command-line interface for ads-search call."""
    if args.next:
        query = None
    else:
        completer = u.KeyWordCompleter(u.ads_keywords, bm.load())
        session = prompt_toolkit.PromptSession(
            history=FileHistory(u.BM_HISTORY_ADS()))
        query = session.prompt(
            "(Press 'tab' for autocomplete)\n",
            auto_suggest=u.AutoSuggestCompleter(),
            completer=completer,
            complete_while_typing=False,
            ).strip()
        if query == "" and os.path.exists(u.BM_CACHE()):
            query = None
        elif query == "":
            return
    try:
        am.manager(query)
    except ValueError as e:
        print(f"\nError: {str(e)}") 
开发者ID:pcubillos,项目名称:bibmanager,代码行数:24,代码来源:__main__.py

示例5: __init__

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def __init__(self, parser, engine, options=None):
        self.parser = parser
        self.engine = engine
        self.options = options if options is not None else {}
        util.ensure_data_dir_exists()
        application = create_prompt_application(
            message='> ',
            lexer=PygmentsLexer(SqlLexer),
            history=FileHistory(os.path.expanduser('~/.aq/history')),
            completer=AqCompleter(schemas=engine.available_schemas, tables=engine.available_tables),
            auto_suggest=AutoSuggestFromHistory(),
            validator=QueryValidator(parser),
            on_abort=AbortAction.RETRY,
        )
        loop = create_eventloop()
        self.cli = CommandLineInterface(application=application, eventloop=loop)
        self.patch_context = self.cli.patch_stdout_context() 
开发者ID:lebinh,项目名称:aq,代码行数:19,代码来源:prompt.py

示例6: main

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def main():
    """ 
         Start the Slack Client 
    """
    os.system("clear; figlet 'Slack Gitsin' | lolcat")
    history = FileHistory(os.path.expanduser("~/.slackHistory"))
    while True:
        text = prompt("slack> ", history=history,
                      auto_suggest=AutoSuggestFromHistory(),
                      on_abort=AbortAction.RETRY,
                      style=DocumentStyle,
                      completer=Completer(fuzzy_match=False,
                                          text_utils=TextUtils()),
                      complete_while_typing=Always(),
                      get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
                      key_bindings_registry=manager.registry,
                      accept_action=AcceptAction.RETURN_DOCUMENT
        )
        slack = Slack(text)
        slack.run_command() 
开发者ID:yasintoy,项目名称:Slack-Gitsin,代码行数:22,代码来源:main.py

示例7: _do_shell

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def _do_shell(_args):
    commands = ['compile', 'convert', 'help', 'exit']
    completer = WordCompleter(commands, WORD=True)
    user_home = os.path.expanduser('~')
    history = FileHistory(os.path.join(user_home, '.asn1tools-history.txt'))
    session = PromptSession(completer=completer,
                            complete_while_typing=True,
                            auto_suggest=AutoSuggestFromHistory(),
                            enable_history_search=True,
                            history=history)
    input_spec = None
    output_spec = None
    output_codec = None

    print("\nWelcome to the asn1tools shell!\n")

    while True:
        try:
            line = session.prompt(u'$ ')
        except EOFError:
            return

        line = line.strip()

        if line:
            if line.startswith('compile'):
                input_spec, output_spec, output_codec = _handle_command_compile(line)
            elif line.startswith('convert'):
                _handle_command_convert(line,
                                        input_spec,
                                        output_spec,
                                        output_codec)
            elif line == 'help':
                _handle_command_help()
            elif line == 'exit':
                return
            else:
                print('{}: command not found'.format(line)) 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:40,代码来源:__init__.py

示例8: history

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def history():
    return FileHistory('%s/.pytify-search-history' % str(Path.home())) 
开发者ID:bjarneo,项目名称:Pytify,代码行数:4,代码来源:history.py

示例9: __init__

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def __init__(self, request, logger, config):
        self.request = request
        self.config = config
        self.logger = logger
        self.cmds = {
            "exploit": self._exploit,
            "check": self._check,
            "list": self._list,
        }

        self.auto_cmds = WordCompleter(["quit", "list", "check", "exploit"], ignore_case=True)
        self.history = FileHistory('.drupwn-history')
        self._load() 
开发者ID:immunIT,项目名称:drupwn,代码行数:15,代码来源:Exploiter.py

示例10: run

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def run(self):
        """Runs the interface and waits for user input commands."""
        completer = WordCompleter(['show', 'name', 'field', 'fields',
                                   'dump', 'recalculate', 'clear', 'back'])
        history = FileHistory(self._polym_path + '/.linterface_history')
        session = PromptSession(history=history)
        while True:
            try:
                command = session.prompt(HTML("<bold>PH:cap/t%d/<red>%s</red> > </bold>" %
                                              (self._tindex, self._l.name)),
                                         completer=completer,
                                         complete_style=CompleteStyle.READLINE_LIKE,
                                         auto_suggest=AutoSuggestFromHistory(),
                                         enable_history_search=True)
            except KeyboardInterrupt:
                self.exit_program()
                continue
            # Argument parsing
            command = command.split(" ")
            if command[0] in self.EXIT:
                self.exit_program()
            elif command[0] in self.RET:
                break
            elif command[0] in ["s", "show"]:
                self._show(command)
            elif command[0] == "name":
                self._name(command)
            elif command[0] in ["field", "f"]:
                self._field(command)
            elif command[0] in ["fields", "fs"]:
                self._fields(command)
            elif command[0] in ["dump", "d"]:
                self._dump(command)
            elif command[0] in ["recalculate", "r"]:
                self._recalculate(command)
            elif command[0] == "clear":
                Interface._clear()
            elif command[0] == "":
                continue
            else:
                Interface._wrong_command() 
开发者ID:shramos,项目名称:polymorph,代码行数:43,代码来源:layerinterface.py

示例11: run

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def run(self):
        """Runs the interface and waits for user input commands."""
        completer = WordCompleter(['show', 'dissect', 'template', 'wireshark',
                                   'clear', 'back'])
        history = FileHistory(self._polym_path + '/.tlinterface_history')
        session = PromptSession(history=history)
        while True:
            try:
                command = session.prompt(HTML("<bold>PH:<red>cap</red> > </bold>"),
                                         completer=completer,
                                         complete_style=CompleteStyle.READLINE_LIKE,
                                         auto_suggest=AutoSuggestFromHistory(),
                                         enable_history_search=True)
            except KeyboardInterrupt:
                self.exit_program()
                continue
            command = command.split(" ")
            if command[0] in self.EXIT:
                self.exit_program()
            elif command[0] in self.RET:
                break
            elif command[0] in ["show", "s"]:
                self._show(command)
            elif command[0] == "dissect":
                self._dissect(command)
            elif command[0] in ["template", "t"]:
                self._template(command)
            elif command[0] in ["wireshark", "w"]:
                self._wireshark(command)
            elif command[0] == "clear":
                Interface._clear()
            elif command[0] == "":
                continue
            else:
                Interface._wrong_command() 
开发者ID:shramos,项目名称:polymorph,代码行数:37,代码来源:tlistinterface.py

示例12: run

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def run(self):
        """Runs the interface and waits for user input commands."""
        completer = WordCompleter(['capture', 'spoof', 'clear', 'import'])
        history = FileHistory(self._polym_path + '/.minterface_history')
        session = PromptSession(history=history)
        while True:
            try:
                command = session.prompt(HTML("<bold><red>PH</red> > </bold>"),
                                         completer=completer,
                                         complete_style=CompleteStyle.READLINE_LIKE,
                                         auto_suggest=AutoSuggestFromHistory(),
                                         enable_history_search=True)
            except KeyboardInterrupt:
                self.exit_program()
                continue
            command = command.split(" ")
            if command[0] in self.EXIT:
                self.exit_program()
            elif command[0] in ["capture", "c"]:
                self._capture(command)
            elif command[0] in ["spoof", "s"]:
                self._spoof(command)
            elif command[0] in ["import", "i"]:
                self._import(command)
            elif command[0] == "clear":
                Interface._clear()
            elif command[0] == "":
                continue
            else:
                Interface._wrong_command() 
开发者ID:shramos,项目名称:polymorph,代码行数:32,代码来源:maininterface.py

示例13: main

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def main(args):
    os.environ[ENV_ADDITIONAL_USER_AGENT] = 'AZURECLISHELL/' + __version__

    parser = argparse.ArgumentParser(prog='az-shell')
    parser.add_argument(
        '--style', dest='style', help='the colors of the shell',
        choices=get_options())
    args = parser.parse_args(args)

    azure_folder = cli_config_dir()
    if not os.path.exists(azure_folder):
        os.makedirs(azure_folder)

    ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
    CONFIG.load(os.path.join(azure_folder, 'az.json'))
    SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600)

    config = SHELL_CONFIGURATION
    shell_config_dir = azclishell.configuration.get_config_dir

    if args.style:
        given_style = args.style
        config.set_style(given_style)
    else:
        given_style = config.get_style()

    style = style_factory(given_style)

    if config.BOOLEAN_STATES[config.config.get('DEFAULT', 'firsttime')]:
        print("When in doubt, ask for 'help'")
        config.firsttime()

    shell_app = Shell(
        completer=AZCOMPLETER,
        lexer=AzLexer,
        history=FileHistory(
            os.path.join(shell_config_dir(), config.get_history())),
        app=APPLICATION,
        styles=style
    )
    shell_app.run() 
开发者ID:Azure,项目名称:azure-cli-shell,代码行数:43,代码来源:__main__.py

示例14: __init__

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def __init__(self, refresh_resources=True):
        shell_dir = os.path.expanduser("~/.kube/shell/")
        self.history = FileHistory(os.path.join(shell_dir, "history"))
        if not os.path.exists(shell_dir):
            os.makedirs(shell_dir)
        self.toolbar = Toolbar(self.get_cluster_name, self.get_namespace, self.get_user, self.get_inline_help) 
开发者ID:cloudnativelabs,项目名称:kube-shell,代码行数:8,代码来源:kubeshell.py

示例15: main

# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import FileHistory [as 别名]
def main():
    our_history = FileHistory(".example-history-file")

    # The history needs to be passed to the `PromptSession`. It can't be passed
    # to the `prompt` call because only one history can be used during a
    # session.
    session = PromptSession(history=our_history)

    while True:
        text = session.prompt("Say something: ")
        print("You said: %s" % text) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:13,代码来源:persistent-history.py


注:本文中的prompt_toolkit.history.FileHistory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。