emulate the CMD interface
To upload files, please first save the app
import streamlit as st
import datetime
# Configure page
st.set_page_config(page_title="CMD Interface", layout="wide")
# Custom CSS for CMD-like interface
st.markdown("""
<style>
.stTextInput input {
background-color: black;
color: #00ff00;
font-family: 'Courier New', Courier, monospace;
border: none;
padding: 10px;
}
.output-text {
background-color: black;
color: #00ff00;
font-family: 'Courier New', Courier, monospace;
padding: 10px;
border: none;
min-height: 400px;
}
</style>
""", unsafe_allow_html=True)
# Initialize session state
if 'command_history' not in st.session_state:
st.session_state.command_history = []
# Title
st.markdown("<h1 style='color: #00ff00; font-family: Courier New'>Command Prompt Emulator</h1>", unsafe_allow_html=True)
# Command input
command = st.text_input("C:\\>", key="command_input")
# Process command
if command:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
st.session_state.command_history.append(f"[{timestamp}] C:\\> {command}")
# Basic command processing
if command.lower() == "help":
st.session_state.command_history.append("""
Available commands:
- help: Display this help message
- clear: Clear the screen
- time: Display current time
- echo [text]: Display text
- dir: List directory contents (simulated)
""")
elif command.lower() == "clear":
st.session_state.command_history = []
elif command.lower() == "time":
st.session_state.command_history.append(f"Current time: {datetime.datetime.now().strftime('%H:%M:%S')}")
elif command.lower().startswith("echo "):
st.session_state.command_history.append(command[5:])
elif command.lower() == "dir":
st.session_state.command_history.append("""
Directory of C:\\
12/01/2023 10:00 <DIR> Program Files
12/01/2023 10:00 <DIR> Users
12/01/2023 10:00 <DIR> Windows
0 File(s) 0 bytes
3 Dir(s) 100,000,000,000 bytes free
""")
else:
st.session_state.command_history.append(f"'{command}' is not recognized as an internal or external command")
# Display output
output = "\n".join(st.session_state.command_history)
st.markdown(f"""
<div class="output-text">
<pre>{output}</pre>
</div>
""", unsafe_allow_html=True)
# Instructions
with st.expander("Instructions"):
st.markdown("""
This is a simple Command Prompt emulator. Available commands:
- `help`: Display available commands
- `clear`: Clear the screen
- `time`: Display current time
- `echo [text]`: Display text
- `dir`: Show simulated directory listing
Press Enter after typing a command to execute it.
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?