How to use the cmd2.ansi.style 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_cmd2.py View on Github external
def test_poutput_ansi_never(outsim_app):
    msg = 'Hello World'
    ansi.allow_style = ansi.STYLE_NEVER
    colored_msg = ansi.style(msg, fg='cyan')
    outsim_app.poutput(colored_msg)
    out = outsim_app.stdout.getvalue()
    expected = msg + '\n'
    assert colored_msg != msg
    assert out == expected
github qsecure-labs / overlord / modules / redirector.py View on Github external
def __init__(self,mod,campaign):
        global campaign_list
        global module

        if mod is not None:    
            module = mod
        
        campaign_list = campaign
        
        # Call cmd_main class 
        i = cmd_main()
        i.prompt = cmd2.ansi.style("Overlord", fg='red', bg='', bold=True, underline=False) + \
            cmd2.ansi.style("/redirector", fg='blue', bg='',
                            bold=True, underline=False) + "$> "
        i.cmdloop()
github qsecure-labs / overlord / overlord.py View on Github external
def do_delmodule(self, arg):
        """Deletes a module"""
        if arg.id == "all":
            self.campaign = []
            notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
            print(f"""\n{notification} All modules have been deleted from the campaign {notification}\n""")
        else:
            for idx,c in enumerate(self.campaign):
                if arg.id == c["id"]:
                    self.campaign.pop(idx)
                    mod = cmd2.ansi.style(c["module"], fg='blue', bg='',bold=True, underline=False)
                    mod_id = cmd2.ansi.style(c["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 deleted from the campaign {notification}\n""")
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 python-cmd2 / cmd2 / examples / colors.py View on Github external
def do_speak(self, args):
        """Repeats what you tell me to."""
        words = []
        for word in args.words:
            if args.piglatin:
                word = '%s%say' % (word[1:], word[0])
            if args.shout:
                word = word.upper()
            words.append(word)

        repetitions = args.repeat or 1
        output_str = ansi.style(' '.join(words), fg=args.fg, bg=args.bg, bold=args.bold, underline=args.underline)

        for i in range(min(repetitions, self.maxrepeats)):
            # .poutput handles newlines, and accommodates output redirection too
            self.poutput(output_str)
github qsecure-labs / overlord / overlord.py View on Github external
super().__init__()
        hide_cmd2_modules(self)
        #Initialize project ID
        dir_path = "projects"
        uniq = True
        while True:
            rand = randomString()
            for p in next(os.walk(dir_path))[1]:
                if p == rand:
                    uniq = False
            if uniq:
                break

        self.project_id = rand

        self.prompt =  "(" + cmd2.ansi.style("Overlord", fg='red', bg='',bold=True, underline=False) + " : " + cmd2.ansi.style( rand, fg='bright_black', bg='',bold=True, underline=False) + ")" +"$> "
        self.loadproject_id.choices = next(os.walk(dir_path))[1]
        self.cloneproject_id.choices = next(os.walk(dir_path))[1]

        if  os.path.exists(dir_path+"/variables.json"):
            with open(dir_path+'/variables.json', 'r') as filehandle:
                self.variables = json.load(filehandle)
                self.domain_parser_id.choices = self.variables["domains"]
github qsecure-labs / overlord / overlord.py View on Github external
if  flag == 'y':
            dir_path = "projects/"+self.project_id+"/.terraform"
            if  os.path.exists(dir_path):
                os.system(f"""cd projects/{self.project_id} && /opt/terraform state rm module.redirect_ns""")
                os.system(f"""cd projects/{self.project_id} && /opt/terraform destroy -auto-approve""")
                os.system(f"""rm projects/{self.project_id}/terraform.tfstate*""")
                shutil.rmtree(f"""projects/{self.project_id}/.terraform""")
            notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
            print(f"""\n{notification} Check if terraform exited without an error before you proceed. {notification}\n""")
            flag1 = input(cmd2.ansi.style("Proceding with deleting project directory. Are you sure? [y/N]:", fg='red', bg='',bold=True, underline=False))
            if flag1 == "y":
                shutil.rmtree("projects/"+self.project_id)
                self.loadproject_id.choices = next(os.walk("projects"))[1]
                self.cloneproject_id.choices = next(os.walk("projects"))[1]
                self.update_choices(self.campaign)
                proj = cmd2.ansi.style(self.project_id, fg='blue', bg='',bold=True, underline=False)
                notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
                print(f"""\n{notification} The project with ID {proj} has been deleted {notification}\n""")
github qsecure-labs / overlord / overlord.py View on Github external
def do_save(self,arg):
        """Save a project"""
        dir_path = "projects/"+self.project_id
        if not os.path.exists(dir_path):
            self.create_dir()
        with open(dir_path+'/campaign.json', 'w') as filehandle:
            json.dump(self.campaign, filehandle,indent=4)
        with open(dir_path+'/variables.json', 'w') as filehandle:
            json.dump(self.variables, filehandle,indent=4)
        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)
        notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
        print(f"""\n{notification} The config files for the project with ID {proj} have been created  {notification}\n""")
github qsecure-labs / overlord / overlord.py View on Github external
uniq = True
            while True:
                rand = randomString()
                for p in next(os.walk(dir_path))[1]:
                    if p == rand:
                        uniq = False
                if uniq:
                    break
            self.project_id = rand
        else:
            self.project_id = arg.id
        self.campaign = []
        proj = cmd2.ansi.style(self.project_id, fg='blue', bg='',bold=True, underline=False)
        notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
        print(f"""\n{notification} New project with ID {proj} has been created.  {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 / overlord.py View on Github external
def set_variables(self, arg):
        with open('projects/variables.json', 'w') as filehandle:
                json.dump(self.variables, filehandle,indent=4)

        notification = cmd2.ansi.style("***", fg='red', bg='',bold=True, underline=False)
        print(f"""\n{notification} Variables have been saved to ./projects/variables.json {notification}\n""")