mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
fix libcurses, get less working again
This commit is contained in:
parent
93a4885563
commit
140aff20a5
4 changed files with 62 additions and 31 deletions
|
|
@ -511,6 +511,26 @@ bios.input.keyboard = {
|
|||
k.lchar = k.char;
|
||||
k.code = -1;
|
||||
break;
|
||||
case 'PageUp':
|
||||
k.char = -7;
|
||||
k.lchr = k.char;
|
||||
k.code = -7;
|
||||
break;
|
||||
case 'PageDown':
|
||||
k.char = -8;
|
||||
k.lchr = k.char;
|
||||
k.code = -8;
|
||||
break;
|
||||
case 'Home':
|
||||
k.char = -9;
|
||||
k.lchr = k.char;
|
||||
k.code = -9;
|
||||
break;
|
||||
case 'End':
|
||||
k.char = -10;
|
||||
k.lchr = k.char;
|
||||
k.code = -10;
|
||||
break;
|
||||
default:
|
||||
k.code = key;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ Options:
|
|||
end = lines.length;
|
||||
curses.clear();
|
||||
for (var i=start; i<end; i++) {
|
||||
curses.printw(lines[i]+'\n');
|
||||
curses.printw("%s\n",lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -424,8 +424,8 @@ Options:
|
|||
|
||||
var parts = txt.split('\n');
|
||||
parts.forEach(function(line) {
|
||||
if (line.length > cols) {
|
||||
var sects = line.match(new RegExp('(.{1,'+cols+'})','g'));
|
||||
if (line.length >= cols) {
|
||||
var sects = line.match(new RegExp('(.{1,'+(cols-1)+'})','g'));
|
||||
lines.push.apply(lines,sects);
|
||||
return;
|
||||
}
|
||||
|
|
@ -462,27 +462,25 @@ Options:
|
|||
|
||||
function input(key) {
|
||||
switch (key) {
|
||||
case 'Escape':
|
||||
case 27:
|
||||
case 'q':
|
||||
curses.endwin();
|
||||
io.exit(0);
|
||||
return;
|
||||
break;
|
||||
case 'Up':
|
||||
case 'ArrowUp':
|
||||
case -4:
|
||||
if (topLine > 0) {
|
||||
topLine--;
|
||||
showAt(topLine);
|
||||
}
|
||||
break;
|
||||
case 'Down':
|
||||
case 'ArrowDown':
|
||||
case -3:
|
||||
if (topLine < bottomLine) {
|
||||
topLine++;
|
||||
showAt(topLine);
|
||||
}
|
||||
break;
|
||||
case 'PageUp':
|
||||
case -7:
|
||||
if (topLine > 0) {
|
||||
topLine -= rows-1;
|
||||
if (topLine < 0)
|
||||
|
|
@ -490,7 +488,7 @@ Options:
|
|||
showAt(topLine);
|
||||
}
|
||||
break;
|
||||
case 'PageDown':
|
||||
case -8:
|
||||
if (topLine < bottomLine) {
|
||||
topLine += rows-1;
|
||||
if (topLine >= bottomLine)
|
||||
|
|
@ -498,11 +496,11 @@ Options:
|
|||
showAt(topLine);
|
||||
}
|
||||
break;
|
||||
case 'Home':
|
||||
case -9:
|
||||
topLine = 0;
|
||||
showAt(topLine);
|
||||
break;
|
||||
case 'End':
|
||||
case -10:
|
||||
topLine = bottomLine;
|
||||
showAt(topLine);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -2474,6 +2474,12 @@ clite.tty = {
|
|||
t.echo = v;
|
||||
return t.echo;
|
||||
break;
|
||||
case 'cols':
|
||||
return t.data[0].length;
|
||||
break;
|
||||
case 'rows':
|
||||
return t.data.length;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@ clite.libs.load('libcurses','curses',function(io,env) {
|
|||
|
||||
return Object.create({
|
||||
|
||||
size:{
|
||||
rows:0,
|
||||
cols:0
|
||||
},
|
||||
ctty:0,
|
||||
isinit:false,
|
||||
types:{
|
||||
A_NULL:0,
|
||||
|
|
@ -22,56 +27,58 @@ return Object.create({
|
|||
// curses only works on a tty
|
||||
if (!clite.io.isatty(io.pid,io.stdin))
|
||||
return false;
|
||||
this.isinit = clite.term.ttyctrl('alt',true);
|
||||
// TODO: get the controlling tty id
|
||||
this.size.rows = clite.tty.ttyctrl(this.ctty,'rows');
|
||||
this.size.cols = clite.tty.ttyctrl(this.ctty,'cols');
|
||||
clite.tty.clear(this.ctty);
|
||||
this.isinit = true;
|
||||
},
|
||||
|
||||
endwin:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.ttyctrl('rawin',false);
|
||||
clite.term.ttyctrl('rawout',false);
|
||||
clite.term.ttyctrl('echo',true);
|
||||
clite.term.ttyctrl('iset','');
|
||||
this.isinit = clite.term.ttyctrl('alt',false);
|
||||
clite.tty.ttyctrl(this.ctty,'raw',false);
|
||||
clite.tty.ttyctrl(this.ctty,'echo',true);
|
||||
this.isinit = false;
|
||||
},
|
||||
|
||||
cbreak:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.ttyctrl('rawin',true);
|
||||
clite.tty.ttyctrl(this.ctty,'raw',true);
|
||||
},
|
||||
nocbreak:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.ttyctrl('rawin',false);
|
||||
clite.tty.ttyctrl(this.ctty,'raw',false);
|
||||
},
|
||||
|
||||
raw:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.ttyctrl('rawin',true);
|
||||
clite.tty.ttyctrl(this.ctty,'raw',true);
|
||||
},
|
||||
noraw:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.ttyctrl('rawin',false);
|
||||
clite.tty.ttyctrl(this.ctty,'raw',false);
|
||||
},
|
||||
|
||||
clear:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.clear();
|
||||
clite.tty.clear(this.ctty);
|
||||
},
|
||||
|
||||
echo:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.ttyctrl('echo',true);
|
||||
clite.tty.ttyctrl(this.ctty,'echo',true);
|
||||
},
|
||||
noecho:function() {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
clite.term.ttyctrl('echo',false);
|
||||
clite.tty.ttyctrl(this.ctty,'echo',false);
|
||||
},
|
||||
|
||||
printw:function(fmt) {
|
||||
|
|
@ -96,30 +103,30 @@ return Object.create({
|
|||
if (!this.isinit)
|
||||
return;
|
||||
a = this.attmap(a);
|
||||
clite.term.ttyctrl('atton',a);
|
||||
clite.tty.ttyctrl(this.ctty,'atton',a);
|
||||
},
|
||||
attroff:function(a) {
|
||||
if (!this.isinit)
|
||||
return;
|
||||
a = this.attmap(a);
|
||||
clite.term.ttyctrl('attoff',a);
|
||||
clite.tty.ttyctrl(this.ctty,'attoff',a);
|
||||
},
|
||||
|
||||
getmaxx:function() {
|
||||
if (!this.isinit)
|
||||
return 0;
|
||||
return clite.term.data.alt.cols;
|
||||
return this.size.cols;
|
||||
},
|
||||
getmaxy:function() {
|
||||
if (!this.isinit)
|
||||
return 0;
|
||||
return clite.term.data.alt.lines;
|
||||
return this.size.rows;
|
||||
},
|
||||
getmaxyx:function(ptry,ptrx) {
|
||||
if (!this.isinit)
|
||||
return false;
|
||||
ptrx.value = clite.term.data.alt.cols;
|
||||
ptry.value = clite.term.data.alt.lines;
|
||||
ptrx.value = this.size.cols;
|
||||
ptry.value = this.size.rows;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue