Exemplo n.º 1
0
def run_recorder(shell, prompt, aliases=None, envvars=None):
    commands = []
    prefix = '(' + style('REC', fg='red') + ') '
    while True:
        formatted_prompt = prefix + format_prompt(THEMES[prompt]) + ' '
        command = click.prompt(formatted_prompt, prompt_suffix='').strip()

        if command == STOP_COMMAND:
            break
        elif command == PREVIEW_COMMAND:
            echo_rec_buffer(commands)
        elif command == UNDO_COMMAND:
            if commands and click.confirm(
                    'Remove command? "{}"'.format(commands[-1].strip())):
                commands.pop()
                secho('Removed command.', bold=True)
                echo_rec_buffer(commands)
            else:
                echo('No commands in buffer. Doing nothing.')
        elif command == 'python':
            commands.append('```python\n')
            console = PythonRecorderConsole()
            console.interact()
            commands.extend(console.commands)
            commands.append('```\n\n')
        elif command in HELP_COMMANDS:
            print_recorder_instructions()
        else:
            commands.append(command + '\n\n')
            run_command(command, shell=shell,
                        aliases=aliases, envvars=envvars, test_mode=TESTING)
    return commands
Exemplo n.º 2
0
def run_recorder(shell, prompt, aliases=None, envvars=None):
    commands = []
    prefix = "(" + style("REC", fg="red") + ") "
    while True:
        formatted_prompt = prefix + format_prompt(THEMES[prompt]) + " "
        command = click.prompt(formatted_prompt, prompt_suffix="").strip()

        if command == STOP_COMMAND:
            break
        elif command == PREVIEW_COMMAND:
            echo_rec_buffer(commands)
        elif command == UNDO_COMMAND:
            if commands and click.confirm('Remove command? "{}"'.format(
                    commands[-1].strip())):
                commands.pop()
                secho("Removed command.", bold=True)
                echo_rec_buffer(commands)
            else:
                echo("No commands in buffer. Doing nothing.")
        elif command == "python":
            commands.append("```python\n")
            console = PythonRecorderConsole()
            console.interact()
            commands.extend(console.commands)
            commands.append("```\n\n")
        elif command in HELP_COMMANDS:
            print_recorder_instructions()
        else:
            commands.append(command + "\n\n")
            run_command(
                command,
                shell=shell,
                aliases=aliases,
                envvars=envvars,
                test_mode=TESTING,
            )
    return commands