Skip to content

Instantly share code, notes, and snippets.

@jasonbking
Created May 22, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbking/a234366ae45648f91b2838ab4ee33779 to your computer and use it in GitHub Desktop.
Save jasonbking/a234366ae45648f91b2838ab4ee33779 to your computer and use it in GitHub Desktop.
#!/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