runtimejs / runtime

[not maintained] Lightweight JavaScript library operating system for the cloud
http://runtimejs.org
Apache License 2.0
1.93k stars 128 forks source link

VGA Based Menus #142

Open RossComputerGuy opened 7 years ago

RossComputerGuy commented 7 years ago

Can anyone help me fix this code? Whenever I push a key, it goes and moves to cursor too far.

function InstalerLang() {
    var fg = runtime.tty.color.WHITE;
    var bg = runtime.tty.color.BLUE;

    runtime.tty.moveTo(0,0);
    runtime.tty.print(" ",(80 * 25) + 80,fg,bg);
    runtime.tty.moveTo((80 - ("Language".length))/2,0);
    runtime.tty.print("Language",1,fg,bg);

    var x = 6;
    var y = 5;

    const locals = require("/sys/config/locals.json");

    for(var i = 0;i < Object.keys(locals).length;i++) {
        runtime.tty.moveTo(x,y+i);
        var local = locals[Object.keys(locals)[i]];
        runtime.tty.print(local.name+" -> "+local.region,1,fg,bg);
    }

    runtime.tty.moveTo(x-2,y);
    runtime.tty.print("[",1,fg,bg);
    runtime.tty.moveTo(x+locals[Object.keys(locals)[0]].name.length+(" -> ").length+locals[Object.keys(locals)[0]].region.length+1,y);
    runtime.tty.print("]",1,fg,bg);

    var changed = false;

    runtime.ps2.setKeyboardDriver({
        init: function(ops) {
            while(true) {
                if(ops.ioPort.read8() == 0x48 || ops.ioPort.read8() == 0x50 && changed == false) {
                    if(ops.ioPort.read8() == 0x48 && y > 5 && changed == false) {
                        changed = true;
                        y--;
                    } else if(ops.ioPort.read8() == 0x50 && y < y+Object.keys(locals).length && changed == false) {
                        changed = true;
                        y++;
                    }
                } else if(changed == true) {
                    changed = false;

                    runtime.tty.moveTo(x-2,y-1);
                    runtime.tty.print(" ",1,fg,bg);
                    runtime.tty.moveTo(x+locals[Object.keys(locals)[0]].name.length+(" -> ").length+locals[Object.keys(locals)[0]].region.length+1,y-1);
                    runtime.tty.print(" ",1,fg,bg);

                    runtime.tty.moveTo(x-2,y+1);
                    runtime.tty.print(" ",1,fg,bg);
                    runtime.tty.moveTo(x+locals[Object.keys(locals)[0]].name.length+(" -> ").length+locals[Object.keys(locals)[0]].region.length+1,y+1);
                    runtime.tty.print(" ",1,fg,bg);

                    runtime.tty.moveTo(x-2,y);
                    runtime.tty.print("[",1,fg,bg);
                    runtime.tty.moveTo(x+locals[Object.keys(locals)[0]].name.length+(" -> ").length+locals[Object.keys(locals)[0]].region.length+1,y);
                    runtime.tty.print("]",1,fg,bg);
                }
            }
        },
        reset: function() {}
    });
}