|
import streamlit as st |
|
import subprocess |
|
|
|
|
|
st.set_page_config(page_title="Advanced Terminal Emulator", layout="wide") |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.output { |
|
background-color: #d4edda; /* Green background for output */ |
|
padding: 10px; |
|
border-radius: 5px; |
|
border: 1px solid #c3e6cb; |
|
} |
|
.error { |
|
background-color: #f8d7da; /* Red background for error */ |
|
padding: 10px; |
|
border-radius: 5px; |
|
border: 1px solid #f5c6cb; |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
st.title("🎨 Advanced Terminal Emulator") |
|
|
|
|
|
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. |
|
""") |
|
|
|
|
|
if 'history' not in st.session_state: |
|
st.session_state.history = [] |
|
|
|
|
|
def run_command(command): |
|
try: |
|
result = subprocess.run(command, shell=True, capture_output=True, text=True) |
|
if result.stdout: |
|
st.subheader("Output:") |
|
st.markdown(f'<div class="output">{result.stdout}</div>', unsafe_allow_html=True) |
|
if result.stderr: |
|
st.subheader("Error:") |
|
st.markdown(f'<div class="error">{result.stderr}</div>', unsafe_allow_html=True) |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
|
|
|
|
col1, col2 = st.columns([2, 1]) |
|
|
|
|
|
with col1: |
|
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) |
|
|
|
if command not in st.session_state.history: |
|
st.session_state.history.append(command) |
|
else: |
|
st.warning("Please enter a command to run.") |
|
|
|
|
|
with col2: |
|
st.subheader("Command History") |
|
for cmd in reversed(st.session_state.history): |
|
if st.button(f"Run: {cmd}", key=cmd): |
|
run_command(cmd) |
|
|
|
|
|
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) |
|
|
|
|
|
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. |
|
""") |
|
|