Skip to content

Commit

Permalink
Add color to eyeball output headers
Browse files Browse the repository at this point in the history
  • Loading branch information
orome committed Oct 25, 2023
1 parent e6f4f79 commit c06d68e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ jobs:
- name: Run eyeball tests
if: runner.os != 'Windows'
run: |
pip install termcolor
PYTHONPATH=. python tests/eyeball.py
- name: Test with pytest
run: |
pip install pytest
pytest tests/ --maxfail=3 --showlocals --color=yes -v
env:
PY_COLORS: "1"
10 changes: 6 additions & 4 deletions tests/eyeball.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# encoding: utf8

import termcolor
from automata import *


Expand All @@ -15,12 +16,13 @@ def print_header(level, label='', mark=None) -> None:
rule = (mark * (HEADER_LENGTH//2))[:((HEADER_LENGTH+1-(len(label)+2))//2)]

# Must be outside f-strings to run on Python < 3.12
header_text = f"{rule} {label} {rule[::-1]}"[:HEADER_LENGTH]
header_start = '\033[1m' if level <= 1 else ''
header_end = '\033[0;0m' if level <= 1 else ''
header_text = termcolor.colored(f"{rule} {label} {rule[::-1]}"[:HEADER_LENGTH],
color='green' if level <= 0 else 'dark_grey',
on_color=None if level <= 0 else 'on_black',
attrs=['bold', 'dark'] if level <= 0 else ['bold'])
header_blanks = '\n' if level != 1 else '\n\n'

print(f"{header_blanks}{header_start}{header_text}{header_end}")
print(f"{header_blanks}{header_text}")


def eyeball_basic_ca(rule_number: int, initial_conditions: str, base: int,
Expand Down

0 comments on commit c06d68e

Please sign in to comment.