diff --git a/clite/bios.js b/clite/bios.js index 8e2d4b6..d4531ff 100644 --- a/clite/bios.js +++ b/clite/bios.js @@ -291,6 +291,23 @@ bios.video.text = { c.data.bk = id; c.className = bios.video.text.internal.dataToClass(c.data); }, + setCursor:function(x,y,enabled) { + if (typeof enabled !== 'boolean') + return; + var c = document.getElementById('vga-cursor'); + if (!c) + return; + c.data.x = x; + c.data.y = y; + c.data.enabled = enabled; + if (!enabled) { + c.style.display = 'none'; + return; + } + c.style.display = 'block'; + c.style.top = (y*bios.video.text.data.screen.nh)+'px'; + c.style.left = (x*bios.video.text.data.screen.nw)+'px'; + }, writeSet:function(name,x,y,id) { if (x < 0 || x > 79 || y < 0 || y > 24) return; @@ -304,6 +321,9 @@ bios.video.text = { case 2: bios.video.text.io.setBlink(x,y,id); break; + case 3: + bios.video.text.io.setCursor(x,y,id); + break; default:; } } @@ -335,11 +355,29 @@ bios.video.text = { c.style.left = (x*xpx)+'px'; c.style.width = xpx+'px'; c.style.height = ypx+'px'; + c.style.zIndex = '5'; c.data = {bg:'0',fg:'F',bk:false}; c.id = 'vga-'+y+'-'+x; bios.video.text.data.el.appendChild(c); } } + // the cursor + var c = document.createElement('div'); + c.className = 'vga-cursor vga-blink vga-bt vga-fF'; + c.style.position = 'absolute'; + c.style.top = '0px'; + c.style.left = '0px'; + c.style.width = xpx+'px'; + c.style.height = ypx+'px'; + c.style.zIndex = '10'; + c.id = 'vga-cursor'; + c.textContent = '_'; + c.data = {}; + c.data.x = x; + c.data.y = y; + c.data.enabled = false; + bios.video.text.data.el.appendChild(c); + bios.video.text.resize(); bios.video.text.data.isinit = true; return bios.video.text.data.isinit; @@ -378,6 +416,14 @@ bios.video.text = { c.style.fontSize = bios.video.text.data.screen.f+'px'; } } + var c = document.getElementById('vga-cursor'); + if (c) { + c.style.top = (y*bios.video.text.data.screen.nh)+'px'; + c.style.left = (x*bios.video.text.data.screen.nw)+'px'; + c.style.width = bios.video.text.data.screen.nw+'px'; + c.style.height = bios.video.text.data.screen.nh+'px'; + c.style.fontSize = bios.video.text.data.screen.f+'px'; + } } }; diff --git a/clite/core.css b/clite/core.css index a9d7fa8..2536288 100644 --- a/clite/core.css +++ b/clite/core.css @@ -28,6 +28,7 @@ div span {margin:0; padding:0; border:0;} .vga-fE {color:#FFFF55;} .vga-fF {color:#FFFFFF;} +.vga-bt {background-color:transparent;} .vga-b0 {background-color:#000000;} .vga-b1 {background-color:#0000AA;} .vga-b2 {background-color:#00AA00;} diff --git a/clite/core.js b/clite/core.js index d991094..53db1f0 100644 --- a/clite/core.js +++ b/clite/core.js @@ -2499,6 +2499,8 @@ clite.tty = { t.x = x; if (y > -1 && y < 25) t.y = y; + if (id == clite.tty.data.activeID) + clite.console.setCursor(x,y); } }; @@ -2507,7 +2509,7 @@ clite.console = { vgaio:null, state:0, size:[80,25], - cursor:[0,0,0,0] + cursor:[0,0] }, init:function() { // set graphics to text mode, and get the VGA api @@ -2564,20 +2566,11 @@ clite.console = { } }, moveCursor:function() { - if ( - clite.console.data.cursor[0] == clite.console.data.cursor[2] - && clite.console.data.cursor[1] == clite.console.data.cursor[3] - ) - return; - clite.console.data.vgaio.writeSet(2,clite.console.data.cursor[0],clite.console.data.cursor[1],false); - clite.console.data.cursor[0] = clite.console.data.cursor[2]; - clite.console.data.cursor[1] = clite.console.data.cursor[3]; - //clite.console.data.vgaio.write(clite.console.data.cursor[0],clite.console.data.cursor[1],'_'); - clite.console.data.vgaio.writeSet(2,clite.console.data.cursor[0],clite.console.data.cursor[1],true); + clite.console.data.vgaio.writeSet(3,clite.console.data.cursor[0],clite.console.data.cursor[1],true); }, setCursor:function(x,y) { - clite.console.data.cursor[2] = x; - clite.console.data.cursor[3] = y; + clite.console.data.cursor[0] = x; + clite.console.data.cursor[1] = y; clite.console.moveCursor(); }, read:function() { diff --git a/clite/vi.js b/clite/vi.js index abfcc57..e3b79d0 100644 --- a/clite/vi.js +++ b/clite/vi.js @@ -20,6 +20,38 @@ clite.commands.load('vi',function(args,env,io) { var topLine = 0; var bottomLine = 0; + const VIMODE_VIEW = 0; + const VIMODE_CMD = 1; + const VIMODE_EDIT = 2; + + function switchMode(m) { + if (m == mode) + return; + switch (m) { + case VIMODE_CMD: + mode = 1; + curses.echo(); + curses.move(rows-1,0); + curses.printw(':'); + cmd_buff = ':'; + showAt(topLine); + break; + case VIMODE_EDIT: + mode = 2; + curses.noecho(); + message = 'INSERT'; + showAt(topLine); + break; + case VIMODE_VIEW: + default: + mode = 0; + cmd_buff = ''; + curses.noecho(); + showAt(topLine); + break; + } + } + function help() { stdio.printf(` vi - Visual text file editor @@ -78,41 +110,20 @@ Options: if (end > lines.length) end = lines.length; curses.clear(); + var cursor_screen = [0,cursor_col+1]; + var k = 0; if (num) { - for (var i=start; i lines[i][0].length) - cursor_col = lines[i][0].length; - var l = lines[i][0]; - var b = l.substring(0,cursor_col); - var e = l.substring(cursor_col); - curses.printw('% 4d %s%c%s\n',i+1,b,cursor,e); - } - }else{ - curses.printw('% 4d %s\n',i+1,lines[i][0]); - } + cursor_screen[1] += 4; + for (var i=start; i lines[i][0].length) - cursor_col = lines[i][0].length; - var l = lines[i][0]; - var b = l.substring(0,cursor_col); - var e = l.substring(cursor_col); - curses.printw(' %s%c%s\n',b,cursor,e); - } - }else{ - curses.printw(' %s\n',lines[i][0]); - } + for (var i=start; i 0) { cmd_buff = cmd_buff.substring(0,cmd_buff.length-1); showAt(topLine); + if (!cmd_buff.length) + switchMode(VIMODE_VIEW); } break; default: @@ -347,10 +348,8 @@ Options: message = 'INSERT'; switch (key) { case curses.key.KEY_ESCAPE: - mode = 0; - curses.noecho(); message = ''; - showAt(topLine); + switchMode(VIMODE_VIEW); break; case curses.key.KEY_UP: cursorUp();