Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dtex opened this issue Aug 1, 2017 · 0 comments

Comments

@dtex
Copy link
Owner

dtex commented Aug 1, 2017

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 dtex changed the title Retain the ability to write to stdout and use the REPL Retain the ability to write to stdout and use the REPL while still updating a bar Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant