File size: 3,282 Bytes
8b49023 509b59f 8b49023 4eb488d 1941bd7 4eb488d 1941bd7 4eb488d 1941bd7 4eb488d 1941bd7 4eb488d 1941bd7 720e97a 509b59f 00de18e 509b59f 00de18e 509b59f b67a2d6 509b59f b67a2d6 b05f987 00de18e b67a2d6 509b59f 00de18e 36d9343 00de18e 509b59f |
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 |
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("""
<style>
.output {
background-color: rgba(76, 175, 80, 0.2); /* Light green with transparency for output */
padding: 10px;
border-radius: 5px;
border: 1px solid rgba(76, 175, 80, 0.5); /* Semi-transparent green border */
}
.error {
background-color: rgba(244, 67, 54, 0.2); /* Light red with transparency for error */
padding: 10px;
border-radius: 5px;
border: 1px solid rgba(244, 67, 54, 0.5); /* Semi-transparent red border */
}
</style>
""", 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'<div class="output">{st.session_state.output}</div>', unsafe_allow_html=True)
if 'error' in st.session_state and st.session_state.error:
st.markdown(f'<div class="error">{st.session_state.error}</div>', unsafe_allow_html=True)
# Optional file upload (if needed)
uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])
if uploaded_file:
file_content = uploaded_file.read().decode("utf-8")
st.subheader("Uploaded File Content")
st.text_area("File Content", value=file_content, height=200)
# Footer with additional information
st.markdown("""
---
**Note:** This is a simple terminal emulator built with Streamlit. Use it for running commands and managing outputs efficiently. For advanced usage, consider additional functionalities.
""")
|