diff options
Diffstat (limited to 'desktop/sources/scripts')
-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 |
3 files changed, 24 insertions, 6 deletions
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) => { |