How to use the cmd2.ansi function in cmd2

To help you get started, we’ve selected a few cmd2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-cmd2 / cmd2 / tests / test_ansi.py View on Github external
def test_strip_ansi():
    base_str = HELLO_WORLD
    ansi_str = ansi.style(base_str, fg='green')
    assert base_str != ansi_str
    assert base_str == ansi.strip_ansi(ansi_str)
github python-cmd2 / cmd2 / cmd2 / argparse_completer.py View on Github external
def _print_completion_error(self, arg_action: argparse.Action, completion_error: CompletionError) -> None:
        """
        Print a CompletionError to the user
        :param arg_action: action being tab completed
        :param completion_error: error that occurred
        """
        # Indent all lines of completion_error
        indented_error = textwrap.indent(str(completion_error), '  ')

        error = ("\nError tab completing {}:\n"
                 "{}\n".format(argparse._get_action_name(arg_action), indented_error))
        self._print_message(ansi.style_error('{}'.format(error)))
github qsecure-labs / overlord / overlord.py View on Github external
def addModule(module,campaign):
    """Adds a module to the campaign"""
    if module:
        campaign.insert(len(campaign),dict(module))
        mod = cmd2.ansi.style(module["module"], fg='blue', bg='',bold=True, underline=False)
        mod_id = cmd2.ansi.style(module["id"], fg='blue', bg='',bold=True, underline=False)
        notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
        print(f"""\n{notification} Module {mod} with ID {mod_id} has been added to the campaign {notification}\n""")
github qsecure-labs / overlord / modules / firewall.py View on Github external
def __init__(self,campaign,mod,project_id):
        global campaign_list
        campaign_list = campaign

        if mod is not None:
            global module
            module = mod

        # Call cmd_main class 
        i = cmd_main()
        i.prompt = "(" + cmd2.ansi.style("Overlord", fg='red', bg='',bold=True, underline=False) + " : " + cmd2.ansi.style( project_id, fg='bright_black', bg='',bold=True, underline=False) + cmd2.ansi.style("/firewall", fg='blue', bg='',bold=True, underline=False) +")" +"$> "
        i.cmdloop()
github qsecure-labs / overlord / overlord.py View on Github external
def do_rename(self,arg):
        """Rename a project"""
        notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
        if not arg:
            print(f"""\n{notification} You have to specify a new name for your project! {notification}\n""")
        else:
            proj_old = cmd2.ansi.style(self.project_id, fg='blue', bg='',bold=True, underline=False)
            dir_path = "projects/"+self.project_id
            if os.path.exists(dir_path):
                os.rename("projects/"+self.project_id, "projects/"+arg)
            self.project_id = arg

            self.loadproject_id.choices = next(os.walk("projects"))[1]
            self.cloneproject_id.choices = next(os.walk("projects"))[1]

            proj = cmd2.ansi.style(self.project_id, fg='blue', bg='',bold=True, underline=False)
            print(f"""\n{notification} The project with ID {proj_old} has been renamed to {proj} {notification}\n""")
            self.prompt =  "(" + cmd2.ansi.style("Overlord", fg='red', bg='',bold=True, underline=False) + " : " + cmd2.ansi.style( self.project_id, fg='bright_black', bg='',bold=True, underline=False) + ")" +"$> "
github qsecure-labs / overlord / modules / letsencrypt.py View on Github external
def __init__(self,campaign,mod,project_id): #domains
        global campaign_list
        global module

        campaign_list = campaign
        if mod is not None:
            module = mod


        # Call cmd_main class 
        i = cmd_main()
        i.prompt = "(" + cmd2.ansi.style("Overlord", fg='red', bg='',bold=True, underline=False) + " : " + cmd2.ansi.style( project_id, fg='bright_black', bg='',bold=True, underline=False) + cmd2.ansi.style("/letsencrypt", fg='blue', bg='',bold=True, underline=False) +")" +"$> "
        i.cmdloop()
github python-cmd2 / cmd2 / cmd2 / argparse_completer.py View on Github external
:return: False if the group has already been completed and there is a conflict, otherwise True
            """
            # Check if this action is in a mutually exclusive group
            for group in self._parser._mutually_exclusive_groups:
                if arg_action in group._group_actions:

                    # Check if the group this action belongs to has already been completed
                    if group in completed_mutex_groups:

                        # If this is the action that completed the group, then there is no error
                        # since it's allowed to appear on the command line more than once.
                        completer_action = completed_mutex_groups[group]
                        if arg_action == completer_action:
                            return True

                        error = ansi.style_error("\nError: argument {}: not allowed with argument {}\n".
                                                 format(argparse._get_action_name(arg_action),
                                                        argparse._get_action_name(completer_action)))
                        self._print_message(error)
                        return False

                    # Mark that this action completed the group
                    completed_mutex_groups[group] = arg_action

                    # Don't tab complete any of the other args in the group
                    for group_action in group._group_actions:
                        if group_action == arg_action:
                            continue
                        elif group_action in self._flag_to_action.values():
                            matched_flags.extend(group_action.option_strings)
                        elif group_action in remaining_positionals:
                            remaining_positionals.remove(group_action)
github qsecure-labs / overlord / modules / godaddy.py View on Github external
def __init__(self,campaign,domains,mod):
        global campaign_list
        campaign_list = campaign
        global domain_list 
        domain_list = domains
        if mod is not None:
            global module
            module = mod

        # Call cmd_main class 
        i = cmd_main()
        i.prompt = cmd2.ansi.style("Overlord", fg='red', bg='', bold=True, underline=False) + \
            cmd2.ansi.style("/godaddy", fg='blue', bg='',
                            bold=True, underline=False) + "$> "
        i.cmdloop()
github qsecure-labs / overlord / modules / c2.py View on Github external
def __init__(self,campaign,mod):
        global campaign_list
        campaign_list = campaign

        if mod is not None:
            global module
            module = mod

        # Call cmd_main class 
        i = cmd_main()
        i.prompt = cmd2.ansi.style("Overlord", fg='red', bg='', bold=True, underline=False) + \
            cmd2.ansi.style("/c2", fg='blue', bg='',
                            bold=True, underline=False) + "$> "
        i.cmdloop()