diff options
-rw-r--r-- | desktop/core/pico.js | 31 | ||||
-rw-r--r-- | desktop/sources/scripts/cursor.js | 25 | ||||
-rw-r--r-- | desktop/sources/scripts/keyboard.js | 35 | ||||
-rw-r--r-- | desktop/sources/scripts/terminal.js | 7 |
4 files changed, 48 insertions, 50 deletions
diff --git a/desktop/core/pico.js b/desktop/core/pico.js index 5daeafd..4f4d0ff 100644 --- a/desktop/core/pico.js +++ b/desktop/core/pico.js @@ -124,15 +124,14 @@ function Pico (w, h) { // Blocks - this.getBlock = function(x,y,w,h) - { + this.getBlock = function (x, y, w, h) { let _y = y const block = [] - while(_y < y+h){ + while (_y < y + h) { let _x = x const line = [] - while(_x < x+w){ - line.push(this.glyphAt(_x,_y)) + while (_x < x + w) { + line.push(this.glyphAt(_x, _y)) _x++ } block.push(line) @@ -141,28 +140,26 @@ function Pico (w, h) { return block } - this.addBlock = function(x,y,block) - { - if(!block || block.length == 0){ this.terminal.log('Nothing to paste'); return; } - + this.addBlock = function (x, y, block) { + if (!block || block.length == 0) { this.terminal.log('Nothing to paste'); return } + let _y = y - for(const lineId in block){ + for (const lineId in block) { let _x = x - for(const glyphId in block[lineId]){ - this.add(_x,_y,block[lineId][glyphId]) + for (const glyphId in block[lineId]) { + this.add(_x, _y, block[lineId][glyphId]) _x++ } _y++ } } - this.removeBlock = function(x,y,w,h) - { + this.removeBlock = function (x, y, w, h) { let _y = y - while(_y < y+h){ + while (_y < y + h) { let _x = x - while(_x < x+w){ - this.remove(_x,_y) + while (_x < x + w) { + this.remove(_x, _y) _x++ } _y++ diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js index 67afb47..e2f893c 100644 --- a/desktop/sources/scripts/cursor.js +++ b/desktop/sources/scripts/cursor.js @@ -1,7 +1,6 @@ 'use strict' -function Cursor(terminal) -{ +function Cursor (terminal) { this.terminal = terminal this.x = 0 @@ -17,25 +16,31 @@ function Cursor(terminal) terminal.update() } - this.scale = function(x, y){ + this.scale = function (x, y) { this.w = clamp(this.w + x, 1, 30) this.h = clamp(this.h - y, 1, 30) terminal.update() } - this.reset = function(){ + this.reset = function () { this.w = 1 this.h = 1 } - this.copy = function(){ + this.copy = function () { this.terminal.log(`Copy ${this.x},${this.y}[${this.w}x${this.h}]`) - this.block = this.terminal.pico.getBlock(this.x,this.y,this.w,this.h) + this.block = this.terminal.pico.getBlock(this.x, this.y, this.w, this.h) } - this.paste = function(){ + this.paste = function () { this.terminal.log(`Paste ${this.x},${this.y}[${this.w}x${this.h}]`) - this.terminal.pico.addBlock(this.x,this.y,this.block) + this.terminal.pico.addBlock(this.x, this.y, this.block) + } + + this.cut = function () { + this.terminal.log(`Cut ${this.x},${this.y}[${this.w}x${this.h}]`) + this.copy() + this.erase() } this.insert = function (g) { @@ -44,7 +49,7 @@ function Cursor(terminal) this.erase = function (g) { this.terminal.log(`Erase ${this.x},${this.y}[${this.w}x${this.h}]`) - this.terminal.pico.removeBlock(this.x,this.y,this.w,this.h) + this.terminal.pico.removeBlock(this.x, this.y, this.w, this.h) } this.inspect = function () { @@ -55,4 +60,4 @@ function Cursor(terminal) function clamp (v, min, max) { return v < min ? min : v > max ? max : v } } -module.exports = Cursor
\ No newline at end of file +module.exports = Cursor diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js index 7824996..11465e9 100644 --- a/desktop/sources/scripts/keyboard.js +++ b/desktop/sources/scripts/keyboard.js @@ -20,6 +20,7 @@ function Keyboard () { if (event.key == 'c' && event.metaKey) { terminal.cursor.copy(); return } if (event.key == 'v' && event.metaKey) { terminal.cursor.paste(); return } + if (event.key == 'x' && event.metaKey) { terminal.cursor.cut(); return } if (event.keyCode == 38) { keyboard.key_arrow_up(event.shiftKey); return } if (event.keyCode == 40) { keyboard.key_arrow_down(event.shiftKey); return } @@ -43,38 +44,34 @@ function Keyboard () { } this.key_arrow_up = function (mod = false) { - if(mod){ + if (mod) { terminal.cursor.scale(0, 1) - } - else{ - terminal.cursor.move(0, 1) + } else { + terminal.cursor.move(0, 1) } } this.key_arrow_down = function (mod = false) { - if(mod){ - terminal.cursor.scale(0, -1) - } - else{ - terminal.cursor.move(0, -1) + if (mod) { + terminal.cursor.scale(0, -1) + } else { + terminal.cursor.move(0, -1) } } this.key_arrow_left = function (mod = false) { - if(mod){ - terminal.cursor.scale(-1, 0) - } - else{ - terminal.cursor.move(-1, 0) + if (mod) { + terminal.cursor.scale(-1, 0) + } else { + terminal.cursor.move(-1, 0) } } this.key_arrow_right = function (mod = false) { - if(mod){ - terminal.cursor.scale(1, 0) - } - else{ - terminal.cursor.move(1, 0) + if (mod) { + terminal.cursor.scale(1, 0) + } else { + terminal.cursor.move(1, 0) } } } diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js index ee0bd43..57ed064 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -1,10 +1,9 @@ 'use strict' function Terminal (pico) { - const Cursor = require('./cursor') - this.cursor = new Cursor(this); + this.cursor = new Cursor(this) this.controller = new Controller() this.theme = new Theme(this.theme = new Theme({ background: '#111111', f_high: '#ffffff', f_med: '#333333', f_low: '#000000', f_inv: '#000000', b_high: '#ffb545', b_med: '#72dec2', b_low: '#444444', b_inv: '#ffffff' })) @@ -142,11 +141,11 @@ function Terminal (pico) { } this.isCursor = function (x, y) { - return x === this.cursor.x && y ===this.cursor.y + return x === this.cursor.x && y === this.cursor.y } this.isSelection = function (x, y) { - if(x >= this.cursor.x && x < this.cursor.x + this.cursor.w && y >= this.cursor.y && y < this.cursor.y + this.cursor.h){ + if (x >= this.cursor.x && x < this.cursor.x + this.cursor.w && y >= this.cursor.y && y < this.cursor.y + this.cursor.h) { return true } return false |