Created
March 28, 2014 04:35
-
-
Save realchrisolin/9825506 to your computer and use it in GitHub Desktop.
set pane title, requires tput. stolen from http://stackoverflow.com/a/9757133
This file contains hidden or 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/sh | |
# usage: no_scroll_line top|bottom 'non-scrolling line content' command to run with args | |
# | |
# Set up a non-scrolling line at the top (or the bottom) of the | |
# terminal, write the given text into it, then (in the scrolling | |
# region) run the given command with its arguments. When the | |
# command has finished, pause with a prompt and reset the | |
# scrolling region. | |
get_size() { | |
set -- $(stty size) | |
LINES=$1 | |
COLUMNS=$2 | |
} | |
set_nonscrolling_line() { | |
get_size | |
case "$1" in | |
t|to|top) | |
non_scroll_line=0 | |
first_scrolling_line=1 | |
scroll_region="1 $(($LINES - 1))" | |
;; | |
b|bo|bot|bott|botto|bottom) | |
first_scrolling_line=0 | |
scroll_region="0 $(($LINES - 2))" | |
non_scroll_line="$(($LINES - 1))" | |
;; | |
*) | |
echo 'error: first argument must be "top" or "bottom"' | |
exit 1 | |
;; | |
esac | |
clear | |
tput csr $scroll_region | |
tput cup "$non_scroll_line" 0 | |
printf %s "$2" | |
tput cup "$first_scrolling_line" 0 | |
} | |
reset_scrolling() { | |
get_size | |
clear | |
tput csr 0 $(($LINES - 1)) | |
} | |
# Set up the scrolling region and write into the non-scrolling line | |
set_nonscrolling_line "$1" "$2" | |
shift 2 | |
# Run something that writes into the scolling region | |
"$@" | |
ec=$? | |
# Reset the scrolling region | |
printf %s 'Press ENTER to reset scrolling (will clear screen)' | |
read a_line | |
reset_scrolling | |
exit "$ec" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment