mirror of
https://github.com/Fakerr/git-recall.git
synced 2026-09-10 07:26:42 -04:00
Merge pull request #34 from ryanc414/fix/ctrl_c
Handle Ctrl-C interrupt
This commit is contained in:
commit
db51c14ad9
32
git-recall
32
git-recall
|
|
@ -192,15 +192,23 @@ function get_diff() {
|
|||
DIFF_LINES_NUMBER=$(( DIFF_LINES_NUMBER + off ))
|
||||
}
|
||||
|
||||
cleanup_diff()
|
||||
{
|
||||
clear_screen
|
||||
cleanup_and_exit
|
||||
}
|
||||
|
||||
# This function will print the diff according the commit's tip. If the diff is too long, the result will be displayed using 'less'.
|
||||
function print_diff() {
|
||||
get_diff
|
||||
if [[ $(( TN + DIFF_LINES_NUMBER + OFFSET )) -ge $(( `tput lines` - 1 )) ]]; then
|
||||
trap cleanup_diff INT
|
||||
if [[ $LESSKEY = true ]]; then
|
||||
echo "$DIFF" | less -r -k /tmp/lsh_less_keys_tmp
|
||||
else
|
||||
echo "$DIFF" | less -r
|
||||
fi
|
||||
trap cleanup_and_exit INT
|
||||
clear_screen
|
||||
else
|
||||
stop=false
|
||||
|
|
@ -247,6 +255,24 @@ function calculate_offset {
|
|||
done
|
||||
}
|
||||
|
||||
# Reset changes made by this script before exiting
|
||||
cleanup_and_exit()
|
||||
{
|
||||
# remove temporary less keybindings
|
||||
[[ $LESSKEY = true ]] && rm /tmp/lsh_less_keys_tmp
|
||||
|
||||
tput cnorm # unhide cursor
|
||||
echo "$NORMAL" # normal colors
|
||||
stty "$orig_stty" > /dev/null 2>&1
|
||||
exit
|
||||
}
|
||||
|
||||
# Store original terminal settings
|
||||
orig_stty=$(stty -g)
|
||||
|
||||
# Catch a control-C interrupt and perform cleanup operations before exiting
|
||||
trap cleanup_and_exit INT
|
||||
|
||||
{ # capture stdout to stderr
|
||||
|
||||
tput civis # hide cursor.
|
||||
|
|
@ -324,11 +350,7 @@ do
|
|||
esac
|
||||
done
|
||||
|
||||
# remove temporary less keybindings
|
||||
[[ $LESSKEY = true ]] && rm /tmp/lsh_less_keys_tmp
|
||||
|
||||
tput cnorm # unhide cursor
|
||||
echo "$NORMAL" # normal colors
|
||||
cleanup_and_exit
|
||||
|
||||
} >&2 # END capture
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue