3535CR = "\r "
3636TRANSIENT = f"{ CLEAR_EOL } { CR } "
3737
38- TERMINAL_COLS = 96
39-
4038
4139@lru_cache (maxsize = None )
4240def aoc_available_puzzles (
@@ -491,12 +489,13 @@ def run_day(
491489 year : int ,
492490 day : int ,
493491 mday : str ,
494- day_inputs : t . Dict ,
495- day_answers : t . Dict ,
492+ day_inputs : dict ,
493+ day_answers : dict ,
496494 languages : dict ,
497- problems : t . Set ,
495+ problems : list [ str ] ,
498496 refresh : bool ,
499497 dry_run : bool ,
498+ terminal_columns : int ,
500499):
501500 elapsed = defaultdict (list )
502501
@@ -549,23 +548,20 @@ def run_day(
549548 continue
550549
551550 if (e ["status" ] == "unknown" and day_answers .get (crc )) or e ["status" ] in ("error" , "failed" ):
552- script = Path (f"resolve_{ e ['status' ]} .sh" )
551+ resolve_script = Path (f"resolve_{ e ['status' ]} .sh" )
553552 if "AOC_TARGET_DIR" in os .environ :
554- script = Path (os .environ ["AOC_TARGET_DIR" ]) / script
553+ resolve_script = Path (os .environ ["AOC_TARGET_DIR" ]) / resolve_script
555554
556- if not globals ().get (script ):
557- with script .open ("wt" ) as f :
555+ if not globals ().get (resolve_script ):
556+ with resolve_script .open ("wt" ) as f :
558557 print ("#!/bin/sh" , file = f )
559- script .chmod (0o755 )
560- globals ()[script ] = True
558+ resolve_script .chmod (0o755 )
559+ globals ()[resolve_script ] = True
561560
562- with script .open ("at" ) as f :
561+ with resolve_script .open ("at" ) as f :
563562 print (f"{ __file__ } --no-build -u { input_name } -l { lang } -r { year } { day } " , file = f )
564563
565- if e ["status" ] != "ok" :
566- info = f" { file } "
567- else :
568- info = ""
564+ answers = e ["answers" ]
569565
570566 status_color = {
571567 "ok" : GREEN ,
@@ -574,22 +570,21 @@ def run_day(
574570 "error" : RED ,
575571 }[e ["status" ]]
576572
577- answers = e ["answers" ]
578-
579573 line = (
580574 f"{ CR } { RESET } { CLEAR_EOL } "
581575 f"{ prefix } "
582576 f" { YELLOW } { lang :<7} { RESET } :"
583577 f" { status_color } { e ['status' ]:7} { RESET } "
584578 f" { WHITE } { e ['elapsed' ] / 1e9 :7.3f} s"
585579 f" { GRAY } { '☽' if in_cache else ' ' } "
586- f" { status_color } { str (answers ):<50} { RESET } "
587- f" { FEINT } { file } { RESET } "
588580 )
589- if TERMINAL_COLS >= 130 :
590- print (line , info )
591- else :
581+
582+ if terminal_columns < 60 :
592583 print (line )
584+ elif terminal_columns < 130 :
585+ print (line , f"{ status_color } { str (answers )} { RESET } " )
586+ else :
587+ print (line , f" { status_color } { str (answers ):<50} { RESET } { FEINT } { file } { RESET } " )
593588
594589 if e ["status" ] in ("error" , "failed" ):
595590 problems .append (line )
@@ -598,10 +593,10 @@ def run_day(
598593
599594 elapsed [lang ].append (e ["elapsed" ] / 1e9 )
600595
601- if len (results ) > 1 :
602- line = f"{ prefix } { RED } { BLINK } MISMATCH BETWEEN SOLUTIONS{ RESET } "
603- print (line )
604- problems .append (line )
596+ # if len(results) > 1:
597+ # line = f"{prefix} {RED}{BLINK}MISMATCH BETWEEN SOLUTIONS{RESET}"
598+ # print(line)
599+ # problems.append(line)
605600
606601 nb_samples = set (len (t ) for _ , t in elapsed .items ())
607602 assert len (nb_samples ) == 1 or len (nb_samples ) == 0
@@ -794,10 +789,7 @@ def main():
794789 CR = ""
795790
796791 # the terminal size
797- cols = subprocess .getoutput ("tput cols" )
798- if cols .isdigit ():
799- global TERMINAL_COLS
800- TERMINAL_COLS = int (cols )
792+ terminal_columns = os .get_terminal_size ().columns
801793
802794 if args .working_dir and args .working_dir .is_dir ():
803795 logging .debug (f"set working directory to: { args .working_dir } " )
@@ -886,12 +878,13 @@ def main():
886878 for mday in day_solutions :
887879 if prev_shown_year != year :
888880 if prev_shown_year != 0 :
889- print (
881+ line = (
890882 "==========================" # prefix
891883 " ===========================" # language, status
892884 " ==================================================" # answers
893885 " ==================================" # input path
894886 )
887+ print (line [: terminal_columns - 1 ])
895888 prev_shown_year = year
896889
897890 mday = mday .name .removeprefix ("day" )
@@ -906,6 +899,7 @@ def main():
906899 problems ,
907900 args .refresh ,
908901 args .dry_run ,
902+ terminal_columns ,
909903 )
910904
911905 if elapsed :
0 commit comments