Update app.py
Browse files5 unmodified lines678991011121 unmodified line141516171718192043 unmodified lines6465666768676869707172717273747576777879808182838474758586878889909192939495963 unmodified lines100101102851031041058810610710810911092111112949596979811311411511611711811912026 unmodified lines1471481491311501511521341531541551561381571581591601611621631451641651471481661671681691707 unmodified lines1781791801621811821641831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442459 unmodified lines2552562571852582592602612622631922642652664 unmodified lines2712722732032742752762772072082092782102112792802812152822832841 unmodified line2862872882232892902912922262932942952292962972982993003013023032363043053062393073083092423103113123139 unmodified lines3233243252583263273286 unmodified lines33533633727133833934034145 unmodified lines3873883893233903913923933283943953963973983343994004014024034044053394064074084099 unmodified lines4194204214223554234244254264274284293614304314324335 unmodified linesapp = Flask(__name__)
# ==========================================# FRONTEND: Premium Glassmorphism + Live File System# FRONTEND: Premium UI + Flawless Translations + Live VFS# ==========================================HTML_TEMPLATE = """<!DOCTYPE html>1 unmodified line<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Twenty IDE | Live File System</title> <title>Twenty IDE | Premium VFS</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> :root {43 unmodified lines @keyframes slideInLeft { to { transform: translateX(0); opacity: 1; } } @keyframes slideInUp { to { transform: translateY(0); opacity: 1; } }
/* Üst Panel */ .top-bar { height: 60px; margin: 15px 15px 0 15px; display: flex; justify-content: space-between; align-items: center; padding: 0 25px; z-index: 100; } /* --- ÜST PANEL VƏ DÜYMƏLƏR (DÜZƏLDİLDİ) --- */ .top-bar { height: 65px; margin: 15px 15px 0 15px; display: flex; justify-content: space-between; align-items: center; padding: 0 30px; z-index: 100; } .brand { font-size: 18px; font-weight: 300; letter-spacing: 4px; display: flex; align-items: center; gap: 20px; } .brand i { color: var(--accent); } .controls { display: flex; align-items: center; gap: 20px; } .lang-select { background: rgba(0, 0, 0, 0.4); color: var(--text-main); border: 1px solid rgba(255,255,255,0.1); padding: 6px 12px; border-radius: var(--radius-small); cursor: pointer; outline: none; transition: 0.3s; font-size: 12px; letter-spacing: 1px; font-weight: 500; } /* Düymələr arası məsafə (gap) artırıldı, ölçülər zərifləşdirildi */ .controls { display: flex; align-items: center; gap: 25px; } .lang-select { background: rgba(0, 0, 0, 0.4); color: var(--text-main); border: 1px solid rgba(255,255,255,0.15); padding: 7px 14px; border-radius: var(--radius-small); cursor: pointer; outline: none; transition: 0.3s; font-size: 13px; letter-spacing: 1px; font-weight: 500; appearance: none; /* Standart oxu gizlədir */ -webkit-appearance: none; text-align: center; min-width: 60px; } .lang-select:hover { border-color: var(--accent); box-shadow: 0 0 10px rgba(0, 242, 254, 0.2); } .run-btn { background: rgba(0, 242, 254, 0.1); color: var(--accent); border: 1px solid var(--accent); padding: 6px 18px; border-radius: var(--radius-small); cursor: pointer; font-weight: 600; transition: 0.4s; display: flex; align-items: center; gap: 6px; box-shadow: 0 0 15px rgba(0, 242, 254, 0.1); letter-spacing: 1px; font-size: 13px; } .run-btn:hover { background: var(--accent); color: #000; box-shadow: 0 0 20px rgba(0, 242, 254, 0.5); transform: translateY(-2px); }
.run-btn { background: rgba(0, 242, 254, 0.05); color: var(--accent); border: 1px solid var(--accent); padding: 7px 20px; border-radius: var(--radius-small); cursor: pointer; font-weight: 600; transition: 0.4s; display: flex; align-items: center; gap: 8px; box-shadow: 0 0 15px rgba(0, 242, 254, 0.1); letter-spacing: 1px; font-size: 13px; } .run-btn:hover { background: var(--accent); color: #000; box-shadow: 0 0 20px rgba(0, 242, 254, 0.4); transform: translateY(-2px); } .panel-toggle { background: transparent; color: var(--text-muted); border: none; cursor: pointer; font-size: 18px; transition: 0.3s; padding: 5px; } .panel-toggle:hover { color: white; transform: scale(1.1); }
3 unmodified lines /* Sol Panel (Fayl Sistemi) */ .sidebar-left { width: 300px; transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1); } .sidebar-left.collapsed { width: 0; border: none; margin: 0; opacity: 0; padding: 0; } .panel-title { padding: 15px 20px; font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--text-muted); border-bottom: 1px solid var(--glass-border); background: rgba(0,0,0,0.2); display: flex; justify-content: space-between; align-items: center; } .panel-title { padding: 18px 25px; font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--text-muted); border-bottom: 1px solid var(--glass-border); background: rgba(0,0,0,0.2); display: flex; justify-content: space-between; align-items: center; } /* Yeni Fayl Düymələri */ .file-actions i { cursor: pointer; margin-left: 10px; font-size: 14px; transition: 0.2s; } .file-actions { display: flex; gap: 15px; } .file-actions i { cursor: pointer; font-size: 14px; transition: 0.2s; color: var(--text-muted); } .file-actions i:hover { color: var(--accent); transform: scale(1.2); }
.file-list { padding: 15px; flex: 1; overflow-y: auto; font-size: 14px; } .file-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--text-muted); cursor: pointer; padding: 10px 12px; border-radius: var(--radius-small); transition: 0.2s; font-size: 13.5px; margin-bottom: 5px; } .file-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--text-muted); cursor: pointer; padding: 10px 15px; border-radius: var(--radius-small); transition: 0.2s; font-size: 13.5px; margin-bottom: 5px; } .file-item:hover { color: white; background: rgba(255,255,255,0.05); } .file-item.active { color: white; background: rgba(0, 242, 254, 0.1); border-left: 3px solid var(--accent); } .file-name { display: flex; align-items: center; gap: 10px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .delete-btn { color: #ff5370; opacity: 0; transition: 0.2s; font-size: 12px; } .file-item:hover .delete-btn { opacity: 0.7; } .delete-btn:hover { opacity: 1 !important; transform: scale(1.1); } .file-item.active { color: white; background: rgba(0, 242, 254, 0.08); border-left: 3px solid var(--accent); } .file-name { display: flex; align-items: center; gap: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .delete-btn { color: #ff5370; opacity: 0; transition: 0.2s; font-size: 12px; padding: 5px; } .file-item:hover .delete-btn { opacity: 0.8; } .delete-btn:hover { opacity: 1 !important; transform: scale(1.2); }
/* Orta Panel */ .center-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }26 unmodified lines <div class="glass-panel top-bar" id="top-bar"> <div class="brand"> <button class="panel-toggle" onclick="togglePanel('left')"><i class="fa-solid fa-folder-tree"></i></button> <i class="fa-solid fa-code"></i> <span id="current-filename-display">TWENTY IDE</span> <i class="fa-solid fa-code"></i> <span id="brand-text">TWENTY IDE</span> <span style="color:var(--text-muted); font-size:12px; margin-left:10px;">-</span> <span id="current-filename-display" style="color:var(--text-muted); font-size:13px; margin-left:10px;">main.py</span> </div> <div class="controls"> <select class="lang-select" id="lang-select"> <select class="lang-select" id="lang-select" onchange="changeLanguage()"> <option value="az">AZ</option> <option value="en">EN</option> </select> <button class="run-btn" onclick="runCode()" id="btn-run"><i class="fa-solid fa-play"></i> İcra Et</button> <button class="run-btn" onclick="runCode()" id="btn-run"><i class="fa-solid fa-play"></i> <span id="t-run">İcra Et</span></button> </div> </div>
<div class="main-layout"> <div class="glass-panel sidebar-left" id="sidebar-left"> <div class="panel-title"> LAYİHƏ <span id="t-project">LAYİHƏ</span> <div class="file-actions"> <i class="fa-solid fa-file-circle-plus" onclick="createNewFile()" title="Yeni Fayl Yarat"></i> <i class="fa-solid fa-upload" onclick="document.getElementById('file-upload').click()" title="Kompüterdən Yüklə"></i> <i class="fa-solid fa-file-circle-plus" onclick="createNewFile()" title="Yeni Fayl Yarat" id="t-new-file"></i> <i class="fa-solid fa-upload" onclick="document.getElementById('file-upload').click()" title="Kompüterdən Yüklə" id="t-upload-file"></i> <input type="file" id="file-upload" style="display: none;" onchange="uploadFile(event)"> </div> </div>7 unmodified lines <div class="terminal-wrapper" id="terminal-wrapper"> <div class="terminal-header"> <span><i class="fa-solid fa-terminal"></i> PowerShell Engine</span> <i class="fa-solid fa-broom" style="cursor:pointer; transition:0.3s;" onclick="clearTerminal()" onmouseover="this.style.color='white'" onmouseout="this.style.color='#999'" title="Təmizlə"></i> <i class="fa-solid fa-broom" style="cursor:pointer; transition:0.3s;" onclick="clearTerminal()" onmouseover="this.style.color='white'" onmouseout="this.style.color='#999'" id="t-clear" title="Təmizlə"></i> </div> <div id="terminal-output"><span style="color: #888;">// Twenty Premium Engine Aktivdir...</span><br><span class="ps-prompt">PS C:\\Twenty></span> Sistem hazırdır.</div> <div id="terminal-output"><span style="color: #888;" id="t-term-start">// Twenty Premium Engine Aktivdir...</span><br><span class="ps-prompt">PS C:\\Twenty></span> <span id="t-term-ready">Sistem hazırdır.</span></div> </div> </div> </div>
<script> // ========================================== // DİL TƏRCÜMƏ SİSTEMİ (QÜSURSUZ) // ========================================== const translations = { 'az': { run: 'İcra Et', project: 'LAYİHƏ', brand: 'TWENTY IDE', termStart: '// Twenty Premium Engine Aktivdir...', termReady: 'Sistem hazırdır.', clearTitle: 'Təmizlə', newFileTitle: 'Yeni Fayl Yarat', uploadTitle: 'Kompüterdən Yüklə', promptNewFile: 'Yeni faylın adını yazın (məsələn: test.py):', errExists: 'Bu adda fayl artıq var!', errLastFile: 'Sonuncu faylı silə bilməzsiniz!', confirmDel: "silinsin?" }, 'en': { run: 'Run Code', project: 'PROJECT', brand: 'TWENTY WORKSPACE', termStart: '// Twenty Premium Engine Initialized...', termReady: 'System is ready.', clearTitle: 'Clear Console', newFileTitle: 'Create New File', uploadTitle: 'Upload from PC', promptNewFile: 'Enter new file name (e.g., test.py):', errExists: 'File with this name already exists!', errLastFile: 'Cannot delete the last remaining file!', confirmDel: "delete?" } };
let currentLang = 'az';
function changeLanguage() { currentLang = document.getElementById('lang-select').value; const t = translations[currentLang]; document.getElementById('t-run').innerText = t.run; document.getElementById('t-project').innerText = t.project; document.getElementById('brand-text').innerText = t.brand; document.getElementById('t-clear').title = t.clearTitle; document.getElementById('t-new-file').title = t.newFileTitle; document.getElementById('t-upload-file').title = t.uploadTitle; // Yalnız əgər terminal təmizlənibsə və ya yeni açılıbsa yazıları dəyiş const termStartEl = document.getElementById('t-term-start'); const termReadyEl = document.getElementById('t-term-ready'); if(termStartEl) termStartEl.innerText = t.termStart; if(termReadyEl) termReadyEl.innerText = t.termReady; }
// ========================================== // VİRTUAL FAYL SİSTEMİ (VFS) MƏNTİQİ // ==========================================9 unmodified lines tree.innerHTML = ""; for (let filename in fileSystem) { // İkon təyini let icon = '<i class="fa-solid fa-file-code" style="color:#aaa;"></i>'; if(filename.endsWith('.py')) icon = '<i class="fa-brands fa-python" style="color:#ffeb3b;"></i>'; else if(filename.endsWith('.txt')) icon = '<i class="fa-solid fa-file-lines" style="color:#888;"></i>';
const isActive = filename === currentFile ? 'active' : ''; // HTML quruluşu const fileDiv = document.createElement('div'); fileDiv.className = `file-item ${isActive}`; fileDiv.innerHTML = `4 unmodified lines `; tree.appendChild(fileDiv); } document.getElementById('current-filename-display').innerText = `TWENTY IDE - ${currentFile}`; document.getElementById('current-filename-display').innerText = currentFile; }
function switchFile(filename) { // Köhnə faylı yadda saxla if(editor) { fileSystem[currentFile] = editor.getValue(); if(editor) fileSystem[currentFile] = editor.getValue(); } // Yeni fayla keç currentFile = filename; editor.setValue(fileSystem[filename]); // Dili təyin et (Python, txt vs) if(filename.endsWith('.py')) monaco.editor.setModelLanguage(editor.getModel(), "python"); else monaco.editor.setModelLanguage(editor.getModel(), "plaintext"); 1 unmodified line }
function createNewFile() { let filename = prompt("Yeni faylın adını yazın (məsələn: test.py):"); const t = translations[currentLang]; let filename = prompt(t.promptNewFile); if(filename && filename.trim() !== "") { if(fileSystem[filename]) { alert("Bu adda fayl artıq var!"); alert(t.errExists); return; } fileSystem[filename] = "# Yeni fayl: " + filename; fileSystem[filename] = "# " + filename; switchFile(filename); } }
function deleteFile(filename) { const t = translations[currentLang]; if(Object.keys(fileSystem).length === 1) { alert("Sonuncu faylı silə bilməzsiniz!"); alert(t.errLastFile); return; } if(confirm(`'${filename}' silinsin?`)) { if(confirm(`'${filename}' ${t.confirmDel}`)) { delete fileSystem[filename]; if(currentFile === filename) { currentFile = Object.keys(fileSystem)[0]; // İlk tapdığına keç currentFile = Object.keys(fileSystem)[0]; editor.setValue(fileSystem[currentFile]); } renderFileTree();9 unmodified lines const content = e.target.result; let filename = file.name; // Eyni adda fayl varsa sonuna rəqəm artır let counter = 1; while(fileSystem[filename]) { const parts = file.name.split('.');6 unmodified lines switchFile(filename); }; reader.readAsText(file); event.target.value = ''; // Inputu təmizlə event.target.value = ''; }
// --- GİRİŞ ANİMASİYASI ---45 unmodified lines padding: { top: 20 } }); // Kodu hər dəyişəndə VFS-də yadda saxla editor.onDidChangeModelContent(() => { fileSystem[currentFile] = editor.getValue(); }); // İlk açılışda fayl ağacını cız renderFileTree(); });
// --- TERMINAL İCRA --- async function runCode() { // Əgər dəyişiklik edilibsə son halı yadda saxla fileSystem[currentFile] = editor.getValue(); const codeToRun = fileSystem[currentFile]; const isEnglish = currentLang === 'en'; const terminal = document.getElementById('terminal-output'); const runText = isEnglish ? "Running..." : "İcra olunur..."; terminal.innerHTML += `\\n\\n<span class="ps-prompt">PS C:\\\\Twenty></span> python ${currentFile}\\n<span style="color: #888;">İcra olunur...</span>`; terminal.innerHTML += `\\n\\n<span class="ps-prompt">PS C:\\\\Twenty></span> python ${currentFile}\\n<span style="color: #888;">${runText}</span>`; terminal.scrollTop = terminal.scrollHeight; try {9 unmodified lines terminal.innerHTML += `\\n<span class="ps-error">${data.output}</span>`; } } catch (error) { const errText = isEnglish ? "Server error!" : "Server xətası!"; terminal.innerHTML += `\\n<span class="ps-error">Server xətası!</span>`; terminal.innerHTML += `\\n<span class="ps-error">${errText}</span>`; } terminal.scrollTop = terminal.scrollHeight; }
function clearTerminal() { const t = translations[currentLang]; document.getElementById('terminal-output').innerHTML = `<span class="ps-prompt">PS C:\\\\Twenty></span> Terminal təmizləndi...`; document.getElementById('terminal-output').innerHTML = `<span class="ps-prompt">PS C:\\\\Twenty></span> ${t.clearTitle}...`; } </script></body>app.py+116-47