Spaces:
Sleeping
Sleeping
File size: 1,506 Bytes
aba525f | 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 | # code_editor.py
import streamlit as st
import streamlit_ace as st_ace
from utils import execute_code
def render_code_editor(selected_lang, ace_theme, editor_key, default_snippet):
st.subheader("Editor")
code = st_ace.st_ace(
value=st.session_state.code,
placeholder=f"Start typing your {selected_lang} code…",
language=selected_lang.lower() if selected_lang != "C++" else "c_cpp",
theme=ace_theme,
keybinding="vscode",
font_size=14,
min_lines=20,
show_gutter=True,
wrap=True,
auto_update=True,
key=editor_key
)
if code != st.session_state.code:
st.session_state.code = code
user_input = st.text_area(
label="📥 Input (stdin)",
value=st.session_state.stdin,
placeholder="Enter input() values here, one per line",
height=100,
key="stdin_input"
)
if user_input != st.session_state.stdin:
st.session_state.stdin = user_input
if st.button("▶️ Run"):
out, err, exc = execute_code(
code=st.session_state.code,
stdin=st.session_state.stdin,
language=selected_lang
)
st.session_state.code_output = out
st.session_state.error_output = err or exc
if st.session_state.get("code_output"):
st.text_area("Output", st.session_state.code_output, height=120)
if st.session_state.get("error_output"):
st.error(st.session_state.error_output)
|