-
-
Save jasonbking/a234366ae45648f91b2838ab4ee33779 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/nawk -f | |
BEGIN { | |
cmd = "/usr/bin/tput lines" | |
cmd | getline lines | |
close(cmd) | |
cmd = "/usr/bin/tput cols" | |
cmd | getline cols | |
close(cmd) | |
cmd = "/usr/bin/tput smul" | |
cmd | getline ul | |
close(cmd) | |
cmd = "/usr/bin/tput rmul" | |
cmd | getline noul | |
close(cmd) | |
} | |
function setscroll(top, bottom) { | |
cmd = sprintf("/usr/bin/tput csr %d %d", top - 1, bottom - 1) | |
cmd | getline out | |
close(cmd) | |
printf("%s", out) | |
} | |
NR == 1 { | |
setscroll(2, lines) | |
fmt = sprintf("%%s%%-%ds%%s\n", cols) | |
printf(fmt, ul, $0, noul) | |
next | |
} | |
{ print } | |
END { | |
setscroll(1, lines) | |
if (NR < lines) { | |
y = NR + 1 | |
} else { | |
y = lines | |
} | |
cmd = sprintf("/usr/bin/tput cup %d 1", y - 1) | |
cmd | getline pos | |
close(cmd) | |
printf("%s", pos) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment