Update app.py
Browse files
app.py
CHANGED
@@ -1,79 +1,83 @@
|
|
1 |
import streamlit as st
|
2 |
import subprocess
|
3 |
|
4 |
-
#
|
5 |
-
st.
|
6 |
-
st.sidebar.write("Enter a terminal command below, and click the **Run Command** button to execute it.")
|
7 |
|
8 |
-
# Main
|
9 |
-
st.title("๐ Terminal
|
|
|
|
|
10 |
st.markdown("""
|
11 |
-
|
12 |
-
|
13 |
""")
|
14 |
|
15 |
-
# Create a larger input field with
|
16 |
-
command = st.text_input("๐ป Enter a terminal command
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
if command:
|
21 |
-
with st.spinner("Running the command..."):
|
22 |
-
try:
|
23 |
-
# Execute the terminal command and capture the output
|
24 |
-
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
25 |
-
|
26 |
-
# Display the output in the Streamlit app
|
27 |
-
st.success("Command executed successfully!")
|
28 |
-
st.subheader("๐ Command Output:")
|
29 |
-
st.code(result.stdout, language="bash")
|
30 |
-
|
31 |
-
# Display errors, if any
|
32 |
-
if result.stderr:
|
33 |
-
st.error(f"โ ๏ธ Error:\n{result.stderr}")
|
34 |
-
except Exception as e:
|
35 |
-
st.error(f"โ Error running command: {e}")
|
36 |
-
else:
|
37 |
-
st.warning("โ ๏ธ Please enter a command to run.")
|
38 |
|
39 |
-
# Display
|
40 |
-
|
41 |
-
st.
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
#
|
49 |
st.markdown("""
|
50 |
<style>
|
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 |
</style>
|
76 |
""", unsafe_allow_html=True)
|
77 |
-
|
78 |
-
# Custom footer text for a user-friendly experience
|
79 |
-
st.markdown("๐ก **Tip**: Use simple commands and see the output instantly. Happy hacking!")
|
|
|
1 |
import streamlit as st
|
2 |
import subprocess
|
3 |
|
4 |
+
# Set the page layout to wide mode for a cleaner look
|
5 |
+
st.set_page_config(page_title="Terminal Command Executor", layout="centered")
|
|
|
6 |
|
7 |
+
# Main title with emojis for visual appeal
|
8 |
+
st.title("๐ Run Terminal Commands Easily")
|
9 |
+
|
10 |
+
# Brief description to guide the user
|
11 |
st.markdown("""
|
12 |
+
### Simple and intuitive tool to execute terminal commands directly from this interface.
|
13 |
+
Just enter a command, hit the button, and see the output below.
|
14 |
""")
|
15 |
|
16 |
+
# Create a larger and clearer input field with a placeholder
|
17 |
+
command = st.text_input("๐ป Enter a terminal command", placeholder="e.g., ls, pwd, echo Hello World", max_chars=100)
|
18 |
|
19 |
+
# Button to run the command
|
20 |
+
run_button = st.button("Run Command")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
# Display the output when the command is executed
|
23 |
+
if run_button and command:
|
24 |
+
with st.spinner("Running command..."):
|
25 |
+
try:
|
26 |
+
# Run the terminal command and capture output
|
27 |
+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
28 |
+
|
29 |
+
# Display success message and output
|
30 |
+
st.success("โ
Command executed successfully!")
|
31 |
+
st.code(result.stdout, language="bash")
|
32 |
+
|
33 |
+
# Display any errors in red
|
34 |
+
if result.stderr:
|
35 |
+
st.error(f"โ ๏ธ Error:\n{result.stderr}")
|
36 |
+
except Exception as e:
|
37 |
+
st.error(f"โ Failed to run command: {e}")
|
38 |
+
else:
|
39 |
+
if run_button:
|
40 |
+
st.warning("โ ๏ธ Please enter a command.")
|
41 |
|
42 |
+
# Custom CSS to simplify and style the UI
|
43 |
st.markdown("""
|
44 |
<style>
|
45 |
+
/* Hide footer */
|
46 |
+
footer {visibility: hidden;}
|
47 |
+
|
48 |
+
/* Increase input box size and font */
|
49 |
+
.stTextInput input {
|
50 |
+
font-size: 16px;
|
51 |
+
height: 50px;
|
52 |
+
width: 100%;
|
53 |
+
padding: 10px;
|
54 |
+
border-radius: 5px;
|
55 |
+
border: 1px solid #3498db;
|
56 |
+
background-color: #f0f4f8;
|
57 |
+
color: #333;
|
58 |
+
}
|
59 |
+
|
60 |
+
/* Customize button */
|
61 |
+
.stButton button {
|
62 |
+
background-color: #3498db;
|
63 |
+
color: white;
|
64 |
+
font-size: 16px;
|
65 |
+
padding: 8px 16px;
|
66 |
+
border-radius: 5px;
|
67 |
+
border: none;
|
68 |
+
}
|
69 |
+
|
70 |
+
/* Set the success and warning messages to look cleaner */
|
71 |
+
.stAlert {
|
72 |
+
font-size: 15px;
|
73 |
+
}
|
74 |
+
|
75 |
+
/* Customize code display */
|
76 |
+
.stCodeBlock {
|
77 |
+
background-color: #2c3e50;
|
78 |
+
color: #ecf0f1;
|
79 |
+
padding: 10px;
|
80 |
+
border-radius: 5px;
|
81 |
+
}
|
82 |
</style>
|
83 |
""", unsafe_allow_html=True)
|
|
|
|
|
|