mirror of
https://github.com/flynx/Slang.git
synced 2025-10-29 10:40:07 +00:00
added several tools to the Slang console...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
c725c089d4
commit
58ae635ded
@ -65,6 +65,18 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
function stringifySlangCode(code){
|
||||||
|
if(code.constructor.name == 'Array'){
|
||||||
|
return '[ '+code.map(function(c){
|
||||||
|
if(c.constructor.name == 'Array'){
|
||||||
|
return stringifySlangCode(c)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}).join(' ')+' ]'
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
|
||||||
function runCommand(){
|
function runCommand(){
|
||||||
var stack = document.getElementById('stack')
|
var stack = document.getElementById('stack')
|
||||||
var console = document.getElementById('console')
|
var console = document.getElementById('console')
|
||||||
@ -80,7 +92,7 @@ function runCommand(){
|
|||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
try{
|
try{
|
||||||
stack.innerText = 'stack: ' + slang(command.innerText)
|
stack.innerText = 'stack: ' + stringifySlangCode(slang(command.innerText))
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
stack.innerText = 'stack: ' + CONTEXT.stack
|
stack.innerText = 'stack: ' + CONTEXT.stack
|
||||||
@ -139,6 +151,22 @@ function toggleBootstrapCode(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showAvailableWords(){
|
||||||
|
document.getElementById('words').innerHTML = Object.keys(NAMESPACE).filter(function(e){
|
||||||
|
// skip words starting with '_'...
|
||||||
|
if(e[0] == '_'){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}).map(function(e){
|
||||||
|
var code = NAMESPACE[e]
|
||||||
|
if(code.constructor.name == 'Array'){
|
||||||
|
code = stringifySlangCode(code)
|
||||||
|
}
|
||||||
|
return '<span title="'+code+'">'+e+'</span>'
|
||||||
|
}).join(', ')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -146,6 +174,8 @@ function toggleBootstrapCode(){
|
|||||||
<h1>Slang</h1>
|
<h1>Slang</h1>
|
||||||
<a href="#" onclick="toggleBootstrapCode()">Toggle bootstrap code view...</a>
|
<a href="#" onclick="toggleBootstrapCode()">Toggle bootstrap code view...</a>
|
||||||
<div id="bootstrap"></div>
|
<div id="bootstrap"></div>
|
||||||
|
<h2>Available words</h2>
|
||||||
|
<p id="words"></p>
|
||||||
<h2>Slang Console</h2>
|
<h2>Slang Console</h2>
|
||||||
<div id="console">
|
<div id="console">
|
||||||
<div class="command" contenteditable="true"></div>
|
<div class="command" contenteditable="true"></div>
|
||||||
@ -162,8 +192,11 @@ document.getElementById('console')
|
|||||||
.addEventListener("keyup", function(e) {
|
.addEventListener("keyup", function(e) {
|
||||||
if(e.keyCode == 13 && e.ctrlKey){
|
if(e.keyCode == 13 && e.ctrlKey){
|
||||||
runCommand()
|
runCommand()
|
||||||
|
showAvailableWords()
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
showAvailableWords()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user