Skip to content
Permalink
Browse files

Added queue tools

  • Loading branch information...
neauoire committed May 23, 2019
1 parent c470d0e commit 563263b7862ad7f32df70f216c183a3f69aa0885
@@ -15,6 +15,15 @@ export default function Commander (terminal) {
if (isColor(parts[1])) { terminal.theme.active.b_inv = '#' + parts[1] }
if (isColor(parts[2])) { terminal.theme.active.b_high = '#' + parts[2] }
},
'erase': (val, run) => { terminal.cursor.erase() },
'select': (val, run) => {
const rect = val.split(';')
const x = rect[0] ? parseInt(rect[0]) : terminal.cursor.x
const y = rect[1] ? parseInt(rect[1]) : terminal.cursor.y
const w = rect[2] ? parseInt(rect[2]) : terminal.cursor.w
const h = rect[3] ? parseInt(rect[3]) : terminal.cursor.h
terminal.cursor.select(x, y, w, h)
},
'find': (val, run) => { terminal.cursor.find(val) },
'move': (val, run) => {
const pos = val.split(';')
@@ -45,10 +54,10 @@ export default function Commander (terminal) {
'stop': (val, run) => { if (run) { terminal.clock.stop() } },
'time': (val, run) => { terminal.clock.setFrame(parseInt(val)) },
'write': (val, run) => {
const g = val.substr(0, 1)
const pos = val.substr(1).split(';')
const x = pos[0] ? parseInt(pos[0]) : terminal.cursor.x
const y = pos[1] ? parseInt(pos[1]) : terminal.cursor.y
const pos = val.split(';')
const g = pos[0].substr(0,1)
const x = pos[1] ? parseInt(pos[1]) : terminal.cursor.x
const y = pos[2] ? parseInt(pos[2]) : terminal.cursor.y
if (!isNaN(x) && !isNaN(y) && g) {
terminal.orca.write(x, y, g)
}
@@ -95,6 +104,7 @@ export default function Commander (terminal) {
const cmd = `${msg}`.split(':')[0].toLowerCase()
const val = `${msg}`.substr(cmd.length + 1)
if (!this.operations[cmd]) { console.warn(`Unknown message: ${msg}`); return }
console.info('Commander', msg)
this.operations[cmd](val, true)
this.stop()
}
@@ -31,6 +31,13 @@ export default function Cursor (terminal) {
terminal.update()
}

this.scaleTo = function (w, h) {
if (isNaN(w) || isNaN(h)) { return }
this.w = clamp(w, 0, terminal.orca.w - 1)
this.h = clamp(h, 0, terminal.orca.h - 1)
terminal.update()
}

this.resize = function (w, h) {
if (isNaN(w) || isNaN(h)) { return }
this.w = clamp(w, 1, terminal.orca.w - this.x)
@@ -66,6 +73,13 @@ export default function Cursor (terminal) {
terminal.update()
}

this.select = function (x, y, w, h) {
console.log(x, y, w, h)
this.moveTo(x, y)
this.scaleTo(w, h)
terminal.update()
}

this.copy = function () {
const block = this.getBlock()
var rows = []
@@ -96,7 +110,7 @@ export default function Cursor (terminal) {
terminal.history.record(terminal.orca.s)
}

this.erase = function (key) {
this.erase = function () {
this.eraseBlock(this.x, this.y, this.w, this.h)
if (this.mode === 1) { this.move(-1, 0) }
terminal.history.record(terminal.orca.s)
@@ -6,6 +6,7 @@ export default function Source (terminal) {
const { dialog, app } = require('electron').remote

this.path = null
this.queue = []

this.start = function () {
this.increment()
@@ -15,6 +16,7 @@ export default function Source (terminal) {
this.new = function () {
console.log('Source', 'Make a new file..')
this.path = null
this.queue = []
terminal.orca.reset()
terminal.resize()
terminal.history.reset()
@@ -85,9 +87,24 @@ export default function Source (terminal) {
if (!fs.existsSync(loc)) { console.warn('Source', 'File does not exist: ' + loc); return }
console.log('Source', 'Reading ' + loc)
this.path = loc
this.remember('active', loc)
this.remember('active', this.path)
this.load(fs.readFileSync(this.path, 'utf8'))

// Look for queue
const queue = path.join(this.folder(), 'queue.orca')
if (fs.existsSync(queue)) {
this.queue = fs.readFileSync(queue, 'utf8').split('\n')
terminal.clock.resetFrame()
console.log('Source', `Found Queue: ${this.queue.length} lines`)
}
}

const data = fs.readFileSync(loc, 'utf8')
this.run = function () {
if (!this.queue || this.queue.length < terminal.orca.f || !this.queue[terminal.orca.f]) { return }
terminal.commander.trigger(this.queue[terminal.orca.f])
}

this.load = function (data) {
const lines = data.split('\n').map((line) => { return clean(line) })
const w = lines[0].length
const h = lines.length
@@ -182,14 +199,6 @@ export default function Source (terminal) {
return `${orca}`
}

this.parse = function (text) {
const lines = text.split('\n').map((line) => { return clean(line) })
const w = lines[0].length
const h = lines.length
const s = lines.join('\n').trim()
return terminal.orca.load(w, h, s)
}

this.locate = function (name) {
if (!this.path) { return }
const loc = path.join(this.folder(), name)
@@ -61,6 +61,7 @@ export default function Terminal () {
this.run = function () {
this.io.clear()
this.clock.run()
this.source.run()
this.orca.run()
this.io.run()
this.update()

0 comments on commit 563263b

Please sign in to comment.
You can’t perform that action at this time.