-
-
Save alfonsodev/7792365 to your computer and use it in GitHub Desktop.
This gist was created to answer http://stackoverflow.com/questions/17424723/how-to-update-data-on-multiple-lines-of-console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(callback) { | |
require('child_process').exec('./cursor-position.sh', function(error, stdout, stderr){ | |
callback(error, JSON.parse(stdout)); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# based on a script from http://invisible-island.net/xterm/xterm.faq.html | |
# http://stackoverflow.com/questions/2575037/how-to-get-the-cursor-position-in-bash | |
exec < /dev/tty | |
oldstty=$(stty -g) | |
stty raw -echo min 0 | |
# on my system, the following line can be replaced by the line below it | |
echo -en "\033[6n" > /dev/tty | |
# tput u7 > /dev/tty # when TERM=xterm (and relatives) | |
IFS=';' read -r -d R -a pos | |
stty $oldstty | |
# change from one-based to zero based so they work with: tput cup $row $col | |
row=$((${pos[0]:2} - 1)) # strip off the esc-[ | |
col=$((${pos[1]} - 1)) | |
echo \{\"row\":$row,\"column\":$col\} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getCursorPosition = require('./cursor-position'); | |
var _logInline = function(row, msg) { | |
if(row >= 0) row --; //litle correction | |
process.stdout.cursorTo(0, row); | |
process.stdout.clearLine(); | |
process.stdout.cursorTo(0, row); | |
process.stdout.write(msg.toString()); | |
}; | |
var delay = 1000; | |
var time = 0; | |
//Start by getting the current position | |
getCursorPosition(function(error, init) { | |
setInterval(function() { | |
time++; | |
_logInline(init.row, 'alpha-' + time); | |
_logInline(init.row + 1, 'bravo-' + time * time); | |
}, delay); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment