Skip to content

Commit

Permalink
Fix info and warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbrnowski committed Aug 16, 2021
1 parent 422b893 commit 7be77b4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions cft/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ def __init__(self, n, name, extension):
}


def error_style(message):
def error_style(message) -> str:
return fg(196) + message + rs.all # red


def warning_style(message):
def warning_style(message) -> str:
return fg(220) + message + rs.all # yellow


def info_style(message):
def info_style(message) -> str:
return fg(244) + message + rs.all # grey


def positive_style(message):
def positive_style(message) -> str:
return fg(70) + message + rs.all # green


def negative_style(message):
def negative_style(message) -> str:
return fg(208) + message + rs.all # orange


def neutral_style(message):
def neutral_style(message) -> str:
return fg(69) + message + rs.all # blue


Expand Down
4 changes: 2 additions & 2 deletions cft/utils/race.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def contest_letters(contest):
if len(r.history):
raise requests.HTTPError
except requests.HTTPError:
print(warning_style('Something went wrong while accessing problems'))
print(warning_style('Something went wrong while accessing problems.'))
return contest_letters_default(contest)
soup = bs4.BeautifulSoup(r.text, 'html.parser')
letters = soup.select('table.problems tr:nth-child(n+2) td:first-child a')
Expand All @@ -42,7 +42,7 @@ def contest_letters_default(contest):
if d.lower() in ('y', 'yes'):
return list('ABCDEFG')
else:
print('Aborted')
print(info_style('Aborted.'))
os.chdir('..')
os.rmdir(contest)
sys.exit()
4 changes: 2 additions & 2 deletions cft/utils/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def submit(args):
except requests.HTTPError:
print(error_style("Something went wrong while submitting."))
sys.exit()
print('Solution has been submitted.')
print(info_style('Solution has been submitted.'))

print('Verdict:')
while True:
Expand All @@ -52,7 +52,7 @@ def submit(args):
v = soup.select_one('div.datatable table tr:nth-child(2) td.status-verdict-cell').text.strip()
print('\033[F\033[K', end='')
if v.startswith('Running') or v == 'In queue':
print('Verdict: ' + v)
print('Verdict: ' + info_style(v))
elif v == 'Accepted':
print('Verdict: ' + positive_style(v))
break
Expand Down
20 changes: 10 additions & 10 deletions cft/utils/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test(args):
try:
r.raise_for_status()
except requests.HTTPError:
print(error_style('Something went wrong while downloading tests'))
print(error_style('Something went wrong while downloading tests.'))
sys.exit()

soup = bs4.BeautifulSoup(r.text, 'html.parser')
Expand All @@ -45,7 +45,7 @@ def test(args):
print(error_style('Solution has not been compiled.'))
sys.exit()
else:
print('Solution has been compiled.')
print(info_style('Solution has been compiled.'))

i = 1
while os.path.exists(os.path.join('in', f'{i}.in')):
Expand All @@ -62,7 +62,7 @@ def compile_solution(problem, compile_command):
return subprocess.run([*compile_command.split(' '), f'{problem}.{language.ext}'], timeout=10)
except subprocess.TimeoutExpired:
print(error_style('Compilation time has exceeded 10 seconds.'))
print('Make sure you are using appropriate compile and run commands for your language.')
print(info_style('Make sure you are using appropriate compile and run commands for your language.'))
sys.exit()
except OSError:
print(error_style('Compile command is wrong or compiler is not installed.'))
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_solution(problem, i, args):
test_err = r.stderr.strip()
except FileNotFoundError:
print(error_style('Executable file has not been found.'))
print('Make sure you are using appropriate compile and run commands for your language.')
print(info_style('Make sure you are using appropriate compile and run commands for your language.'))
sys.exit()
except subprocess.TimeoutExpired:
print(negative_style('Execution time exceeded 10 seconds.'))
Expand All @@ -102,18 +102,18 @@ def test_solution(problem, i, args):
else:
print(negative_style('Test did not pass\n'))
if test_err:
print('Program error:', test_err, '', sep='\n')
print(info_style('Program error:'), test_err, '', sep='\n')
terminal_width = (shutil.get_terminal_size().columns - 4) // 2
max_line_width = max(len(line) for line in test_out.split('\n') + test_ans.split('\n'))
if max_line_width > terminal_width:
print('Program output:', test_out, '', sep='\n')
print('Answer:', test_ans, sep='\n')
print(info_style('Program output:'), test_out, '', sep='\n')
print(info_style('Answer:'), test_ans, sep='\n')
else:
max_line_width = min(max(max_line_width + 4, 16), terminal_width)
print(f'{"Program output:":{max_line_width}} {"Answer:":{max_line_width}}')
print(info_style(f'{"Program output:":{max_line_width}} Answer:'))
for out_line, ans_line in zip(test_out.split('\n'), test_ans.split('\n')):
separator = negative_style(' ? ') if not check_line(out_line, ans_line, args) else ' '*4
print(f'{out_line:{max_line_width}}{separator}{ans_line:{max_line_width}}')
separator = negative_style(' ? ') if not check_line(out_line, ans_line, args) else ' ' * 4
print(f'{out_line:{max_line_width}}{separator}{ans_line}')
print('')


Expand Down

0 comments on commit 7be77b4

Please sign in to comment.