mscdex / node-ncurses

An ncurses binding for node.js
MIT License
386 stars 25 forks source link

strange scroll behavior #33

Closed franck34 closed 11 years ago

franck34 commented 11 years ago

Launch the code below, then use keys UP & DOWN.

On my side,it's scroll, but lines which are supposed to be visible are not

An idea ? code issue or bug ?

var nc = require('ncurses');

// If Ctrl+C, let's clean up and exit as clean as possible
process.on('SIGINT', function() {
    nc.cleanup();
    process.exit();
});

// In case of coding errors, let's clean up screen before dumping error
process.on('uncaughtException',function(err) {
    nc.cleanup();
    console.log(err.stack);
    process.exit();
});

var win = new nc.Window();

var win1 = new nc.Window(win.height-2,50,0,0);

//win1.frame('win1Title');
win1.scrollok(true);
win1.setscrreg(1,win1.height-1);

for (var row=1;row<100;row++) {
    win1.print(row,1,'Line '+row);
}

win1.cursor(1,1);

var selectedLine = 1;
win1.refresh();

var onKey = function(chr,chrCode,isKey) {
    if (chrCode != nc.keys.DOWN && chrCode != nc.keys.UP) return;

    if (chrCode == nc.keys.DOWN) {
        if (selectedLine == win1.height-2) return;
        var v = 1;
    } else if (chrCode == nc.keys.UP) {
        if (selectedLine == 1) return;
        var v = -1;
    }
    var i = selectedLine+v;
    //win1.cursor(i,1);
    win1.scroll(v);
    win1.refresh();
    selectedLine = selectedLine + v;
}

// Handler input char on this child windows
win1.on('inputChar',onKey);
franck34 commented 11 years ago

This code is completely wrong.

"scroll" means "move", so i have to display "dropped lines" myself.

franck34 commented 11 years ago

Please close this ticket