tide/functions/_tide_right_prompt.fish

88 lines
3.0 KiB
Fish
Raw Normal View History

2020-05-20 20:05:33 +03:00
function _tide_right_prompt
2020-09-07 22:00:54 +03:00
set -l splitText (_tide_fetch_right_prompt_items)
2020-11-25 07:41:24 +03:00
set -l rightPromptHeight (count $splitText)
set -l leftPromptHeight (math 1+(string match --all 'newline' $tide_left_prompt_items | count))
2020-05-17 07:43:27 +03:00
2020-06-30 05:54:59 +03:00
if test "$tide_right_prompt_frame_enabled" = 'true'
2020-12-26 19:42:21 +03:00
set -l frameColor (set_color $tide_right_prompt_frame_color -b normal || echo)
2020-07-05 21:34:01 +03:00
set splitText[1] $splitText[1]$frameColor'─╮'
2020-06-30 05:54:59 +03:00
2020-12-26 03:32:03 +03:00
test $leftPromptHeight -gt 1 && if test $rightPromptHeight -gt 1
set splitText[-1] $splitText[-1]$frameColor'─╯'
else
set splitText[2] $frameColor'─╯'
set rightPromptHeight (math $rightPromptHeight+1)
2020-06-30 05:54:59 +03:00
end
2020-05-15 07:53:37 +03:00
end
2020-06-30 05:54:59 +03:00
for lineOfText in $splitText[1..-2]
_tide_print_at_end $lineOfText
2020-06-30 05:54:59 +03:00
end
2020-11-25 07:41:24 +03:00
if test $rightPromptHeight -eq $leftPromptHeight
set -U _tide_right_prompt_display_$_tide_fish_pid $splitText[-1]
2020-11-25 07:41:24 +03:00
set rightPromptHeight (math $rightPromptHeight-1)
2020-05-15 07:53:37 +03:00
else
set -U _tide_right_prompt_display_$_tide_fish_pid
2020-11-25 07:41:24 +03:00
_tide_print_at_end $splitText[-1]
2020-05-15 07:53:37 +03:00
end
2020-05-17 07:43:27 +03:00
2020-11-25 07:41:24 +03:00
_tide_cursor_up $rightPromptHeight
2020-05-15 07:53:37 +03:00
end
function _tide_fetch_right_prompt_items
2020-11-25 07:41:24 +03:00
set lastItemWasNewline
2020-06-26 22:02:40 +03:00
2020-11-25 07:44:42 +03:00
set_color normal
2020-06-26 22:02:40 +03:00
for item in $tide_right_prompt_items
if test "$item" = 'newline'
2020-11-25 07:41:24 +03:00
set_color $previousColor -b normal
printf '%s' $tide_right_prompt_suffix\n
2020-07-05 21:34:01 +03:00
set lastItemWasNewline
2020-11-25 07:41:24 +03:00
else
set -l output (_tide_item_$item)
if test -n "$output"
set -l colorName tide_"$item"_bg_color
set -l color $$colorName
test -n "$color" || set color normal
if set -e lastItemWasNewline
set_color $color -b normal
printf '%s' $tide_right_prompt_prefix
else
if test "$color" = "$previousColor"
set_color $tide_right_prompt_item_separator_same_color_color
printf '%s' $tide_right_prompt_item_separator_same_color
else
set_color $color -b $previousColor
printf '%s' $tide_right_prompt_item_separator_diff_color
end
end
2020-06-26 22:02:40 +03:00
2020-11-25 07:41:24 +03:00
set_color -b $color
2020-11-25 07:41:24 +03:00
if test "$tide_right_prompt_pad_items" = 'true'
2020-12-26 19:42:21 +03:00
printf '%s' " $output"(set_color -b $color || echo)' ' # The set_color is for git_prompt which resets the background color
2020-07-05 21:34:01 +03:00
else
2020-11-25 07:41:24 +03:00
printf '%s' "$output"
2020-07-05 21:34:01 +03:00
end
2020-06-26 22:02:40 +03:00
2020-11-25 07:41:24 +03:00
set previousColor $color
2020-06-26 22:02:40 +03:00
end
end
2020-05-09 01:32:58 +03:00
end
2020-06-26 22:02:40 +03:00
2020-07-05 21:34:01 +03:00
if not set -q lastItemWasNewline
set_color $previousColor -b normal
printf '%s' $tide_right_prompt_suffix
end
2020-05-15 07:53:37 +03:00
end
function _tide_print_at_end -a text
2020-07-05 21:34:01 +03:00
set -l startLocation (math $COLUMNS -(_tide_decolor $text | string length))
_tide_cursor_right $startLocation
2020-07-05 21:34:01 +03:00
printf '%s%b' $text '\v\r' # For some reason \n doesn't work but \v\r does
2020-04-21 21:52:24 +03:00
end