Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
feat(project): change prokect code
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadreza1388 committed Sep 8, 2024
1 parent f97e64d commit e84610e
Show file tree
Hide file tree
Showing 5 changed files with 5,319 additions and 39 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# salam/salam-wa.js
# salam/salam-wa.wasm
124 changes: 124 additions & 0 deletions salam-online (2).html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!DOCTYPE html>
<html dir="rtl" lang="fa-IR">

<head>
<title>Salam Programming Language</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style/style.css">
</head>

<body>
<header>
<button id="execute" disabled="true">اجرا</button>
</header>
<textarea id="code"></textarea>
<iframe></iframe>
<pre></pre>

<script>
const codeTextArea = document.querySelector('#code');
const executeButton = document.querySelector('#execute');
const outputPre = document.querySelector('pre');
const iframe = document.querySelector('iframe');

const args = ['code', ''];
let isReady = false;

var Module = {
noInitialRun: true,
onRuntimeInitialized: () => {
console.log('Salam loaded successfully');
isReady = true;
executeButton.disabled = false;

if (codeTextArea.value.toString().trim() !== '') {
runSalam();
}
},
print: (text) => {
console.log(text);
}
};

function captureOutput(arguments) {
if(iframe.style.right === "50%"){
iframe.style.right = "150%"
}else if(iframe.style.right === "150%"){
iframe.style.right = "50%"
}else {
iframe.style.right = "50%"
}
if (outputPre) {
outputPre.textContent = '';
}

let output = '';

const originalConsoleLog = console.log;
console.log = function (text) {
output += text + '\n';
};

callMain(arguments);

console.log = originalConsoleLog;

if (outputPre) {
outputPre.textContent = output;

const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (iframeDocument) {
iframeDocument.open();
iframeDocument.write(output);
iframeDocument.close();
}
}

return output;
}

function runSalam() {
console.log('Running Salam code...');
const code = codeTextArea.value.toString().trim();

if (!code) {
alert('Code is empty! Please enter Salam code.');
return;
}

args[1] = code;
console.log('Calling Salam with arguments:', args);

if (isReady) {
captureOutput(args);
} else {
console.log('Salam runtime not ready. Please wait...');
}
}

executeButton.addEventListener('click', () => {
console.log('Button clicked!');
runSalam();
});

codeTextArea.addEventListener('keydown', (e) => {
if (e.key === 'Tab') {
e.preventDefault();
const start = codeTextArea.selectionStart;
const end = codeTextArea.selectionEnd;

codeTextArea.value = codeTextArea.value.substring(0, start) + ' ' + codeTextArea.value.substring(end);

codeTextArea.selectionStart = codeTextArea.selectionEnd = start + 4;
}
});

const script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'salam-wa.js';
document.body.appendChild(script);
</script>
</body>

</html>
37 changes: 0 additions & 37 deletions salam-online.html

This file was deleted.

Loading

0 comments on commit e84610e

Please sign in to comment.