skanaujiya commited on
Commit
509b59f
·
verified ·
1 Parent(s): d0ee7b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -30
app.py CHANGED
@@ -1,35 +1,66 @@
1
  import streamlit as st
2
  import subprocess
3
 
4
- # Set the page layout to wide mode for better spacing
5
- st.set_page_config(page_title="Terminal Command Executor", layout="centered")
6
 
7
  # Main title
8
- st.title("🖥️ Simple Terminal Emulator")
9
-
10
- # Instruction text
11
- st.write("Enter a command and see the result below. This works just like your terminal!")
12
-
13
- # Input field for terminal command
14
- command = st.text_area("Enter terminal command")
15
-
16
- # Button to run the command
17
- if st.button("Run Command"):
18
- if command:
19
- try:
20
- # Execute the terminal command and capture the output
21
- result = subprocess.run(command, shell=True, capture_output=True, text=True)
22
-
23
- # Show the output
24
- if result.stdout:
25
- st.subheader("Output:")
26
- st.code(result.stdout)
27
-
28
- # Show any errors if they occur
29
- if result.stderr:
30
- st.subheader("Error:")
31
- st.code(result.stderr)
32
- except Exception as e:
33
- st.error(f"An error occurred: {e}")
34
- else:
35
- st.warning("Please enter a command to run.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """)