Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,66 @@
|
|
1 |
import streamlit as st
|
2 |
import subprocess
|
3 |
|
4 |
-
# Set
|
5 |
-
st.set_page_config(page_title="Terminal
|
6 |
|
7 |
# Main title
|
8 |
-
st.title("
|
9 |
-
|
10 |
-
#
|
11 |
-
st.
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
#
|
17 |
-
if st.
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import subprocess
|
3 |
|
4 |
+
# Set page configuration
|
5 |
+
st.set_page_config(page_title="Advanced Terminal Emulator", layout="wide")
|
6 |
|
7 |
# Main title
|
8 |
+
st.title("🎨 Advanced Terminal Emulator")
|
9 |
+
|
10 |
+
# Instructions and description
|
11 |
+
st.markdown("""
|
12 |
+
This enhanced terminal emulator lets you run commands and view outputs in a clean and modern interface.
|
13 |
+
You can access previous commands and see results in a well-organized manner.
|
14 |
+
""")
|
15 |
+
|
16 |
+
# Command history management
|
17 |
+
if 'history' not in st.session_state:
|
18 |
+
st.session_state.history = []
|
19 |
+
|
20 |
+
# Function to run the command and capture output
|
21 |
+
def run_command(command):
|
22 |
+
try:
|
23 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
24 |
+
if result.stdout:
|
25 |
+
st.subheader("Output:")
|
26 |
+
st.code(result.stdout)
|
27 |
+
if result.stderr:
|
28 |
+
st.subheader("Error:")
|
29 |
+
st.code(result.stderr)
|
30 |
+
except Exception as e:
|
31 |
+
st.error(f"An error occurred: {e}")
|
32 |
+
|
33 |
+
# Layout with columns
|
34 |
+
col1, col2 = st.columns([2, 1])
|
35 |
+
|
36 |
+
# Command input and button in the first column
|
37 |
+
with col1:
|
38 |
+
command = st.text_area("Enter terminal command", placeholder="e.g., ls, pwd, echo 'Hello World'", height=100)
|
39 |
+
if st.button("Run Command"):
|
40 |
+
if command:
|
41 |
+
run_command(command)
|
42 |
+
# Add to command history
|
43 |
+
if command not in st.session_state.history:
|
44 |
+
st.session_state.history.append(command)
|
45 |
+
else:
|
46 |
+
st.warning("Please enter a command to run.")
|
47 |
+
|
48 |
+
# Command history display in the second column
|
49 |
+
with col2:
|
50 |
+
st.subheader("Command History")
|
51 |
+
for cmd in reversed(st.session_state.history):
|
52 |
+
if st.button(f"Run: {cmd}", key=cmd):
|
53 |
+
run_command(cmd)
|
54 |
+
|
55 |
+
# Optional file upload (if needed)
|
56 |
+
uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])
|
57 |
+
if uploaded_file:
|
58 |
+
file_content = uploaded_file.read().decode("utf-8")
|
59 |
+
st.subheader("Uploaded File Content")
|
60 |
+
st.text_area("File Content", value=file_content, height=200)
|
61 |
+
|
62 |
+
# Footer with additional information
|
63 |
+
st.markdown("""
|
64 |
+
---
|
65 |
+
**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.
|
66 |
+
""")
|