File size: 3,427 Bytes
f66144d
 
 
3934d18
 
 
 
 
 
b036d44
 
99f1fce
 
3934d18
b036d44
99f1fce
3934d18
b036d44
 
 
3934d18
b036d44
 
3934d18
99f1fce
b036d44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3934d18
 
67a88a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3934d18
 
 
67a88a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import streamlit as st

def init_session_state():
    if "dark_mode" not in st.session_state:
        st.session_state.dark_mode = False
    if "code" not in st.session_state:
        st.session_state.code = ""
    if "stdin" not in st.session_state:
        st.session_state.stdin = ""
    if "language" not in st.session_state:
        st.session_state.language = "Python"  # Default


def apply_theme():
    dark = st.session_state.dark_mode

    colors = {
        "bg": "#0f1620" if dark else "#f5f5f5",
        "panel_bg": "#1c2330" if dark else "#ffffff",
        "text": "#e3e8f1" if dark else "#1a1a1a",
        "accent": "#ff5252",
        "border": "#2a3240" if dark else "#dddddd",
        "shadow": "rgba(0,0,0,0.3)" if dark else "rgba(0,0,0,0.1)",
    }

    # Map selected language to Ace supported values
    language = st.session_state.get("language", "python").lower()
    if language == "c++":
        language = "c_cpp"
    elif language == "c#":
        language = "csharp"
    elif language == "javascript":
        language = "javascript"
    elif language == "python":
        language = "python"
    elif language == "java":
        language = "java"
    elif language == "c":
        language = "c"

    ace_theme = "monokai" if dark else "chrome"

    # Inject CSS styles
    st.markdown(
        f"""
        <style>
        .stApp {{
            background-color: {colors["bg"]};
            color: {colors["text"]};
        }}
        [data-testid="stSidebar"] {{
            background-color: {colors["panel_bg"]} !important;
        }}
        .ace_editor, .ace_scroller {{
            background: {colors["panel_bg"]} !important;
            box-shadow: 0 4px 8px {colors["shadow"]} !important;
            border-radius: 8px !important;
        }}
        textarea, input, .stTextArea textarea {{
            background: {colors["panel_bg"]} !important;
            color: {colors["text"]} !important;
            border: 1px solid {colors["border"]} !important;
            border-radius: 4px !important;
        }}
        label, .stTextLabel, .stTextArea label {{
            color: {colors["text"]} !important;
        }}
        button, .stDownloadButton > button {{
            background-color: {colors["accent"]} !important;
            color: #fff !important;
            border-radius: 6px !important;
            transition: transform 0.1s;
        }}
        button:hover {{
            transform: scale(1.02) !important;
        }}
        .chat-container {{
            background: {colors["panel_bg"]} !important;
            border: 1px solid {colors["border"]} !important;
            border-radius: 8px !important;
            padding: 1rem;
            max-height: 480px;
            overflow-y: auto;
        }}
        .chat-message {{
            margin-bottom: 1rem;
            padding: 0.75rem 1rem;
            border-radius: 12px;
        }}
        .user-message {{
            background: rgba(100,149,237,0.2);
            align-self: flex-end;
        }}
        .bot-message {{
            background: rgba(200,200,200,0.2);
            align-self: flex-start;
        }}
        pre code {{
            display: block;
            padding: 0.5rem;
            background: rgba(0,0,0,0.1);
            border-radius: 4px;
            overflow-x: auto;
        }}
        </style>
        """,
        unsafe_allow_html=True,
    )

    return colors, ace_theme