some improvements to vi

This commit is contained in:
Lisa Milne 2023-12-05 20:04:33 +10:00
parent 777dac8bfc
commit bbf92c58ec
2 changed files with 35 additions and 15 deletions

View file

@ -968,14 +968,6 @@ clite.io = {
return vfsapi.mkFile(uid,path);
}
}
// TODO: get rid of this
//clite.io.open = function(pid,path,cb,open_link) {
//if (typeof cb === 'undefined')
//cb = false;
//if (typeof open_link === 'undefined')
//open_link = false;
//return getFileDes(pid,path,open_link,cb);
//}
clite.io.open = function(pid,path,flags,cb) {
var read = false;
var write = false;
@ -2018,8 +2010,13 @@ clite.term = {
},
keyup:function(e) {
if (clite.term.data.isalt && clite.term.data.alt.israwIn) {
if (clite.term.data.handler != null)
clite.term.data.handler(e.key);
if (clite.term.data.handler != null) {
if (e.key == 'Tab') {
clite.term.data.handler('\t');
}else{
clite.term.data.handler(e.key);
}
}
if (!clite.term.data.alt.echo) {
e.target.value = '';
clite.term.data.buff = '';

View file

@ -13,6 +13,7 @@ clite.commands.load('vi',function(args,env,io) {
var cursor_col = 0;
var changed = false;
var num = false;
var message = '';
function help() {
stdio.printf(`
@ -85,6 +86,8 @@ Options:
if (cursor_col == 0) {
curses.printw('% 4d%c%s\n',i+1,cursor,lines[i][0]);
}else{
if (cursor_col > 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);
@ -101,6 +104,8 @@ Options:
if (cursor_col == 0) {
curses.printw('%c%s\n',cursor,lines[i][0]);
}else{
if (cursor_col > 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);
@ -111,6 +116,7 @@ Options:
}
}
}
curses.printw('%s\t\t\t\t\t\t%d,%d\n',message,cursor_line,cursor_col);
}
function prepFile(fd) {
@ -191,10 +197,14 @@ Options:
changed = false;
}
if (quit && (!changed || force)) {
curses.endwin();
io.exit(0);
return false;
if (quit) {
if (!changed || force) {
curses.endwin();
io.exit(0);
return false;
}else{
message = 'no write since last change (add ! to override)';
}
}
return true;
@ -257,13 +267,14 @@ Options:
curses.initscr();
cols = curses.getmaxx();
rows = curses.getmaxy();
rows = curses.getmaxy()-2;
curses.cbreak();
curses.noecho();
curses.printw('Loading...');
function input(key) {
if (mode == 0) { // view mode
//message = '';
switch (key) {
case 'Up':
case 'ArrowUp':
@ -284,28 +295,37 @@ Options:
case 'i':
curses.noecho();
mode = 2;
message = 'INSERT';
showAt(topLine);
break;
case 'a':
cursor_col = lines[cursor_line].length;
curses.noecho();
mode = 2;
message = 'INSERT';
showAt(topLine);
break;
case ':':
curses.echo();
term.ttyctrl('iset',':');
cmd_buff = ':';
mode = 1;
showAt(topLine);
break;
}
}else if (mode == 1) { // command mode
//message = '';
switch (key) {
case 'Escape':
mode = 0;
cmd_buff = '';
curses.noecho();
showAt(topLine);
break;
case 'Enter':
if (!doCommand(cmd_buff))
return;
showAt(topLine);
cmd_buff = '';
term.ttyctrl('iset','');
break;
@ -315,10 +335,13 @@ Options:
break;
}
}else{ // 2 edit mode
message = 'INSERT';
switch (key) {
case 'Escape':
mode = 0;
curses.noecho();
message = '';
showAt(topLine);
break;
case 'Up':
case 'ArrowUp':