1+ from rich .console import Console
2+ from rich .panel import Panel
3+ from rich .table import Table
4+ from rich .progress import Progress , BarColumn , TextColumn
5+ from rich import box
6+ from rich .text import Text
7+ from rich .columns import Columns
8+ import typer
9+
10+ console = Console ()
11+
12+ def display_auth_error ():
13+ """Display error message when not authenticated"""
14+ console .print (Panel ("❌ Please login first using the login command" ,
15+ style = "bold red" , border_style = "red" ))
16+ raise typer .Exit (1 )
17+
18+ def display_file_not_found_error (file ):
19+ """Display error message when file is not found"""
20+ console .print (Panel (f"❌ File not found: { file } " , style = "bold red" , border_style = "red" ))
21+ raise typer .Exit (1 )
22+
23+ def display_language_detection_message (lang ):
24+ """Display auto-detected language message"""
25+ console .print (f"🔍 Auto-detected language: [cyan]{ lang } [/]" )
26+
27+ def display_language_detection_error (extension ):
28+ """Display error message when language cannot be detected"""
29+ console .print (Panel (f"❌ Could not detect language for { extension } files. Please specify with --lang" ,
30+ style = "bold red" , border_style = "red" ))
31+ raise typer .Exit (1 )
32+
33+ def display_problem_not_found_error (problem ):
34+ """Display error message when problem is not found"""
35+ console .print (Panel (f"❌ Problem not found: { problem } " , style = "bold red" , border_style = "red" ))
36+ raise typer .Exit (1 )
37+
38+ def display_submission_details (problem , problem_name , lang , file ):
39+ """Display submission details and confirmation prompt using a clean layout"""
40+ # Create formatted text lines instead of a nested table
41+ content = [
42+ f"[cyan]Problem:[/] { problem } - { problem_name } " ,
43+ f"[cyan]Language:[/] { lang } " ,
44+ f"[cyan]File:[/] { str (file )} "
45+ ]
46+
47+ console .print (Panel (
48+ "\n " .join (content ),
49+ title = "Submission Details" ,
50+ border_style = "blue" ,
51+ box = box .ROUNDED
52+ ))
53+
54+ return typer .confirm ("Do you want to submit this solution?" )
55+
56+ def display_submission_canceled ():
57+ """Display submission canceled message"""
58+ console .print ("[yellow]Submission canceled[/]" )
59+ raise typer .Exit (0 )
60+
61+ def create_submission_progress ():
62+ """Create and return a submission progress context"""
63+ return Progress (
64+ TextColumn ("[bold yellow]Submitting solution..." , justify = "right" ),
65+ BarColumn (bar_width = 40 , style = "yellow" ),
66+ transient = True ,
67+ )
68+
69+ def display_submission_results (result ):
70+ """Display submission results with a cleaner layout"""
71+ if result ["success" ]:
72+ status = result ['status' ]
73+
74+ # Set colors based on status
75+ if status == "Accepted" :
76+ status_style = "bold green"
77+ border_style = "green"
78+ emoji = "✅"
79+ elif status in ["Runtime Error" , "Time Limit Exceeded" ]:
80+ status_style = "bold yellow"
81+ border_style = "yellow"
82+ emoji = "⚠️"
83+ else :
84+ status_style = "bold red"
85+ border_style = "red"
86+ emoji = "❌"
87+
88+ # Get metrics
89+ runtime = result .get ('runtime' , 'N/A' )
90+ memory = result .get ('memory' , 'N/A' )
91+ passed = result .get ('passed_testcases' , 0 )
92+ total = result .get ('total_testcases' , 0 )
93+ test_case_str = f"{ passed } /{ total } ({ passed / total * 100 :.1f} %)" if total > 0 else "N/A"
94+
95+ content = [
96+ f"[cyan]⏱️ Runtime:[/] { runtime } " ,
97+ f"[cyan]💾 Memory:[/] { memory } " ,
98+ f"[cyan]🧪 Test Cases:[/] { test_case_str } "
99+ ]
100+
101+ title = f"{ emoji } Submission Result: [{ status_style } ]{ status } [/]"
102+ console .print (Panel (
103+ "\n " .join (content ),
104+ title = title ,
105+ border_style = border_style ,
106+ box = box .ROUNDED
107+ ))
108+
109+ if status != "Accepted" and result .get ('error_message' ):
110+ error_msg = result .get ('error_message' , 'No details available' )
111+ console .print (Panel (error_msg , title = "Error Details" , border_style = "red" ))
112+ else :
113+ error_panel = Panel (
114+ f"{ result .get ('error' , 'Unknown error' )} " ,
115+ title = "❌ Submission Failed" ,
116+ border_style = "red"
117+ )
118+ console .print (error_panel )
119+
120+ def display_exception_error (e ):
121+ """Display exception error message"""
122+ console .print (Panel (f"❌ Error: { str (e )} " , style = "bold red" , border_style = "red" ))
123+ raise typer .Exit (1 )
0 commit comments