diff options
-rw-r--r-- | desktop/core/lib/g.js | 1 | ||||
-rw-r--r-- | desktop/core/lib/i.js | 1 | ||||
-rw-r--r-- | desktop/core/lib/j.js | 4 | ||||
-rw-r--r-- | desktop/core/lib/k.js | 1 | ||||
-rw-r--r-- | desktop/core/lib/l.js | 4 | ||||
-rw-r--r-- | desktop/core/lib/p.js | 1 | ||||
-rw-r--r-- | desktop/core/lib/q.js | 3 | ||||
-rw-r--r-- | desktop/core/pico.js | 5 | ||||
-rw-r--r-- | desktop/sources/scripts/cursor.js | 17 | ||||
-rw-r--r-- | desktop/sources/scripts/keyboard.js | 1 | ||||
-rw-r--r-- | desktop/sources/scripts/terminal.js | 12 |
11 files changed, 32 insertions, 18 deletions
diff --git a/desktop/core/lib/g.js b/desktop/core/lib/g.js index 139b7e1..3d75670 100644 --- a/desktop/core/lib/g.js +++ b/desktop/core/lib/g.js @@ -9,7 +9,6 @@ function FnG (pico, x, y, passive) { this.name = 'generator' this.glyph = 'g' this.info = 'Generates a direction fn from bang.' - this.ports.push({ x: 0, y: 0, bang: true }) this.operation = function () { const bang = this.bang() diff --git a/desktop/core/lib/i.js b/desktop/core/lib/i.js index 2c0db3d..63496ce 100644 --- a/desktop/core/lib/i.js +++ b/desktop/core/lib/i.js @@ -9,7 +9,6 @@ function FnI (pico, x, y, passive) { this.name = 'increment' this.glyph = 'i' this.info = 'Increments southward numeric fn on bang.' - this.ports.push({ x: 0, y: 0, bang: true }) this.ports.push({ x: 0, y: 1, output: true }) this.ports.push({ x: 1, y: 0, input: true }) this.ports.push({ x: -1, y: 0, input: true }) diff --git a/desktop/core/lib/j.js b/desktop/core/lib/j.js index 3b4978f..f94dc5c 100644 --- a/desktop/core/lib/j.js +++ b/desktop/core/lib/j.js @@ -13,9 +13,7 @@ function FnJ (pico, x, y, passive) { this.operation = function () { const n = this.north() - if (!n) { return } - - pico.add(this.x, this.y + 1, n.glyph) + pico.add(this.x, this.y + 1, !n ? '.' : n.glyph) pico.lock(this.x, this.y + 1) } } diff --git a/desktop/core/lib/k.js b/desktop/core/lib/k.js index fea0917..a8c0cd2 100644 --- a/desktop/core/lib/k.js +++ b/desktop/core/lib/k.js @@ -9,7 +9,6 @@ function FnK (pico, x, y, passive) { this.name = 'kill' this.glyph = 'k' this.info = 'Kills southward fns, on bang.' - this.ports.push({ x: 0, y: 0, bang: true }) this.ports.push({ x: 0, y: 1, output: true }) this.operation = function () { diff --git a/desktop/core/lib/l.js b/desktop/core/lib/l.js index e97ad94..df67b74 100644 --- a/desktop/core/lib/l.js +++ b/desktop/core/lib/l.js @@ -9,7 +9,7 @@ function FnL (pico, x, y, passive) { this.name = 'loop' this.glyph = 'l' this.info = 'Loop a number of characters ahead.' - this.ports = [{ x: 0, y: 0, bang: true }, { x: -1, y: 0, input: true }] + this.ports.push({ x: -1, y: 0, input: true }) if (pico) { this.w = this.west() @@ -26,7 +26,7 @@ function FnL (pico, x, y, passive) { } this.operation = function () { - if (!this.len || this.len < 1 || !this.bang()) { return } + if (!this.len || this.len < 1) { return } const a = [] for (let x = 1; x <= this.len; x++) { diff --git a/desktop/core/lib/p.js b/desktop/core/lib/p.js index e018c6b..0a5e66f 100644 --- a/desktop/core/lib/p.js +++ b/desktop/core/lib/p.js @@ -9,7 +9,6 @@ function FnP (pico, x, y, passive) { this.name = 'push' this.glyph = 'p' this.info = 'Moves away, on bang.' - this.ports.push({ x: 0, y: 0, bang: true }) this.operation = function () { const origin = this.bang() diff --git a/desktop/core/lib/q.js b/desktop/core/lib/q.js index 5324dc3..8c2f521 100644 --- a/desktop/core/lib/q.js +++ b/desktop/core/lib/q.js @@ -3,7 +3,7 @@ const FnBase = require('./_base') function FnQ (pico, x, y, passive) { - FnBase.call(this, pico, x, y, passive) + FnBase.call(this, pico, x, y, true) this.name = 'query' this.glyph = ':' @@ -28,6 +28,7 @@ function FnQ (pico, x, y, passive) { } this.run = function () { + if (!this.bang()) { return } if (!this.query) { pico.terminal.log(`Unknown query <${this.cmd}>`); return } if (this.cmd.indexOf('.') > -1) { return } this.query.run() diff --git a/desktop/core/pico.js b/desktop/core/pico.js index 533a81e..918070d 100644 --- a/desktop/core/pico.js +++ b/desktop/core/pico.js @@ -17,8 +17,9 @@ function Pico (w, h) { function makeDocs (lib) { const h = {} for (const id in lib) { - const P = new lib[id]() - h[P.glyph] = P.docs() + const fn = new lib[id]() + if (fn.type === 'misc') { continue } + h[fn.glyph] = fn.docs() } return h } diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js index 8316c8c..0bc5d1e 100644 --- a/desktop/sources/scripts/cursor.js +++ b/desktop/sources/scripts/cursor.js @@ -10,6 +10,8 @@ function Cursor (terminal) { this.block = [] + this.mode = 0 + this.move = function (x, y) { this.x = clamp(this.x + x, 0, pico.w - 1) this.y = clamp(this.y - y, 0, pico.h - 1) @@ -25,6 +27,7 @@ function Cursor (terminal) { this.reset = function () { this.w = 1 this.h = 1 + this.mode = 0 } this.copy = function () { @@ -45,6 +48,9 @@ function Cursor (terminal) { this.insert = function (g) { pico.add(this.x, this.y, g) + if (this.mode === 1) { + this.move(1, 0) + } } this.erase = function (g) { @@ -54,13 +60,22 @@ function Cursor (terminal) { this.inspect = function () { const g = pico.glyphAt(this.x, this.y) - return pico.docs[g] ? pico.docs[g] : this._position() + return pico.docs[g] ? pico.docs[g] : this._position() + this._mode() } this._position = function () { return `${this.x},${this.y}` + (this.w !== 1 || this.h !== 1 ? `[${this.w}x${this.h}]` : '') } + this._mode = function () { + return this.mode !== 0 ? `<${this.mode === 1 ? 'insert' : 'default'}>` : '' + } + + this.toggleMode = function () { + this.mode = this.mode === 0 ? 1 : 0 + this.terminal.log(`Changed Mode ${this.mode === 1 ? 'insert' : 'default'}`) + } + function clamp (v, min, max) { return v < min ? min : v > max ? max : v } } diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js index f786e4b..59caa17 100644 --- a/desktop/sources/scripts/keyboard.js +++ b/desktop/sources/scripts/keyboard.js @@ -30,6 +30,7 @@ function Keyboard () { if (event.metaKey) { return } if (event.ctrlKey) { return } + if (event.key === 'Enter') { terminal.cursor.toggleMode(); return } if (event.key === 'Backspace') { terminal.cursor.erase(); return } if (event.key === ' ') { terminal.pause(); event.preventDefault(); return } if (event.key === 'Escape') { terminal.clear(); terminal.isPaused = false; terminal.cursor.reset(); return } diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js index a7b1199..5182b98 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -12,7 +12,7 @@ function Terminal (pico) { this.pico = pico this.el = document.createElement('canvas') this.isPaused = false - this.tile = { w: 12, h: 20 } + this.tile = { w: 20, h: 30 } this.debug = 'hello.' this.timer = null @@ -45,7 +45,6 @@ function Terminal (pico) { this.run = function () { if (this.isPaused) { return } - this.debug = 'Idle.' this.qqq.clear() this.clear() @@ -180,7 +179,7 @@ function Terminal (pico) { ctx.textBaseline = 'bottom' ctx.textAlign = 'center' - ctx.font = `${this.tile.h * 0.75}px input_mono_regular` + ctx.font = `${this.tile.h * 0.75}px input_mono_medium` if (styles.isSelection) { ctx.fillStyle = this.theme.active.b_inv @@ -211,7 +210,7 @@ function Terminal (pico) { } this.resize = function () { - this.size = { width: this.tile.w * pico.w, height: this.tile.h * pico.h + (this.tile.h * 3), ratio: 0.75 } + this.size = { width: this.tile.w * pico.w, height: this.tile.h * pico.h + (this.tile.h * 3), ratio: 0.5 } this.el.width = this.size.width this.el.height = this.size.height + this.tile.h this.el.style.width = (this.size.width * this.size.ratio) + 'px' @@ -220,7 +219,10 @@ function Terminal (pico) { let { remote } = require('electron') let win = remote.getCurrentWindow() - win.setSize((this.size.width * this.size.ratio) + 60, (this.size.height * this.size.ratio) + 30, true) + const width = parseInt((this.size.width * this.size.ratio) + 60) + const height = parseInt((this.size.height * this.size.ratio) + 30) + + win.setSize(width, height, true) } window.onresize = (event) => { |