提交 2a4f7b37 编写于 作者: W weixin_41863029

Fri Dec 1 16:01:00 CST 2023 inscode

上级 0520122c
import streamlit as st
from streamlit_option_menu import option_menu
import subprocess
# 设置Streamlit应用程序的标题
st.set_page_config(page_title="app name", layout="wide")
st.title("Online Rust Compiler")
menu1="菜单1"
menu2="菜单2"
code = st.text_area("Write your rust code here", height=300)
with st.sidebar:
menu = option_menu("菜单", [menu1, menu2],
icons=['house', "list-task"],
menu_icon="cast", default_index=0)
if st.button("Run"):
st.write("Compiling and Running...")
def main():
with open("main.rs", "w") as f:
f.write(code)
if menu == menu1:
st.subheader(f"{menu1}")
compile_process = subprocess.Popen("rustc main.rs", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
compile_result = compile_process.communicate()
if menu == menu2:
st.subheader(f"{menu2}")
if compile_result[1]:
st.write("Compilation Error:")
st.error(compile_result[1].decode())
else:
try:
run_process = subprocess.run("./main", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, timeout=10)
except subprocess.TimeoutExpired:
st.write("Time Limit Exceeded!")
st.error("Program execution time exceeded 10 seconds.")
exit(0)
finally:
with open("main.rs", "r") as f:
code_output = f.read()
if __name__ == '__main__':
main()
st.write("Original Rust Code:")
st.code(code_output, language="rust")
if run_process.stderr:
st.write("Standard Error:")
st.error(run_process.stderr.decode())
if run_process.stdout:
st.write("Standard Output:")
st.code(run_process.stdout.decode(), language="text")
\ No newline at end of file
fn main() {
println!("Hello, world!");
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册