File size: 2,437 Bytes
8b49023
 
 
eec2447
 
8b49023
eec2447
 
 
 
475d256
eec2447
 
475d256
 
eec2447
 
8b49023
eec2447
 
475d256
eec2447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b49023
eec2447
8b49023
 
eec2447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b49023
475d256
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
81
82
83
84
import streamlit as st
import subprocess

# Set the page layout to wide mode for a cleaner look
st.set_page_config(page_title="Terminal Command Executor", layout="centered")

# Main title with emojis for visual appeal
st.title("🚀 Run Terminal Commands Easily")

# Brief description to guide the user
st.markdown("""
### Simple and intuitive tool to execute terminal commands directly from this interface.
Just enter a command, hit the button, and see the output below.
""")

# Create a larger and clearer input field with a placeholder
command = st.text_input("💻 Enter a terminal command", placeholder="e.g., ls, pwd, echo Hello World", max_chars=100)

# Button to run the command
run_button = st.button("Run Command")

# Display the output when the command is executed
if run_button and command:
    with st.spinner("Running command..."):
        try:
            # Run the terminal command and capture output
            result = subprocess.run(command, shell=True, capture_output=True, text=True)
            
            # Display success message and output
            st.success("✅ Command executed successfully!")
            st.code(result.stdout, language="bash")
            
            # Display any errors in red
            if result.stderr:
                st.error(f"⚠️ Error:\n{result.stderr}")
        except Exception as e:
            st.error(f"❌ Failed to run command: {e}")
else:
    if run_button:
        st.warning("⚠️ Please enter a command.")

# Custom CSS to simplify and style the UI
st.markdown("""
    <style>
    /* Hide footer */
    footer {visibility: hidden;}

    /* Increase input box size and font */
    .stTextInput input {
        font-size: 16px;
        height: 50px;
        width: 100%;
        padding: 10px;
        border-radius: 5px;
        border: 1px solid #3498db;
        background-color: #f0f4f8;
        color: #333;
    }

    /* Customize button */
    .stButton button {
        background-color: #3498db;
        color: white;
        font-size: 16px;
        padding: 8px 16px;
        border-radius: 5px;
        border: none;
    }

    /* Set the success and warning messages to look cleaner */
    .stAlert {
        font-size: 15px;
    }

    /* Customize code display */
    .stCodeBlock {
        background-color: #2c3e50;
        color: #ecf0f1;
        padding: 10px;
        border-radius: 5px;
    }
    </style>
""", unsafe_allow_html=True)