<commit_before>#!/usr/bin/env bash

# Script to demonstrate features of colorama

# This demo, which can manually be visually verified, exists because we don't
# have an automated system test.

# Implemented as a bash script which invokes python so that we can test the
# behaviour on exit, which resets default colors again.

python 2>err <<EOF
import sys

from colorama import init, Fore, Back, Style

init()

# example of common usage
print Fore.GREEN + 'green' + Fore.RED + 'red' + Fore.RESET + 'normal',
print Back.GREEN + 'green' + Back.RED + 'red' + Back.RESET + 'normal',
print Style.DIM + 'dim' + \
    Style.NORMAL + 'normal' + \
    Style.BRIGHT + 'bright'
print Style.RESET_ALL

FORES = [
    Fore.BLACK,
    Fore.RED,
    Fore.GREEN,
    Fore.YELLOW,
    Fore.BLUE,
    Fore.MAGENTA,
    Fore.CYAN,
    Fore.WHITE,
]
BACKS = [
    Back.BLACK,
    Back.RED,
    Back.GREEN,
    Back.YELLOW,
    Back.BLUE,
    Back.MAGENTA,
    Back.CYAN,
    Back.WHITE,
]
STYLES = [
    Style.DIM,
    Style.NORMAL,
    Style.BRIGHT,
]

NAMES = {
    Fore.BLACK: 'black',
    Fore.RED: 'red',
    Fore.GREEN: 'green',
    Fore.YELLOW: 'yellow',
    Fore.BLUE: 'blue',
    Fore.MAGENTA: 'magenta',
    Fore.CYAN: 'cyan',
    Fore.WHITE: 'white',
    Fore.RESET: 'reset',
    Back.BLACK: 'black',
    Back.RED: 'red',
    Back.GREEN: 'green',
    Back.YELLOW: 'yellow',
    Back.BLUE: 'blue',
    Back.MAGENTA: 'magenta',
    Back.CYAN: 'cyan',
    Back.WHITE: 'white',
    Back.RESET: 'reset',
}

# print grid of all colors and brightnesses
# use stdout.write to write chars with no newline nor spaces between them
sys.stdout.write('        ')
for foreground in FORES:
    sys.stdout.write('%s%-7s' % (foreground, NAMES[foreground]))
print

for background in BACKS:
    sys.stdout.write('%s%-7s%s %s' %
       (background, NAMES[background], Back.RESET, background))

    for foreground in FORES:
        sys.stdout.write(foreground)

        for brightness in STYLES:
            sys.stdout.write(brightness)

            sys.stdout.write('X ')

        sys.stdout.write(Style.RESET_ALL + ' ' + background)

    print Style.RESET_ALL

# check autoreset works
init(autoreset=True)
print
print Fore.CYAN + Back.MAGENTA + Style.BRIGHT + 'colored', 'autoreset'

# check reset_all is called at exit
init(autoreset=False)
print Fore.YELLOW + Back.BLUE + Style.BRIGHT + 'colored',

EOF

echo 'reset at exit'

python 2>err <<EOF2
import sys
from colorama import init, Fore

init()

# check that ANSI in redirected stderr is stripped
print Fore.RED + 'Red stdout.',
print >>sys.stderr, Fore.BLUE + 'ANSI stripped from blue redirected stderr.'

# check that stripped ANSI in redirected stderr did not affect stdout
print 'Further stdout should be red'
EOF2

cat err

rm -rf err out


<commit_msg>tidy demo.sh<commit_after>#!/usr/bin/env bash

# Script to demonstrate features of colorama

# This demo, which can manually be visually verified, exists because we don't
# have an automated system test.

# Implemented as a bash script which invokes python so that we can test the
# behaviour on exit, which resets default colors again.


# example of common usage
python 2>err <<EOF
import sys
from colorama import init, Fore, Back, Style

init()

print Fore.GREEN + 'green' + Fore.RED + 'red' + Fore.RESET + 'normal',
print Back.GREEN + 'green' + Back.RED + 'red' + Back.RESET + 'normal',
print Style.DIM + 'dim' + \
    Style.NORMAL + 'normal' + \
    Style.BRIGHT + 'bright'
print Style.RESET_ALL
EOF


# print grid of all colors and brightnesses
# uses stdout.write to write chars with no newline nor spaces between them
python 2>err <<EOF2
import sys
from colorama import init, Fore, Back, Style

init()

FORES = [
    Fore.BLACK,
    Fore.RED,
    Fore.GREEN,
    Fore.YELLOW,
    Fore.BLUE,
    Fore.MAGENTA,
    Fore.CYAN,
    Fore.WHITE,
]
BACKS = [
    Back.BLACK,
    Back.RED,
    Back.GREEN,
    Back.YELLOW,
    Back.BLUE,
    Back.MAGENTA,
    Back.CYAN,
    Back.WHITE,
]
STYLES = [
    Style.DIM,
    Style.NORMAL,
    Style.BRIGHT,
]

NAMES = {
    Fore.BLACK: 'black',
    Fore.RED: 'red',
    Fore.GREEN: 'green',
    Fore.YELLOW: 'yellow',
    Fore.BLUE: 'blue',
    Fore.MAGENTA: 'magenta',
    Fore.CYAN: 'cyan',
    Fore.WHITE: 'white',
    Fore.RESET: 'reset',
    Back.BLACK: 'black',
    Back.RED: 'red',
    Back.GREEN: 'green',
    Back.YELLOW: 'yellow',
    Back.BLUE: 'blue',
    Back.MAGENTA: 'magenta',
    Back.CYAN: 'cyan',
    Back.WHITE: 'white',
    Back.RESET: 'reset',
}

sys.stdout.write('        ')
for foreground in FORES:
    sys.stdout.write('%s%-7s' % (foreground, NAMES[foreground]))
print

for background in BACKS:
    sys.stdout.write('%s%-7s%s %s' %
       (background, NAMES[background], Back.RESET, background))

    for foreground in FORES:
        sys.stdout.write(foreground)

        for brightness in STYLES:
            sys.stdout.write(brightness)

            sys.stdout.write('X ')

        sys.stdout.write(Style.RESET_ALL + ' ' + background)

    print Style.RESET_ALL
print
EOF2


# check autoreset works
# check reset_all is called at exit
python <<EOF3
import sys
from colorama import init, Fore, Back, Style

init(autoreset=True)
print
print Fore.CYAN + Back.MAGENTA + Style.BRIGHT + 'colored', 'autoreset'

init(autoreset=False)
print Fore.YELLOW + Back.BLUE + Style.BRIGHT + 'colored',
EOF3
echo 'reset at exit'


# check ANSI is stripped from redirected stdout
python >out <<EOF4
import sys
from colorama import init, Fore
init()

print Fore.RED + 'redirected stdout should contain no ansi'
EOF4
cat out


# check that ANSI is stripped from redirected stderr, and that stripped ANSI in
# redirected stderr does not affect stdout
python 2>err <<EOF2
import sys
from colorama import init, Fore

init()

print Fore.RED + 'Red stdout.',
print >>sys.stderr, Fore.BLUE + 'redirected stderr should contain no ansi'

print 'Further stdout should also be red'
EOF2
cat err


# clean up
rm -rf err out


{'fraction_non_alphanumeric': 0.11972423070455691, 'fraction_numerical': 0.003194888178913738, 'mean_word_length': 3.110573600552868, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5656371', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2046, 'n_words': 626}