ayoubghilmi commited on
Commit
2cad0aa
·
verified ·
1 Parent(s): 7f09f87

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +637 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Ayoub Edit Code
3
- emoji: 🏃
4
- colorFrom: blue
5
- colorTo: indigo
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: ayoub-edit-code
3
+ emoji: 🐳
4
+ colorFrom: green
5
+ colorTo: blue
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,637 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>PyWeb - Online Python Editor</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
10
+ <style>
11
+ .editor-container {
12
+ }
13
+ .editor {
14
+ height: 100%;
15
+ font-size: 14px;
16
+ line-height: 1.5;
17
+ tab-size: 4;
18
+ }
19
+ .output {
20
+ height: 100%;
21
+ overflow-y: auto;
22
+ white-space: pre-wrap;
23
+ background-color: #1e1e1e;
24
+ color: #d4d4d4;
25
+ font-family: 'Courier New', monospace;
26
+ padding: 10px;
27
+ }
28
+ .sidebar {
29
+ transition: all 0.3s ease;
30
+ }
31
+ .sidebar.collapsed {
32
+ width: 50px;
33
+ }
34
+ .sidebar-item {
35
+ transition: all 0.2s ease;
36
+ }
37
+ .sidebar-item:hover {
38
+ background-color: rgba(255, 255, 255, 0.1);
39
+ }
40
+ .tab {
41
+ transition: all 0.2s ease;
42
+ }
43
+ .tab.active {
44
+ border-bottom: 2px solid #3b82f6;
45
+ }
46
+ .autocomplete-list {
47
+ position: absolute;
48
+ background: #2d2d2d;
49
+ border: 1px solid #444;
50
+ max-height: 200px;
51
+ overflow-y: auto;
52
+ z-index: 100;
53
+ width: 200px;
54
+ }
55
+ .autocomplete-item {
56
+ padding: 5px 10px;
57
+ cursor: pointer;
58
+ }
59
+ .autocomplete-item:hover {
60
+ background-color: #3b82f6;
61
+ }
62
+ .line-numbers {
63
+ background-color: #1e1e1e;
64
+ color: #858585;
65
+ text-align: right;
66
+ padding-right: 10px;
67
+ user-select: none;
68
+ }
69
+ .python-keyword {
70
+ color: #569cd6;
71
+ }
72
+ .python-string {
73
+ color: #ce9178;
74
+ }
75
+ .python-comment {
76
+ color: #6a9955;
77
+ }
78
+ .python-function {
79
+ color: #dcdcaa;
80
+ }
81
+ .python-number {
82
+ color: #b5cea8;
83
+ }
84
+ .terminal {
85
+ height: 100%;
86
+ background-color: #1e1e1e;
87
+ color: #d4d4d4;
88
+ font-family: 'Courier New', monospace;
89
+ padding: 10px;
90
+ overflow-y: auto;
91
+ }
92
+ .terminal-input {
93
+ background-color: transparent;
94
+ border: none;
95
+ outline: none;
96
+ color: #d4d4d4;
97
+ font-family: 'Courier New', monospace;
98
+ width: 90%;
99
+ }
100
+ .terminal-prompt {
101
+ color: #4CAF50;
102
+ }
103
+ .terminal-cursor {
104
+ display: inline-block;
105
+ width: 10px;
106
+ height: 15px;
107
+ background-color: #d4d4d4;
108
+ animation: blink 1s infinite;
109
+ }
110
+ @keyframes blink {
111
+ 0%, 100% { opacity: 1; }
112
+ 50% { opacity: 0; }
113
+ }
114
+ .terminal-output {
115
+ margin-bottom: 10px;
116
+ white-space: pre-wrap;
117
+ }
118
+ </style>
119
+ </head>
120
+ <body class="bg-gray-900 text-white">
121
+ <div class="flex flex-col h-screen">
122
+ <!-- Top Navigation -->
123
+ <div class="bg-gray-800 px-4 py-2 flex items-center justify-between border-b border-gray-700">
124
+ <div class="flex items-center space-x-4">
125
+ <div class="flex items-center">
126
+ <i class="fab fa-python text-blue-400 text-2xl mr-2"></i>
127
+ <h1 class="text-xl font-bold">PyWeb</h1>
128
+ </div>
129
+ <div class="hidden md:flex space-x-2">
130
+ <button class="px-3 py-1 rounded hover:bg-gray-700 flex items-center">
131
+ <i class="fas fa-file mr-1"></i> New
132
+ </button>
133
+ <button class="px-3 py-1 rounded hover:bg-gray-700 flex items-center">
134
+ <i class="fas fa-folder-open mr-1"></i> Open
135
+ </button>
136
+ <button class="px-3 py-1 rounded hover:bg-gray-700 flex items-center">
137
+ <i class="fas fa-save mr-1"></i> Save
138
+ </button>
139
+ </div>
140
+ </div>
141
+ <div class="flex items-center space-x-4">
142
+ <button id="run-btn" class="bg-green-600 hover:bg-green-700 px-4 py-1 rounded flex items-center">
143
+ <i class="fas fa-play mr-1"></i> Run
144
+ </button>
145
+ <div class="relative">
146
+ <button class="px-3 py-1 rounded hover:bg-gray-700">
147
+ <i class="fas fa-cog"></i>
148
+ </button>
149
+ </div>
150
+ </div>
151
+ </div>
152
+
153
+ <!-- Main Content -->
154
+ <div class="flex flex-1 overflow-hidden">
155
+ <!-- Sidebar -->
156
+ <div id="sidebar" class="sidebar bg-gray-800 w-64 flex flex-col border-r border-gray-700">
157
+ <div class="p-3 border-b border-gray-700 flex justify-between items-center">
158
+ <h2 class="font-semibold">Explorer</h2>
159
+ <button id="sidebar-toggle" class="text-gray-400 hover:text-white">
160
+ <i class="fas fa-chevron-left"></i>
161
+ </button>
162
+ </div>
163
+ <div class="flex-1 overflow-y-auto">
164
+ <div class="py-2">
165
+ <div class="sidebar-item px-4 py-2 flex items-center cursor-pointer">
166
+ <i class="fas fa-folder-open text-blue-400 mr-2"></i>
167
+ <span>Project</span>
168
+ </div>
169
+ <div class="ml-6">
170
+ <div class="sidebar-item px-4 py-2 flex items-center cursor-pointer">
171
+ <i class="fas fa-file-code text-yellow-400 mr-2"></i>
172
+ <span>main.py</span>
173
+ </div>
174
+ <div class="sidebar-item px-4 py-2 flex items-center cursor-pointer">
175
+ <i class="fas fa-file-code text-yellow-400 mr-2"></i>
176
+ <span>utils.py</span>
177
+ </div>
178
+ </div>
179
+ </div>
180
+ <div class="py-2 border-t border-gray-700">
181
+ <div class="sidebar-item px-4 py-2 flex items-center cursor-pointer">
182
+ <i class="fas fa-search text-purple-400 mr-2"></i>
183
+ <span>Search</span>
184
+ </div>
185
+ </div>
186
+ <div class="py-2 border-t border-gray-700">
187
+ <div id="terminal-tab" class="sidebar-item px-4 py-2 flex items-center cursor-pointer">
188
+ <i class="fas fa-terminal text-green-400 mr-2"></i>
189
+ <span>Terminal</span>
190
+ </div>
191
+ </div>
192
+ </div>
193
+ </div>
194
+
195
+ <!-- Editor Area -->
196
+ <div class="flex-1 flex flex-col overflow-hidden">
197
+ <!-- Tabs -->
198
+ <div class="bg-gray-800 border-b border-gray-700 flex overflow-x-auto">
199
+ <div id="editor-tab" class="tab active px-4 py-2 flex items-center border-r border-gray-700 cursor-pointer">
200
+ <i class="fas fa-file-code text-yellow-400 mr-2"></i>
201
+ <span>main.py</span>
202
+ <i class="fas fa-times ml-2 text-gray-400 hover:text-white"></i>
203
+ </div>
204
+ <div class="tab px-4 py-2 flex items-center border-r border-gray-700 cursor-pointer">
205
+ <i class="fas fa-file-code text-yellow-400 mr-2"></i>
206
+ <span>utils.py</span>
207
+ <i class="fas fa-times ml-2 text-gray-400 hover:text-white"></i>
208
+ </div>
209
+ <div class="px-4 py-2 flex items-center cursor-pointer hover:bg-gray-700">
210
+ <i class="fas fa-plus text-gray-400"></i>
211
+ </div>
212
+ </div>
213
+
214
+ <!-- Editor and Output -->
215
+ <div id="editor-container" class="editor-container flex flex-col md:flex-row flex-1 overflow-hidden">
216
+ <!-- Editor -->
217
+ <div class="flex-1 flex overflow-hidden">
218
+ <div class="line-numbers overflow-y-auto"></div>
219
+ <textarea id="editor" class="editor flex-1 bg-gray-900 text-white p-4 outline-none resize-none overflow-auto" spellcheck="false"># Welcome to PyWeb - Python Editor
220
+ # Write your Python code here and click Run
221
+
222
+ def greet(name):
223
+ """A simple greeting function"""
224
+ return f"Hello, {name}!"
225
+
226
+ print(greet("World"))
227
+
228
+ # Try some math
229
+ result = 42 + 3.14 * 2
230
+ print(f"The answer is {result}")
231
+
232
+ # List comprehension example
233
+ squares = [x**2 for x in range(10)]
234
+ print(f"Squares: {squares}")</textarea>
235
+ </div>
236
+
237
+ <!-- Output -->
238
+ <div class="w-full md:w-1/3 bg-gray-800 border-t md:border-t-0 md:border-l border-gray-700 flex flex-col">
239
+ <div class="bg-gray-700 px-4 py-2 flex justify-between items-center">
240
+ <h3 class="font-semibold">Output</h3>
241
+ <div class="flex space-x-2">
242
+ <button id="clear-output" class="text-gray-400 hover:text-white">
243
+ <i class="fas fa-trash-alt"></i>
244
+ </button>
245
+ <button class="text-gray-400 hover:text-white">
246
+ <i class="fas fa-expand"></i>
247
+ </button>
248
+ </div>
249
+ </div>
250
+ <pre id="output" class="output flex-1"></pre>
251
+ </div>
252
+ </div>
253
+
254
+ <!-- Terminal (hidden by default) -->
255
+ <div id="terminal-container" class="editor-container flex flex-col flex-1 overflow-hidden" style="display: none;">
256
+ <div class="terminal flex-1 flex flex-col">
257
+ <div class="bg-gray-700 px-4 py-2 flex justify-between items-center">
258
+ <h3 class="font-semibold">Terminal</h3>
259
+ <div class="flex space-x-2">
260
+ <button id="clear-terminal" class="text-gray-400 hover:text-white">
261
+ <i class="fas fa-trash-alt"></i>
262
+ </button>
263
+ <button id="close-terminal" class="text-gray-400 hover:text-white">
264
+ <i class="fas fa-times"></i>
265
+ </button>
266
+ </div>
267
+ </div>
268
+ <div id="terminal-content" class="flex-1 overflow-y-auto p-2">
269
+ <div class="terminal-output">
270
+ PyWeb Terminal v1.0<br>
271
+ Type 'help' for a list of commands<br><br>
272
+ </div>
273
+ <div class="terminal-line flex items-center">
274
+ <span class="terminal-prompt">user@pyweb:~$&nbsp;</span>
275
+ <input id="terminal-input" class="terminal-input" type="text" autofocus>
276
+ <span class="terminal-cursor"></span>
277
+ </div>
278
+ </div>
279
+ </div>
280
+ </div>
281
+ </div>
282
+ </div>
283
+
284
+ <!-- Status Bar -->
285
+ <div class="bg-gray-800 px-4 py-1 flex justify-between items-center text-sm border-t border-gray-700">
286
+ <div class="flex items-center space-x-4">
287
+ <div class="flex items-center">
288
+ <i class="fab fa-python text-blue-400 mr-1"></i>
289
+ <span>Python 3.10</span>
290
+ </div>
291
+ <div class="hidden md:flex items-center">
292
+ <i class="fas fa-code-branch text-purple-400 mr-1"></i>
293
+ <span>main</span>
294
+ </div>
295
+ </div>
296
+ <div class="flex items-center space-x-4">
297
+ <div class="flex items-center">
298
+ <i class="fas fa-memory text-yellow-400 mr-1"></i>
299
+ <span>128 MB</span>
300
+ </div>
301
+ <div class="flex items-center">
302
+ <i class="fas fa-bolt text-green-400 mr-1"></i>
303
+ <span id="status-ready">Ready</span>
304
+ </div>
305
+ </div>
306
+ </div>
307
+ </div>
308
+
309
+ <script>
310
+ // DOM Elements
311
+ const editor = document.getElementById('editor');
312
+ const output = document.getElementById('output');
313
+ const runBtn = document.getElementById('run-btn');
314
+ const clearOutputBtn = document.getElementById('clear-output');
315
+ const sidebar = document.getElementById('sidebar');
316
+ const sidebarToggle = document.getElementById('sidebar-toggle');
317
+ const statusReady = document.getElementById('status-ready');
318
+ const terminalTab = document.getElementById('terminal-tab');
319
+ const editorTab = document.getElementById('editor-tab');
320
+ const terminalContainer = document.getElementById('terminal-container');
321
+ const editorContainer = document.getElementById('editor-container');
322
+ const terminalContent = document.getElementById('terminal-content');
323
+ const terminalInput = document.getElementById('terminal-input');
324
+ const clearTerminalBtn = document.getElementById('clear-terminal');
325
+ const closeTerminalBtn = document.getElementById('close-terminal');
326
+
327
+ // Terminal state
328
+ let terminalHistory = [];
329
+ let historyIndex = -1;
330
+ let currentDirectory = '~';
331
+
332
+ // Initialize line numbers
333
+ function updateLineNumbers() {
334
+ const lineNumbers = document.querySelector('.line-numbers');
335
+ const lines = editor.value.split('\n');
336
+ lineNumbers.innerHTML = '';
337
+
338
+ for (let i = 1; i <= lines.length; i++) {
339
+ const lineNumber = document.createElement('div');
340
+ lineNumber.textContent = i;
341
+ lineNumbers.appendChild(lineNumber);
342
+ }
343
+ }
344
+
345
+ // Syntax highlighting (simplified)
346
+ function applySyntaxHighlighting() {
347
+ // This is a simplified version - a real implementation would use a proper lexer
348
+ const code = editor.value;
349
+
350
+ // Keywords to highlight
351
+ const keywords = ['def', 'return', 'if', 'else', 'elif', 'for', 'while', 'in', 'and', 'or', 'not', 'True', 'False', 'None', 'import', 'from', 'as', 'class', 'try', 'except', 'finally', 'with', 'raise', 'is', 'lambda', 'nonlocal', 'global', 'yield', 'async', 'await'];
352
+
353
+ // Simple regex-based highlighting
354
+ let highlighted = code
355
+ .replace(/(".*?"|'.*?')/g, '<span class="python-string">$1</span>')
356
+ .replace(/#.*$/gm, '<span class="python-comment">$&</span>')
357
+ .replace(/\b\d+\.?\d*\b/g, '<span class="python-number">$&</span>')
358
+ .replace(new RegExp(`\\b(${keywords.join('|')})\\b`, 'g'), '<span class="python-keyword">$1</span>')
359
+ .replace(/\b(def|class)\s+(\w+)\b/g, '<span class="python-keyword">$1</span> <span class="python-function">$2</span>');
360
+
361
+ // Create a temporary div to hold the highlighted code
362
+ const tempDiv = document.createElement('div');
363
+ tempDiv.innerHTML = highlighted;
364
+
365
+ // Get the cursor position
366
+ const cursorPos = editor.selectionStart;
367
+
368
+ // Replace the editor content (this will lose the cursor position)
369
+ // In a real implementation, we would use a proper code editor library
370
+ // that maintains cursor position during highlighting
371
+
372
+ // For now, we'll just update the line numbers
373
+ updateLineNumbers();
374
+ }
375
+
376
+ // Run Python code
377
+ async function runPythonCode() {
378
+ const code = editor.value;
379
+ output.textContent = 'Running...';
380
+ statusReady.textContent = 'Running';
381
+ runBtn.disabled = true;
382
+ runBtn.classList.remove('bg-green-600', 'hover:bg-green-700');
383
+ runBtn.classList.add('bg-gray-600', 'cursor-not-allowed');
384
+
385
+ try {
386
+ // In a real implementation, you would send this to a backend service
387
+ // that can execute Python code safely. For this demo, we'll simulate
388
+ // execution with a timeout and some example output.
389
+
390
+ // Simulate network delay
391
+ await new Promise(resolve => setTimeout(resolve, 500));
392
+
393
+ // Simulate execution
394
+ const result = simulatePythonExecution(code);
395
+ output.textContent = result;
396
+
397
+ statusReady.textContent = 'Ready';
398
+ } catch (error) {
399
+ output.textContent = `Error: ${error.message}`;
400
+ statusReady.textContent = 'Error';
401
+ } finally {
402
+ runBtn.disabled = false;
403
+ runBtn.classList.add('bg-green-600', 'hover:bg-green-700');
404
+ runBtn.classList.remove('bg-gray-600', 'cursor-not-allowed');
405
+ }
406
+ }
407
+
408
+ // Simulate Python execution (for demo purposes)
409
+ function simulatePythonExecution(code) {
410
+ // This is just for demonstration - in a real app, you'd use a proper Python interpreter
411
+
412
+ // Check for some common patterns to simulate different outputs
413
+ if (code.includes('import os') && code.includes('os.system')) {
414
+ return "Error: Restricted system call (os.system)";
415
+ }
416
+
417
+ if (code.includes('while True:')) {
418
+ return "Error: Potential infinite loop detected";
419
+ }
420
+
421
+ if (code.includes('import sys') && code.includes('sys.exit')) {
422
+ return "Process finished with exit code 0";
423
+ }
424
+
425
+ // Default simulated output
426
+ return `Hello, World!
427
+ The answer is 48.28
428
+ Squares: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
429
+
430
+ Process finished with exit code 0`;
431
+ }
432
+
433
+ // Clear output
434
+ function clearOutput() {
435
+ output.textContent = '';
436
+ }
437
+
438
+ // Toggle sidebar
439
+ function toggleSidebar() {
440
+ sidebar.classList.toggle('collapsed');
441
+ const icon = sidebarToggle.querySelector('i');
442
+ if (sidebar.classList.contains('collapsed')) {
443
+ icon.classList.remove('fa-chevron-left');
444
+ icon.classList.add('fa-chevron-right');
445
+ } else {
446
+ icon.classList.remove('fa-chevron-right');
447
+ icon.classList.add('fa-chevron-left');
448
+ }
449
+ }
450
+
451
+ // Terminal functions
452
+ function showTerminal() {
453
+ editorContainer.style.display = 'none';
454
+ terminalContainer.style.display = 'flex';
455
+ terminalInput.focus();
456
+ }
457
+
458
+ function showEditor() {
459
+ terminalContainer.style.display = 'none';
460
+ editorContainer.style.display = 'flex';
461
+ }
462
+
463
+ function clearTerminal() {
464
+ terminalContent.innerHTML = `
465
+ <div class="terminal-output">
466
+ PyWeb Terminal v1.0<br>
467
+ Type 'help' for a list of commands<br><br>
468
+ </div>
469
+ <div class="terminal-line flex items-center">
470
+ <span class="terminal-prompt">user@pyweb:~$&nbsp;</span>
471
+ <input id="terminal-input" class="terminal-input" type="text" autofocus>
472
+ <span class="terminal-cursor"></span>
473
+ </div>
474
+ `;
475
+ terminalInput = document.getElementById('terminal-input');
476
+ terminalInput.focus();
477
+ setupTerminalInput();
478
+ }
479
+
480
+ function setupTerminalInput() {
481
+ terminalInput.addEventListener('keydown', function(e) {
482
+ if (e.key === 'Enter') {
483
+ const command = terminalInput.value.trim();
484
+ if (command) {
485
+ terminalHistory.push(command);
486
+ historyIndex = terminalHistory.length;
487
+ processCommand(command);
488
+ }
489
+ } else if (e.key === 'ArrowUp') {
490
+ if (terminalHistory.length > 0 && historyIndex > 0) {
491
+ historyIndex--;
492
+ terminalInput.value = terminalHistory[historyIndex];
493
+ e.preventDefault();
494
+ }
495
+ } else if (e.key === 'ArrowDown') {
496
+ if (terminalHistory.length > 0 && historyIndex < terminalHistory.length - 1) {
497
+ historyIndex++;
498
+ terminalInput.value = terminalHistory[historyIndex];
499
+ e.preventDefault();
500
+ } else if (historyIndex === terminalHistory.length - 1) {
501
+ historyIndex = terminalHistory.length;
502
+ terminalInput.value = '';
503
+ e.preventDefault();
504
+ }
505
+ }
506
+ });
507
+ }
508
+
509
+ function processCommand(command) {
510
+ // Add the command to the terminal output
511
+ const outputDiv = document.createElement('div');
512
+ outputDiv.className = 'terminal-output';
513
+ outputDiv.innerHTML = `<span class="terminal-prompt">user@pyweb:~$&nbsp;</span>${command}`;
514
+ terminalContent.insertBefore(outputDiv, terminalContent.lastElementChild);
515
+
516
+ // Process the command
517
+ let response = '';
518
+ const args = command.split(' ');
519
+ const cmd = args[0].toLowerCase();
520
+
521
+ switch (cmd) {
522
+ case 'help':
523
+ response = `Available commands:<br>
524
+ help - Show this help message<br>
525
+ clear - Clear the terminal<br>
526
+ ls - List files<br>
527
+ cd [dir] - Change directory<br>
528
+ run - Run the current Python code<br>
529
+ python [code] - Execute Python code<br>
530
+ exit - Close the terminal`;
531
+ break;
532
+ case 'clear':
533
+ clearTerminal();
534
+ return;
535
+ case 'ls':
536
+ response = `main.py<br>utils.py<br>README.md`;
537
+ break;
538
+ case 'cd':
539
+ if (args.length > 1) {
540
+ currentDirectory = args[1];
541
+ response = `Changed directory to ${currentDirectory}`;
542
+ } else {
543
+ response = `Usage: cd [directory]`;
544
+ }
545
+ break;
546
+ case 'run':
547
+ runPythonCode();
548
+ response = `Running Python code from editor...`;
549
+ break;
550
+ case 'python':
551
+ if (args.length > 1) {
552
+ const pythonCode = args.slice(1).join(' ');
553
+ try {
554
+ // This is just for demo - in a real app you'd use a proper interpreter
555
+ if (pythonCode.includes('print')) {
556
+ response = pythonCode.includes('"') ?
557
+ pythonCode.match(/"([^"]*)"/)[1] :
558
+ pythonCode.match(/'([^']*)'/)[1];
559
+ } else {
560
+ response = `Executed: ${pythonCode}`;
561
+ }
562
+ } catch (e) {
563
+ response = `Error: ${e.message}`;
564
+ }
565
+ } else {
566
+ response = `Usage: python [code]`;
567
+ }
568
+ break;
569
+ case 'exit':
570
+ showEditor();
571
+ return;
572
+ default:
573
+ response = `Command not found: ${cmd}. Type 'help' for available commands.`;
574
+ }
575
+
576
+ // Add the response to the terminal
577
+ const responseDiv = document.createElement('div');
578
+ responseDiv.className = 'terminal-output';
579
+ responseDiv.innerHTML = response;
580
+ terminalContent.insertBefore(responseDiv, terminalContent.lastElementChild);
581
+
582
+ // Add a new input line
583
+ const newInputDiv = document.createElement('div');
584
+ newInputDiv.className = 'terminal-line flex items-center';
585
+ newInputDiv.innerHTML = `
586
+ <span class="terminal-prompt">user@pyweb:${currentDirectory}$&nbsp;</span>
587
+ <input id="terminal-input" class="terminal-input" type="text" autofocus>
588
+ <span class="terminal-cursor"></span>
589
+ `;
590
+ terminalContent.appendChild(newInputDiv);
591
+
592
+ // Remove the old input
593
+ terminalContent.removeChild(terminalContent.lastElementChild.previousElementSibling);
594
+
595
+ // Set up the new input
596
+ terminalInput = document.getElementById('terminal-input');
597
+ setupTerminalInput();
598
+ terminalInput.focus();
599
+ }
600
+
601
+ // Event Listeners
602
+ editor.addEventListener('input', updateLineNumbers);
603
+ editor.addEventListener('keydown', function(e) {
604
+ if (e.key === 'Tab') {
605
+ e.preventDefault();
606
+ const start = this.selectionStart;
607
+ const end = this.selectionEnd;
608
+
609
+ // Insert tab character
610
+ this.value = this.value.substring(0, start) + ' ' + this.value.substring(end);
611
+
612
+ // Move cursor
613
+ this.selectionStart = this.selectionEnd = start + 4;
614
+
615
+ updateLineNumbers();
616
+ }
617
+ });
618
+
619
+ runBtn.addEventListener('click', runPythonCode);
620
+ clearOutputBtn.addEventListener('click', clearOutput);
621
+ sidebarToggle.addEventListener('click', toggleSidebar);
622
+ terminalTab.addEventListener('click', showTerminal);
623
+ editorTab.addEventListener('click', showEditor);
624
+ clearTerminalBtn.addEventListener('click', clearTerminal);
625
+ closeTerminalBtn.addEventListener('click', showEditor);
626
+
627
+ // Initialize
628
+ updateLineNumbers();
629
+ setupTerminalInput();
630
+
631
+ // Auto-resize editor when window resizes
632
+ window.addEventListener('resize', function() {
633
+ updateLineNumbers();
634
+ });
635
+ </script>
636
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=ayoubghilmi/ayoub-edit-code" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
637
+ </html>