Improved examples
This commit is contained in:
61
index.html
61
index.html
@@ -513,7 +513,7 @@ function Client () {
|
||||
this.acels.set('View', 'Toggle Commander', 'CmdOrCtrl+K', () => { this.commander.toggle() })
|
||||
this.acels.set('View', 'Expand Commander', 'CmdOrCtrl+Shift+K', () => { this.commander.toggle(true) })
|
||||
this.acels.set('Project', 'Run', 'CmdOrCtrl+R', () => { this.commander.run() })
|
||||
this.acels.set('Project', 'Re-Indent', 'CmdOrCtrl+Shift+I', () => { this.commander.reindent() })
|
||||
this.acels.set('Project', 'Re-Indent', 'CmdOrCtrl+Shift+I', () => { this.commander.lint() })
|
||||
this.acels.set('Project', 'Clean', 'Escape', () => { this.commander.cleanup() })
|
||||
this.acels.route(this)
|
||||
}
|
||||
@@ -725,7 +725,7 @@ function Commander (client) {
|
||||
}
|
||||
this.cleanup = function () {
|
||||
this._input.value = this.clean(this._input.value)
|
||||
this.reindent()
|
||||
this.lint()
|
||||
this.run()
|
||||
}
|
||||
this.update = function () {
|
||||
@@ -736,30 +736,6 @@ function Commander (client) {
|
||||
this.onClick = () => {
|
||||
this.setStatus()
|
||||
}
|
||||
this.reindent = function () {
|
||||
let val = this._input.value.replace(/\n/g, '').replace(/ \)/g, ')').replace(/ +(?= )/g, '').replace(/\( \(/g, '((').replace(/\) \)/g, '))').trim()
|
||||
let depth = 0
|
||||
if (val.split('(').length !== val.split(')').length) {
|
||||
client.log('Uneven number of parens.')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < val.length; i++) {
|
||||
const c = val.charAt(i)
|
||||
if (c === '(') { depth++ } else if (c === ')') { depth-- }
|
||||
if (c === ';') {
|
||||
const indent = '\n' + (' '.repeat(depth))
|
||||
val = insert(val, indent, i)
|
||||
i += indent.length
|
||||
}
|
||||
if (c === '(') {
|
||||
const indent = '\n' + (' '.repeat(depth - 1))
|
||||
val = insert(val, indent, i)
|
||||
i += indent.length
|
||||
}
|
||||
}
|
||||
val = val.split('\n').map((line) => { return line.substr(0, 2) === '; ' ? `\n${line}\n` : line }).join('\n')
|
||||
this._input.value = val.trim()
|
||||
}
|
||||
this.clean = function (input) {
|
||||
const keywords = ['$pos+', '$pos', '$rect', '$line', '$x', '$y', '$xy']
|
||||
for (const word of keywords) {
|
||||
@@ -876,6 +852,36 @@ function Commander (client) {
|
||||
const fnParams = fnString.split(') => {')[0].substr(1).split(',').reduce((acc, item) => { return `${acc}${item.indexOf('=') > -1 ? '~' + item.split('=')[0].trim() : item} ` }, '').trim()
|
||||
return `(${(name + ' ' + fnParams).trim()})`
|
||||
}
|
||||
this.lint = function () {
|
||||
let val = this._input.value.replace(/\n/g, '').replace(/ \)/g, ')').replace(/ +(?= )/g, '').replace(/\( \(/g, '((').replace(/\) \)/g, '))').trim()
|
||||
let depth = 0
|
||||
if (val.split('(').length !== val.split(')').length) {
|
||||
client.log('Uneven number of parens.')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < val.length; i++) {
|
||||
const c = val.charAt(i)
|
||||
if (c === '(') { depth++ } else if (c === ')') { depth-- }
|
||||
if (c === ';') {
|
||||
const indent = '\n' + (' '.repeat(depth))
|
||||
val = insert(val, indent, i)
|
||||
i += indent.length
|
||||
}
|
||||
if (c === '(') {
|
||||
const indent = '\n' + (' '.repeat(depth - 1))
|
||||
val = insert(val, indent, i)
|
||||
i += indent.length
|
||||
}
|
||||
if (c === ')' && depth === 0) {
|
||||
val = insert(val, '\n', i + 1)
|
||||
}
|
||||
}
|
||||
val = val.split('\n').map((line) => { return line.substr(0, 2) === '; ' ? `\n${line}\n` : line }).join('\n')
|
||||
this._input.value = val.trim()
|
||||
function insert (str, add, i) {
|
||||
return [str.slice(0, i), `${add}`, str.slice(i)].join('')
|
||||
}
|
||||
}
|
||||
this.splash = `; Ronin v2.50
|
||||
(def logo-path "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ")
|
||||
;
|
||||
@@ -883,9 +889,6 @@ function Commander (client) {
|
||||
(resize 600 600)
|
||||
(stroke
|
||||
(svg 140 140 logo-path) "black" 7)`
|
||||
function insert (str, add, i) {
|
||||
return [str.slice(0, i), `${add}`, str.slice(i)].join('')
|
||||
}
|
||||
}
|
||||
'use strict'
|
||||
function Lisp (lib = {}) {
|
||||
|
||||
Reference in New Issue
Block a user