Skip to content

Instantly share code, notes, and snippets.

@wh0th3h3llam1
Created October 15, 2021 13:36
Show Gist options
  • Save wh0th3h3llam1/e65bc1eab967a22952e1ced5129bfcac to your computer and use it in GitHub Desktop.
Save wh0th3h3llam1/e65bc1eab967a22952e1ced5129bfcac to your computer and use it in GitHub Desktop.
Colorful output on Python/Bash/Batch/PowerShell
@echo off
echo Gray
echo Red
echo Green
echo Yellow
echo Blue
echo Magenta
echo Cyan
echo White
echo [ERROR] Some ERROR
echo [INFO] Some INFO
echo [SUCCESS] Some SUCCESS
echo.
echo [INFO] Some [4; highlight  text
@REM REFERENCES
rem https://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line
rem https://gist.github.com/mlocati/fdabcaeb8071d5c75a2d51712db24011#file-win10colors-cmd
rem https://gist.githubusercontent.com/mlocati/fdabcaeb8071d5c75a2d51712db24011/raw/b710612d6320df7e146508094e84b92b34c77d48/win10colors.cmd
rem http://codeproject.com/Articles/17033/Add-Colors-to-Batch-Files
# A module "PSWriteColor" is required for this to work
# It can be installed using below command
# Install-Module -Name PSWriteColor -RequiredVersion 0.86
Write-Color -Text "[SUCCESS]", "Module Installed Successfully" -Color Green, White
Write-Color -Text "[INFO] ", "Files Updated Successfully" -C Cyan, White
Write-Color -Text "[WARNING]", "No Admin Permissions, All features will not be available" -Color Yellow, White
Write-Color -Text "[ERROR] ", "Couldn't update system" -C Red, White
# Allowed Colors
# Black,
# DarkBlue,
# DarkGreen,
# DarkCyan,
# DarkRed,
# DarkMagenta,
# DarkYellow,
# Gray,
# DarkGray,
# Blue,
# Green,
# Cyan,
# Red,
# Magenta,
# Yellow,
# White,
import os
os.system("")
# Group of Different functions for different styles
class Color:
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
WHITE = '\033[37m'
UNDERLINE = '\033[4m'
RESET = '\033[0m'
print(Color.YELLOW + "Hello, World!")
# REFERENCES:
# https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-python
def print_format_table():
"""
prints table of formatted text format options
"""
for style in range(8):
for fg in range(30, 38):
s1 = ''
for bg in range(40, 48):
formatting = ';'.join([str(style), str(fg), str(bg)])
s1 += '\x1b[%sm %s \x1b[0m' % (formatting, formatting)
print(s1)
print('\n')
print_format_table()
#!/bin/bash
# ANSI Colour Codes for Coloured Output
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
NC='\033[0m'
printf "${RED}[ERROR]${NC} Action couldn't be completed\n"
printf "${GREEN}[SUCCESS] ${NC}Action completed\n"
# Coloured output won't work with plain echo
echo -e "I ${RED}love${NC} Stack Overflow"
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BROWN_ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHT_GRAY='\033[0;37m'
DARK_GRAY='\033[1;30m'
LIGHT_RED='\033[1;31m'
LIGHT_GREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHT_BLUE='\033[1;34m'
LIGHT_PURPLE='\033[1;35m'
LIGHT_CYAN='\033[1;36m'
WHITE='\033[1;37m'
#
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
# Light Gray 0;37 White 1;37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment