import streamlit as st import subprocess # Set page configuration st.set_page_config(page_title="Advanced Terminal Emulator", layout="wide") # Custom CSS for output and error background colors with transparency st.markdown(""" """, unsafe_allow_html=True) # Main title st.title("🎨 Advanced Terminal Emulator") # Instructions and description st.markdown(""" This enhanced terminal emulator lets you run commands and view outputs in a clean and modern interface. You can access previous commands and see results in a well-organized manner. """) # Command history management if 'history' not in st.session_state: st.session_state.history = [] # Function to run the command and capture output def run_command(command): try: result = subprocess.run(command, shell=True, capture_output=True, text=True) st.session_state.output = result.stdout st.session_state.error = result.stderr except Exception as e: st.session_state.error = str(e) st.session_state.output = None # Layout with three columns col1, col2, col3 = st.columns([1, 2, 1]) # Command history display in the first column with col1: st.subheader("Command History") for cmd in reversed(st.session_state.history): if st.button(f"Run: {cmd}", key=cmd): run_command(cmd) # Command input in the second column with col2: command = st.text_area("Enter terminal command", placeholder="e.g., ls, pwd, echo 'Hello World'", height=100) if st.button("Run Command"): if command: run_command(command) # Add to command history if command not in st.session_state.history: st.session_state.history.append(command) else: st.warning("Please enter a command to run.") # Output display in the third column with col3: st.subheader("Output:") if 'output' in st.session_state and st.session_state.output: st.markdown(f'