How to use the colored.fg function in colored

To help you get started, we’ve selected a few colored 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 nk412 / corella / hnossa.py View on Github external
def draw_row(cells):
	for n_cell, cell in enumerate(cells):
		val = int((float(cell)+1) // (2/(len(GRADIENT)-1)))
		print('{color}{c}{c}{c}{c}{reset}'.format(
			color=fg(GRADIENT_COLORS[val]),
			c=GRADIENT[val],
			reset=attr('reset')
			), end='')
github gwen001 / pentest-tools / openredirect.py View on Github external
t_payloads.append( args.payloads )
    n_payloads = len(t_payloads)
    sys.stdout.write( '%s[+] %d payloads found: %s%s\n' % (fg('green'),n_payloads,args.payloads,attr(0)) )
else:
    n_payloads = 0

t_path = [ '' ]
if args.path:
    if os.path.isfile(args.path):
        fp = open( args.path, 'r' )
        t_path = fp.read().strip().split("\n")
        fp.close()
    else:
        t_path.append( args.path )
n_path = len(t_path)
sys.stdout.write( '%s[+] %d path found: %s%s\n' % (fg('green'),n_path,args.path,attr(0)) )

if args.verbose:
    _verbose = int(args.verbose)
else:
    _verbose = 1

if args.threads:
    _threads = int(args.threads)
else:
    _threads = 10

if args.redirect:
    t_redirect_domain = [ args.redirect.lower() ]
else:
    t_redirect_domain = [ 'google.com', 'www.google.com', '216.58.214.206' ]
github gwen001 / pentest-tools / quickhits.py View on Github external
def saveFile( d_output, t_urlparse, r ):
    # filename = t_urlparse.path.strip('/')
    filename = t_urlparse.path
    filename = re.sub( '[^0-9a-zA-Z_\-\.]', '_', filename )
    d_output = d_output +  '/' + t_urlparse.netloc
    f_output = d_output + '/' + filename
    # print(f_output)
    
    if not os.path.isdir(d_output):
        try:
            os.makedirs( d_output )
        except Exception as e:
            sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
            return
    
    s_headers = 'HTTP/1.1 ' + str(r.status_code) + ' ' + r.reason + "\n"
    for k,v in r.headers.items():
        s_headers = s_headers + k + ': ' + v + "\n"

    # print(s_headers)
    content = s_headers + "\n" + r.text
    fp = open( f_output, 'w' )
    fp.write( content )
    fp.close()
github magicalraccoon / tootstream / src / tootstream / toot.py View on Github external
"""Unmutes a user by username or id.

    ex: unmute 23
        unmute @user
        unmute @user@instance.example.com"""
    userid = get_userid(mastodon, rest)
    if isinstance(userid, list):
        cprint("  multiple matches found:", fg('red'))
        printUsersShort(userid)
    elif userid == -1:
        cprint("  username not found", fg('red'))
    else:
        try:
            relations = mastodon.account_unmute(userid)
            if not relations['muting']:
                cprint("  user " + str(userid) + " is now unmuted", fg('blue'))
        except:
            cprint("  Error, unable to unmute.", fg('red'))
unmute.__argstr__ = ''
github gwen001 / github-search / github-survey2.py View on Github external
def doGetCode( result ):
    token = random.choice( t_tokens )
    headers = {"Authorization": "token "+token}
    # print( headers )

    try:
        print( result['git_url'] )
        r = requests.get( result['git_url'], headers=headers, timeout=5 )
    except Exception as e:
        sys.stdout.write( "%s[-] error occurred: %s%s\n" % (fg('red'),e,attr(0)) )
        return False

    if r:
        t_json = r.json()
        if 'sha' in t_json:
            if len(t_json['content']):
                result['code'] = base64.b64decode( t_json['content'].replace('\n','') )
            else:
                result['code'] = ''
            return True
        else:
            return False
    else:
        return False
github SebiSebi / friendlylog / friendlylog / colored_logger.py View on Github external
def _colorize(msg, loglevel):
        loglevel = str(loglevel).lower()
        if loglevel not in LOG_LEVEL_LIST:
            raise RuntimeError("{} should be oneof {}.".format(
                loglevel, LOG_LEVEL_LIST))  # pragma: no cover
        msg = str(loglevel).upper() + ": " + str(msg)

        if loglevel == DEBUG:
            return "{}{}{}{}{}".format(fg(14), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == INFO:
            return "{}{}{}{}{}".format(fg(46), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == WARNING:
            return "{}{}{}{}{}".format(fg(214), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == ERROR:
            return "{}{}{}{}{}".format(fg(202), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == CRITICAL:
            return "{}{}{}{}{}".format(fg(196), attr(1), msg, attr(21), attr(0))  # noqa: E501
github android-dtf / dtf / python-dtf / dtf / colors.py View on Github external
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Wrapper API for using colors in dtf modules"""

from __future__ import absolute_import
from colored import fg, attr

import dtf.globals as glbl

COLOR_ERR = fg(1)
COLOR_WARN = fg(3)
COLOR_INFO = fg(2)
COLOR_VERB = fg(6)
COLOR_DEB = fg(5)


def __use_colors():

    """Check if colors should be used"""

    return bool(glbl.get_generic_global('Config', 'use_colors') == '1')


def error(message):

    """Color format a message for errors"""
github SebiSebi / friendlylog / friendlylog / colored_logger.py View on Github external
def _colorize(msg, loglevel):
        loglevel = str(loglevel).lower()
        if loglevel not in LOG_LEVEL_LIST:
            raise RuntimeError("{} should be oneof {}.".format(
                loglevel, LOG_LEVEL_LIST))  # pragma: no cover
        msg = str(loglevel).upper() + ": " + str(msg)

        if loglevel == DEBUG:
            return "{}{}{}{}{}".format(fg(14), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == INFO:
            return "{}{}{}{}{}".format(fg(46), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == WARNING:
            return "{}{}{}{}{}".format(fg(214), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == ERROR:
            return "{}{}{}{}{}".format(fg(202), attr(1), msg, attr(21), attr(0))  # noqa: E501
        if loglevel == CRITICAL:
            return "{}{}{}{}{}".format(fg(196), attr(1), msg, attr(21), attr(0))  # noqa: E501
github magicalraccoon / tootstream / src / tootstream / toot.py View on Github external
def printToot(toot):
    if not toot:
        return

    out = []
    # if it's a boost, only output header line from toot
    # then get other data from toot['reblog']
    if toot.get('reblog'):
        header = stylize("  Boosted by ", fg('yellow'))
        display_name = format_display_name(toot['account']['display_name'])
        name = " ".join(( display_name,
                          format_username(toot['account'])+":" ))
        out.append(header + stylize(name, fg('blue')))
        toot = toot['reblog']

    # get the first two lines
    random.seed(toot['account']['display_name'])
    out += [ "  "+format_toot_nameline(toot, fg(random.choice(COLORS))),
             "  "+format_toot_idline(toot) ]

    if toot['spoiler_text'] != '':
        # pass CW through get_content for wrapping/indenting
        faketoot = { 'content': "[CW: "+toot['spoiler_text']+"]" }
        out.append( stylize(get_content(faketoot), fg('red')))
github python-tableformatter / tableformatter / tableformatter.py View on Github external
def set_color_library(cls, library_name: str) -> None:
        """Manually override the color library being used."""
        if library_name == 'colored':
            from colored import fg, bg, attr

            cls.TEXT_COLOR_WHITE = fg('white')
            cls.TEXT_COLOR_YELLOW = fg(226)
            cls.TEXT_COLOR_RED = fg(196)
            cls.TEXT_COLOR_GREEN = fg(119)
            cls.TEXT_COLOR_BLUE = fg(27)
            cls.BG_COLOR_ROW = bg(234)
            cls.BG_RESET = attr('reset')  # docs say bg(0) should do this but it doesn't work right
            cls.BOLD = attr('bold')
            cls.RESET = attr('reset')
        elif library_name == 'colorama':
            from colorama import Fore, Back, Style

            cls.TEXT_COLOR_WHITE = Fore.WHITE
            cls.TEXT_COLOR_YELLOW = Fore.LIGHTYELLOW_EX
            cls.TEXT_COLOR_RED = Fore.LIGHTRED_EX
            cls.TEXT_COLOR_GREEN = Fore.LIGHTGREEN_EX
            cls.TEXT_COLOR_BLUE = Fore.LIGHTBLUE_EX
            cls.BG_COLOR_ROW = Back.LIGHTBLACK_EX
            cls.BG_RESET = Back.RESET
            cls.BOLD = Style.BRIGHT
            cls.RESET = Fore.RESET + Back.RESET