Example #1
0
    def test_text_spinner_color(self):
        """Test basic spinner with available colors color (both spinner and text)
        """
        for color, color_int in COLORS.items():
            self._stream_file = os.path.join(self.TEST_FOLDER, 'test.txt')
            self._stream = io.open(self._stream_file, 'w+')

            spinner = Halo(
                text='foo',
                text_color=color,
                color=color,
                spinner='dots',
                stream=self._stream
            )

            spinner.start()
            time.sleep(1)
            spinner.stop()
            output = self._get_test_output()['colors']

            # check if spinner colors match
            self.assertEqual(color_int, int(output[0][0]))
            self.assertEqual(color_int, int(output[1][0]))
            self.assertEqual(color_int, int(output[2][0]))

            # check if text colors match
            self.assertEqual(color_int, int(output[0][1]))
            self.assertEqual(color_int, int(output[1][1]))
            self.assertEqual(color_int, int(output[2][1]))
Example #2
0
    def test_spinner_color(self):
        """Test ANSI escape characters are present
        """

        for color, color_int in COLORS.items():
            spinner = HaloNotebook(color=color)
            spinner.start()
            output = self._get_test_output(spinner, no_ansi=False)
            spinner.stop()

            output_merged = [arr for c in output['colors'] for arr in c]

            self.assertEquals(str(color_int) in output_merged, True)
Example #3
0
    def test_spinner_color(self):
        """Test ANSI escape characters are present
        """

        for color, color_int in COLORS.items():
            self._stream = io.open(self._stream_file, 'w+')  # reset stream
            spinner = Halo(color=color, stream=self._stream)
            spinner.start()
            spinner.stop()

            output = self._get_test_output(no_ansi=False)
            output_merged = [arr for c in output['colors'] for arr in c]

            self.assertEquals(str(color_int) in output_merged, True)
Example #4
0
    def test_text_spinner_color(self):
        """Test basic spinner with available colors color (both spinner and text)
        """
        for color, color_int in COLORS.items():
            spinner = HaloNotebook(text='foo', text_color=color, color=color, spinner='dots')

            spinner.start()
            time.sleep(1)
            output = self._get_test_output(spinner)['colors']
            spinner.stop()

            # check if spinner colors match
            self.assertEqual(color_int, int(output[0][0]))
            self.assertEqual(color_int, int(output[1][0]))
            self.assertEqual(color_int, int(output[2][0]))

            # check if text colors match
            self.assertEqual(color_int, int(output[0][1]))
            self.assertEqual(color_int, int(output[1][1]))
            self.assertEqual(color_int, int(output[2][1]))
Example #5
0
import re
import curses
from termcolor import COLORS, RESET, ATTRIBUTES, HIGHLIGHTS
from .log import log

C_R = {'\x1b[%dm' % v: 'COLOR_%s' % k.upper() for k, v in COLORS.items()}
A_R = {'\x1b[%dm' % v: 'A_%s' % k.upper() for k, v in ATTRIBUTES.items()}
A_R['\x1b[3m'] = 'A_ITALIC'
H_R = {
    '\x1b[%dm' % v: 'COLOR_%s' % k[3:].upper()
    for k, v in HIGHLIGHTS.items()
}
COLORS_R = {'\x1b[%dm' % v: k for k, v in COLORS.items()}
COLOR_SCAN = re.compile(r'(\x1b\[\d+m)')
delete_sub = re.compile(r'(\x1b\[\d+\w)')
COLOR_SCAN2 = re.compile(r'(\x1b\[(\d+)\;?\d*m)')


def ascii2filter(words):
    if isinstance(words, list):
        strings = COLOR_SCAN2.sub('', ' '.join(words)).split()
    else:
        strings = COLOR_SCAN2.sub('', words)
    return strings


def fgascii2curses(context,
                   row,
                   col,
                   string,
                   colors=None,
Example #6
0
import re

from termcolor import cprint, colored, COLORS

mobile = '06 09-00-15-45'

# raw string
pattern1 = r'\d\d-\d\d-\d\d-\d\d-\d\d'
# add end of line $ ans start of line ^
pattern2 = r'\A\d\d-\d\d-\d\d-\d\d-\d\d$'
pattern3 = r'\A[0-9]{2}[ -]\d\d-\d\d-\d\d-\d\d$'
pattern4 = r'\A[0-9]{2}[ -]\d{2}-\d{2}-\d{2}-\d{2}'

for k, v in COLORS.items():
    print(f'{k}', end='  ')
print('\n')

if re.fullmatch(pattern4, mobile):
    cprint(f'{mobile} is accepted',
           'green',
           on_color='on_white',
           attrs=['bold'])
else:
    print(f'{mobile} is {colored("rejected", "grey", "on_red")}')

a_str = 'this is'


def test_exp(p):
    global a_str
    if re.match(p, a_str):