File size: 2,725 Bytes
8b49023 c96c151 8b49023 c96c151 1941bd7 c96c151 509b59f c96c151 00d5f7a 509b59f c96c151 509b59f c96c151 509b59f 110ec43 509b59f c96c151 110ec43 c96c151 33402fc c96c151 |
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 |
import streamlit as st
import subprocess
# Sidebar for user instructions and input
st.sidebar.title("Terminal Command Runner")
st.sidebar.write("Enter a terminal command below, and click the **Run Command** button to execute it.")
# Main page layout
st.title("๐ Terminal Command Executor")
st.markdown("""
This tool allows you to run terminal commands directly from the web interface.
Enter a command in the input field, and the output will be displayed below.
""")
# Create a user-friendly input field with a placeholder and description
command = st.text_area("๐ป Enter a terminal command:", placeholder="e.g., ls, pwd, echo Hello World")
# Create a button to execute the command
if st.button("Run Command"):
if command:
with st.spinner("Running the command..."):
try:
# Execute the terminal command and capture the output
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Display the output in the Streamlit app
st.subheader("๐ Command Output:")
st.code(result.stdout, language="bash")
# Display errors, if any
if result.stderr:
st.error(f"โ ๏ธ Error:\n{result.stderr}")
except Exception as e:
st.error(f"โ Error running command: {e}")
else:
st.warning("โ ๏ธ Please enter a command to run.")
# Display additional tips in the sidebar
st.sidebar.header("Quick Tips")
st.sidebar.write("""
- To list files: `ls`
- To show current directory: `pwd`
- To display system info: `uname -a`
- To print something: `echo "Hello"`
""")
# Custom CSS for button styling
st.markdown("""
<style>
footer {visibility: hidden;}
.css-18e3th9 {background-color: #34495e;}
h1 {color: #3498db;}
.stTextInput input {
border: 1px solid #2980b9;
background-color: #ecf0f1;
}
.stButton button {
background-color: #27ae60;
color: white;
font-size: 16px;
}
.stButton button:hover {
background-color: red; /* Button background color on hover */
color: white; /* Text color remains white on hover */
}
.stMarkdown h2, .stMarkdown h3 {
color: #2ecc71;
}
.stTextArea textarea {
border-color: #3498db;
}
.css-qbe2hs {
color: #f1c40f;
}
</style>
""", unsafe_allow_html=True)
# Custom footer text for a user-friendly experience
st.markdown("๐ก **Tip**: Use simple commands and see the output instantly. Happy hacking!")
|