skanaujiya commited on
Commit
c96c151
·
verified ·
1 Parent(s): 0682a81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -73
app.py CHANGED
@@ -1,84 +1,76 @@
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
- # Custom CSS for output and error background colors with transparency
 
8
  st.markdown("""
9
- <style>
10
- .output {
11
- background-color: rgba(76, 175, 80, 0.2); /* Light green with transparency for output */
12
- padding: 10px;
13
- border-radius: 5px;
14
- border: 1px solid rgba(76, 175, 80, 0.5); /* Semi-transparent green border */
15
- }
16
- .error {
17
- background-color: rgba(244, 67, 54, 0.2); /* Light red with transparency for error */
18
- padding: 10px;
19
- border-radius: 5px;
20
- border: 1px solid rgba(244, 67, 54, 0.5); /* Semi-transparent red border */
21
- }
22
- </style>
23
- """, unsafe_allow_html=True)
24
-
25
- # Main title
26
- st.title("🎨 Advanced Terminal Emulator")
27
-
28
- # Instructions and description
29
- st.markdown("""
30
- This enhanced terminal emulator lets you run commands and view outputs in a clean and modern interface.
31
- You can access previous commands and see results in a well-organized manner.
32
  """)
33
 
34
- # Command history management
35
- if 'history' not in st.session_state:
36
- st.session_state.history = []
37
-
38
- # Function to run the command and capture output
39
- def run_command(command):
40
- try:
41
- result = subprocess.run(command, shell=True, capture_output=True, text=True)
42
- if result.stdout:
43
- st.subheader("Output:")
44
- st.markdown(f'<div class="output">{result.stdout}</div>', unsafe_allow_html=True)
45
- if result.stderr:
46
- st.subheader("Error:")
47
- st.markdown(f'<div class="error">{result.stderr}</div>', unsafe_allow_html=True)
48
- except Exception as e:
49
- st.error(f"An error occurred: {e}")
50
-
51
- # Layout with columns
52
- col1, col2 = st.columns([2, 1])
53
 
54
- # Command input and button in the first column
55
- with col1:
56
- command = st.text_area("Enter terminal command", placeholder="e.g., ls, pwd, echo 'Hello World'", height=100)
57
- if st.button("Run Command"):
58
- if command:
59
- run_command(command)
60
- # Add to command history
61
- if command not in st.session_state.history:
62
- st.session_state.history.append(command)
63
- else:
64
- st.warning("Please enter a command to run.")
 
 
 
 
 
 
 
 
 
65
 
66
- # Command history display in the second column
67
- with col2:
68
- st.subheader("Command History")
69
- for cmd in reversed(st.session_state.history):
70
- if st.button(f"Run: {cmd}", key=cmd):
71
- run_command(cmd)
72
-
73
- # Optional file upload (if needed)
74
- uploaded_file = st.file_uploader("Upload a file to process with command:", type=["txt", "csv"])
75
- if uploaded_file:
76
- file_content = uploaded_file.read().decode("utf-8")
77
- st.subheader("Uploaded File Content")
78
- st.text_area("File Content", value=file_content, height=200)
79
 
80
- # Footer with additional information
81
  st.markdown("""
82
- ---
83
- **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.
84
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import subprocess
3
 
4
+ # Sidebar for user instructions and input
5
+ st.sidebar.title("Terminal Command Runner")
6
+ st.sidebar.write("Enter a terminal command below, and click the **Run Command** button to execute it.")
7
 
8
+ # Main page layout
9
+ st.title("🚀 Terminal Command Executor")
10
  st.markdown("""
11
+ This tool allows you to run terminal commands directly from the web interface.
12
+ Enter a command in the input field, and the output will be displayed below.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  """)
14
 
15
+ # Create a user-friendly input field with a placeholder and description
16
+ command = st.text_input("💻 Enter a terminal command:", placeholder="e.g., ls, pwd, echo Hello World")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ # Create a button to execute the command
19
+ if st.button("Run Command"):
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 additional tips in the sidebar
40
+ st.sidebar.header("Quick Tips")
41
+ st.sidebar.write("""
42
+ - To list files: `ls`
43
+ - To show current directory: `pwd`
44
+ - To display system info: `uname -a`
45
+ - To print something: `echo "Hello"`
46
+ """)
 
 
 
 
 
47
 
48
+ # A footer for better UI and personalized touch
49
  st.markdown("""
50
+ <style>
51
+ footer {visibility: hidden;}
52
+ .css-18e3th9 {background-color: #34495e;}
53
+ h1 {color: #3498db;}
54
+ .stTextInput input {
55
+ border: 1px solid #2980b9;
56
+ background-color: #ecf0f1;
57
+ }
58
+ .stButton button {
59
+ background-color: #27ae60;
60
+ color: white;
61
+ font-size: 16px;
62
+ }
63
+ .stMarkdown h2, .stMarkdown h3 {
64
+ color: #2ecc71;
65
+ }
66
+ .stTextArea textarea {
67
+ border-color: #3498db;
68
+ }
69
+ .css-qbe2hs {
70
+ color: #f1c40f;
71
+ }
72
+ </style>
73
+ """, unsafe_allow_html=True)
74
+
75
+ # Custom footer text for a user-friendly experience
76
+ st.markdown("💡 **Tip**: Use simple commands and see the output instantly. Happy hacking!")