mirror of
https://github.com/Fakerr/git-recall.git
synced 2026-09-10 07:26:42 -04:00
fix redraw issue
This commit is contained in:
parent
9d50eda776
commit
1ae18daa5c
60
git-recall
60
git-recall
|
|
@ -127,16 +127,7 @@ NI=${#COMMITS[@]} # Total number of items.
|
||||||
SN=$(( `tput lines` - 1 )) # Screen's number of lines.
|
SN=$(( `tput lines` - 1 )) # Screen's number of lines.
|
||||||
CN=$(tput cols) # Screen's number of columns.
|
CN=$(tput cols) # Screen's number of columns.
|
||||||
TN=$(( $NI < $((SN -1)) ? $NI : $((SN -1)))) # Number of lines that we will display.
|
TN=$(( $NI < $((SN -1)) ? $NI : $((SN -1)))) # Number of lines that we will display.
|
||||||
OFFSET=0
|
OFFSET=0 #Incremented by one each time a commit's length is higher than teminal width.
|
||||||
|
|
||||||
# Add +1 to OFFSET if a commit's length is bigger than the current terminal session's width. (This is to fix a redraw issue)
|
|
||||||
for C in "${COMMITS[@]}"
|
|
||||||
do
|
|
||||||
ELT="$(echo "$C" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes
|
|
||||||
if [[ ${#ELT} -gt $CN ]]; then
|
|
||||||
OFFSET=$(( OFFSET + 1 ))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# If there is no items, exit.
|
# If there is no items, exit.
|
||||||
if [[ $NI = 0 ]]; then
|
if [[ $NI = 0 ]]; then
|
||||||
|
|
@ -147,6 +138,15 @@ if [[ $NI = 0 ]]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Add +1 to OFFSET if a commit's length is bigger than the current terminal session's width. (This is to fix a redraw issue)
|
||||||
|
for C in "${COMMITS[@]}"
|
||||||
|
do
|
||||||
|
ELT="$(echo "$C" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes
|
||||||
|
if [[ ${#ELT} -gt $CN ]]; then
|
||||||
|
OFFSET=$(( OFFSET + 1 ))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Set keys.
|
# Set keys.
|
||||||
au="`echo -e '\e[A'`" # arrow up
|
au="`echo -e '\e[A'`" # arrow up
|
||||||
au_1="k" # arrow up
|
au_1="k" # arrow up
|
||||||
|
|
@ -206,6 +206,20 @@ function print_diff() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Calculate OFFSET to avoid bad redraw. (Really bad performance.)
|
||||||
|
function calculate_offset {
|
||||||
|
# Add +1 to OFFSET if a commit's length is bigger than the current terminal session's width. (This is to fix a redraw issue)
|
||||||
|
OFFSET=0
|
||||||
|
limit=$(( SN + SI ))
|
||||||
|
tmp=("${COMMITS[@]:$SI:$limit}")
|
||||||
|
for C in "${tmp[@]}"
|
||||||
|
do
|
||||||
|
ELT="$(echo "$C" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes
|
||||||
|
if [[ ${#ELT} -gt $CN ]]; then
|
||||||
|
OFFSET=$(( OFFSET + 1 ))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
{ # capture stdout to stderr
|
{ # capture stdout to stderr
|
||||||
|
|
||||||
|
|
@ -218,7 +232,19 @@ END=false # end while loop
|
||||||
while ! $END
|
while ! $END
|
||||||
do
|
do
|
||||||
|
|
||||||
for i in `seq $SI $(( $TN + $SI -1 ))`
|
# Set last index to print. (based on OFFSET)
|
||||||
|
if [[ $TN == $NI ]]; then
|
||||||
|
END_INDEX=$TN
|
||||||
|
elif [[ $TN == $(( SN - 1 )) ]]; then
|
||||||
|
# Calculate new OFFSET.
|
||||||
|
if [[ $OFFSET != 0 ]]; then
|
||||||
|
calculate_offset #This involve really bad performance. Should be reconsidered.
|
||||||
|
fi
|
||||||
|
END_INDEX=$(( TN + SI -1 - OFFSET ))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Loop and echo commits
|
||||||
|
for i in `seq $SI $END_INDEX`
|
||||||
do
|
do
|
||||||
echo -n "$NORMAL"
|
echo -n "$NORMAL"
|
||||||
[[ $CP == $i ]] && echo -n "$REVERSE"
|
[[ $CP == $i ]] && echo -n "$REVERSE"
|
||||||
|
|
@ -236,18 +262,22 @@ do
|
||||||
|
|
||||||
"$au" | "$au_1")
|
"$au" | "$au_1")
|
||||||
CP=$(( CP - 1 ))
|
CP=$(( CP - 1 ))
|
||||||
[[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $(( SN - 1 )) ]] && CP=$NI && SI=$(( NI - SN + 2 ))
|
[[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $(( SN - 1 )) ]] && CP=$(( NI - OFFSET )) && SI=$(( NI - SN + 2 ))
|
||||||
[[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $NI ]] && CP=$TN
|
[[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $NI ]] && CP=$TN
|
||||||
[[ $CP == $(( SI - 1 )) ]] && [[ $SI != 1 ]] && SI=$(( SI - 1 ))
|
[[ $CP == $(( SI - 1 )) ]] && [[ $SI != 1 ]] && SI=$(( SI - 1 ))
|
||||||
tput cuu $(( TN + OFFSET ))
|
|
||||||
|
[[ $TN != $(( SN - 1 )) ]] && tput cuu $(( TN + OFFSET ))
|
||||||
|
[[ $TN == $(( SN - 1 )) ]] && tput cuu $(( SN - 1 ))
|
||||||
[[ $SI != 1 ]] && tput ed # clear screen
|
[[ $SI != 1 ]] && tput ed # clear screen
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"$ad" | "$ad_1")
|
"$ad" | "$ad_1")
|
||||||
CP=$(( CP + 1 ))
|
CP=$(( CP + 1 ))
|
||||||
[[ $CP == $(( NI + 1 )) ]] && CP=1 && SI=1
|
[[ $CP == $(( NI + 1 )) ]] && CP=1 && SI=1
|
||||||
[[ $CP == $(( SN + SI - 1)) ]] && [[ $TN == $(( SN - 1 )) ]] && SI=$(( SI + 1 ))
|
[[ $CP == $(( SN + SI - 1 - OFFSET )) ]] && [[ $TN == $(( SN - 1 )) ]] && SI=$(( SI + 1 ))
|
||||||
tput cuu $(( TN + OFFSET ))
|
|
||||||
|
[[ $TN != $(( SN - 1 )) ]] && tput cuu $(( TN + OFFSET ))
|
||||||
|
[[ $TN == $(( SN - 1 )) ]] && tput cuu $(( SN - 1 ))
|
||||||
[[ $SI != 1 ]] && tput ed # clear screen
|
[[ $SI != 1 ]] && tput ed # clear screen
|
||||||
[[ $SI = 1 ]] && [[ $CP = 1 ]] && tput ed # clear screen
|
[[ $SI = 1 ]] && [[ $CP = 1 ]] && tput ed # clear screen
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue