Compare commits
1 Commits
63b7170ccb
...
fff22c22d7
Author | SHA1 | Date | |
---|---|---|---|
fff22c22d7 |
@ -27,9 +27,11 @@ prompt_fresh_setup() {
|
||||
if [ $almostontop -eq 1 ]; then
|
||||
# Hook to clear the screen then prints the prompt with previous command at
|
||||
# the top of the screen.
|
||||
add-zsh-hook preexec fresh_almostontop
|
||||
add-zsh-hook precmd fresh_almostontop_precmd
|
||||
add-zsh-hook preexec fresh_almostontop_preexec
|
||||
else
|
||||
add-zsh-hook -d preexec fresh_almostontop
|
||||
add-zsh-hook -d preexec fresh_almostontop_preexec
|
||||
add-zsh-hook -d precmd fresh_almostontop_precmd
|
||||
fi
|
||||
|
||||
[ $recompile -eq 1 ] && prompt_cleanup
|
||||
@ -128,7 +130,22 @@ fresh_line_one() {
|
||||
print -P "$time_stamp $directory$git$py$docker$result"
|
||||
}
|
||||
|
||||
fresh_almostontop() {
|
||||
# Executed before each prompt.
|
||||
fresh_almostontop_precmd() {
|
||||
# TODO: store the cursor position for use in fresh_almostontop_preexec
|
||||
# CSI ESC[6n gets the cursor position in the form ESC[<row>;<column>R
|
||||
printf "\033[6n"
|
||||
# Discard prefix delimited by [
|
||||
read -s -d [
|
||||
# Store the <row> delimited by ; in fresh_precmd_row
|
||||
read -s -d \; fresh_precmd_row
|
||||
# Discard suffix delimted by R otherwise it is output to the tty
|
||||
read -s -d R
|
||||
# printf "$fresh_precmd_row\n"
|
||||
}
|
||||
|
||||
# Executed just after a command has been read and is about to be executed.
|
||||
fresh_almostontop_preexec() {
|
||||
# CSI ESC[6n gets the cursor position in the form ESC[<row>;<column>R
|
||||
printf "\033[6n"
|
||||
# Discard prefix delimited by [
|
||||
@ -141,14 +158,16 @@ fresh_almostontop() {
|
||||
# CSI ESC[<num>B moves the cursor down <num> lines
|
||||
let "down = $LINES - $row"
|
||||
printf "\033[${down}B"
|
||||
# Calculate the number of lines in the prompt
|
||||
let "prompt_lines = ($row - $fresh_precmd_row) + 2"
|
||||
# Print new lines to push the old command out of view
|
||||
let "new = $row - 3"
|
||||
let "new = $row - $prompt_lines"
|
||||
for (( i = 0; i < $new; i++ )); do
|
||||
printf "\n"
|
||||
done
|
||||
# Move the cursor to the line below the prompt
|
||||
# CSI ESC[<num>A moves the cursor up <num> lines
|
||||
let "up = $LINES - 3"
|
||||
let "up = $LINES - $prompt_lines"
|
||||
printf "\033[${up}A"
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user