barcli icon indicating copy to clipboard operation
barcli copied to clipboard

Retain the ability to write to stdout and use the REPL while still updating a bar

Open dtex opened this issue 7 years ago • 0 comments

It may not be possible, but this here is a pretty good start:

var child_process = require("child_process");

Barcli.prototype.update = function(data) {
    var position = getPosition();

    // Update the bar

    // Restore to original position
    process.stdout.write("\033["+position.row+";"+position.column+"H\033[?25h");
});

function getPosition() {
  var output = child_process.execSync("exec < /dev/tty\noldstty=$(stty -g)\nstty raw -echo min 0\necho \"\\033[6n\" > /dev/tty\n\nIFS=\';\' read -r -d R -a pos\nstty $oldstty\nrow=$((${pos[0]:2}))\ncol=$((${pos[1]}))\necho \\{\\\"row\\\":$row, \\\"column\\\":$col\\}");
  return JSON.parse(output.toString());
};

Right now hitting any key causes the shell script to fail.

Other big problem to solve is how do we keep track of where our barcli graph is as the window scrolls?

Maybe it's possible to read each line in the window and find the bar if it's visible.

dtex avatar Aug 01 '17 21:08 dtex