@@ -4,9 +4,11 @@ import { useEditor } from '@/client/store/editor';
4
4
import { useEditorOptions } from '@/client/store/editor-options' ;
5
5
import { api } from '@/client/trpc' ;
6
6
import { Button } from '@/components/ui/button' ;
7
+ import { ScrollArea , ScrollBar } from '@/components/ui/scroll-area' ;
7
8
import { Skeleton } from '@/components/ui/skeleton' ;
8
9
import { Textarea } from '@/components/ui/textarea' ;
9
10
import { languageOptions } from '@/constants/app' ;
11
+ import { cn } from '@/lib/utils/cn' ;
10
12
import Editor from '@monaco-editor/react' ;
11
13
import { CSSProperties } from 'react' ;
12
14
import { toast } from 'sonner' ;
@@ -63,10 +65,27 @@ function CodeEditorLoading() {
63
65
export function CodeOutput ( ) {
64
66
const output = useEditor ( ( state ) => state . output ) ;
65
67
66
- // Change the theme depending of the error state
68
+ function getOutput ( ) {
69
+ if ( ! output . status ) return { className : '' , val : null } ;
70
+
71
+ const { id } = output . status ;
72
+ // Compilation Error
73
+ if ( id === 6 ) return { className : 'text-red-500' , val : output . compile_output ? atob ( output . compile_output ) : null } ;
74
+
75
+ // Accepted
76
+ if ( id === 3 ) return { className : 'text-green-500' , val : output . stdout ? atob ( output . stdout ) : null } ;
77
+
78
+ // Time limit exceeded
79
+ if ( id === 5 ) return { className : 'text-red-500' , val : 'Time Limit Exceeded' } ;
80
+
81
+ return { className : 'text-red-500' , val : output . stderr ? atob ( output . stderr ) : null } ;
82
+ }
67
83
68
84
return (
69
- < pre className = 'bg-muted rounded-lg my-2 p-3 text-sm min-h-56 text-muted-foreground' > { output . stdout ? atob ( output . stdout ) : 'Output panel' } </ pre >
85
+ < ScrollArea className = 'bg-muted h-56 rounded-lg py-2 my-2' >
86
+ < pre className = { cn ( 'px-3 text-sm text-muted-foreground' , getOutput ( ) ?. className ) } > { getOutput ( ) ?. val } </ pre >
87
+ < ScrollBar className = 'px-3' scrollAreaThumbClassname = 'bg-muted-foreground/30' orientation = 'horizontal' />
88
+ </ ScrollArea >
70
89
) ;
71
90
}
72
91
0 commit comments