mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
get vi cursor working right
This commit is contained in:
parent
662f4b736a
commit
aac0fd25af
2 changed files with 22 additions and 6 deletions
|
|
@ -156,6 +156,14 @@ return Object.create({
|
|||
ptry.value = this.size.rows;
|
||||
return true;
|
||||
},
|
||||
getyx:function() {
|
||||
if (!this.isinit)
|
||||
return false;
|
||||
var c = clite.tty.getCursor(this.ctty);
|
||||
if (!Array.isArray(c))
|
||||
return [0,0];
|
||||
return [c[1],c[0]];
|
||||
},
|
||||
|
||||
move:function(y,x) {
|
||||
if (!this.isinit)
|
||||
|
|
|
|||
20
clite/vi.js
20
clite/vi.js
|
|
@ -85,10 +85,12 @@ Options:
|
|||
var s = -1;
|
||||
var disp = '';
|
||||
var rows = 0;
|
||||
var done = false;
|
||||
for (var i=0; i<line.length; i++) {
|
||||
if (i == cursor_col) {
|
||||
cursor_line_real = rows;
|
||||
cursor_col_real = cl;
|
||||
done = true;
|
||||
}
|
||||
if (cl > cols) {
|
||||
var b = '';
|
||||
|
|
@ -131,6 +133,10 @@ Options:
|
|||
cl++;
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
cursor_line_real = rows;
|
||||
cursor_col_real = cl;
|
||||
}
|
||||
curses.addstr(disp+'\n');
|
||||
}
|
||||
|
||||
|
|
@ -144,15 +150,15 @@ Options:
|
|||
if (end > lines.length)
|
||||
end = lines.length;
|
||||
curses.clear();
|
||||
var cursor_line_screen = 0;
|
||||
var k = 0;
|
||||
if (num) {
|
||||
cursor_screen[1] += 4;
|
||||
for (var i=start; i<end; i++,k++) {
|
||||
if (i == cursor_line) {
|
||||
cursor_line_screen = k;
|
||||
curses.printw('% 4d ',i+1);
|
||||
cursor_line_real = k;
|
||||
drawCursorLine(lines[i].real);
|
||||
if (cursor_line_real == k)
|
||||
cursor_col_real += 6;
|
||||
}else{
|
||||
curses.printw('% 4d %s\n',i+1,lines[i].disp);
|
||||
}
|
||||
|
|
@ -160,9 +166,11 @@ Options:
|
|||
}else{
|
||||
for (var i=start; i<end; i++,k++) {
|
||||
if (i == cursor_line) {
|
||||
cursor_line_screen = k;
|
||||
curses.addch(' ');
|
||||
cursor_line_real = k;
|
||||
drawCursorLine(lines[i].real);
|
||||
if (cursor_line_real == k)
|
||||
cursor_col_real += 1;
|
||||
}else{
|
||||
curses.printw(' %s\n',lines[i].disp);
|
||||
}
|
||||
|
|
@ -177,7 +185,7 @@ Options:
|
|||
if (cmd_buff != '')
|
||||
curses.printw('%s',cmd_buff);
|
||||
if (mode != VIMODE_CMD)
|
||||
curses.move(cursor_line_real+cursor_line_screen,cursor_col_real+1);
|
||||
curses.move(cursor_line_real,cursor_col_real);
|
||||
}
|
||||
|
||||
function prepLine(line) {
|
||||
|
|
@ -512,7 +520,7 @@ Options:
|
|||
}
|
||||
|
||||
curses.initscr();
|
||||
cols = curses.getmaxx();
|
||||
cols = curses.getmaxx()-8;
|
||||
rows = curses.getmaxy();
|
||||
curses.cbreak();
|
||||
curses.noecho();
|
||||
|
|
|
|||
Loading…
Reference in a new issue