tide/functions/_tide_left_prompt.fish

85 lines
2.6 KiB
Fish
Raw Normal View History

2020-05-20 20:05:33 +03:00
function _tide_left_prompt
2020-06-25 20:31:01 +03:00
set lastItemWasNewline # Display prefix instead of separator before first item
2020-06-25 05:45:50 +03:00
set color normal
2020-06-29 22:32:56 +03:00
set currentHeight 1
2020-06-25 05:45:50 +03:00
for item in $tide_left_prompt_items
if test "$item" = 'newline'
2020-06-30 21:49:37 +03:00
_print_frame
2020-07-04 23:47:08 +03:00
if not set -q lastItemWasNewline && not set -q lastItemWasPromptChar
set_color $previousColor -b normal
printf '%s' $tide_left_prompt_suffix
end
2020-06-25 05:45:50 +03:00
printf '%b' '\n'
2020-06-29 22:32:56 +03:00
2020-06-25 05:45:50 +03:00
set lastItemWasNewline
2020-06-29 22:32:56 +03:00
set currentHeight (math $currentHeight +1)
2020-06-25 05:45:50 +03:00
continue
end
set -l output (_tide_item_$item)
if test -n "$output"
2020-06-30 21:49:37 +03:00
_print_frame
2020-06-29 22:32:56 +03:00
2020-06-30 21:49:37 +03:00
set -l colorName tide_"$item"_bg_color
2020-06-25 05:45:50 +03:00
set -l color $$colorName
2020-07-04 23:47:08 +03:00
if set -e lastItemWasNewline || set -e lastItemWasPromptChar
if test "$item" != 'prompt_char'
2020-07-04 23:47:08 +03:00
set_color $color -b normal
printf '%s' $tide_left_prompt_prefix
end
2020-06-25 05:45:50 +03:00
else
2020-07-04 23:47:08 +03:00
if test "$color" = "$previousColor"
set_color $tide_left_prompt_item_separator_same_color_color
printf '%s' $tide_left_prompt_item_separator_same_color
else
set_color $previousColor -b $color
printf '%s' $tide_left_prompt_item_separator_diff_color
end
2020-06-25 05:45:50 +03:00
end
2020-06-27 00:59:35 +03:00
2020-07-04 23:47:08 +03:00
set_color -b $color
if test "$tide_left_prompt_pad_items" = 'true' -a "$item" != 'prompt_char'
printf '%s' " $output"(set_color -b $color)' ' # The set_color is for git_prompt which resets the background color
else
printf '%s' "$output"
end
2020-06-27 00:59:35 +03:00
2020-06-25 05:45:50 +03:00
set previousColor $color
if test "$item" = 'prompt_char'
2020-07-04 23:47:08 +03:00
set lastItemWasPromptChar
end
2020-06-25 05:45:50 +03:00
end
end
2020-06-30 05:54:59 +03:00
if set -q lastItemWasNewline
if test "$tide_left_prompt_frame_enabled" = 'true'
set_color $tide_left_prompt_frame_color
printf '%s' '╰─'
end
2020-07-04 23:47:08 +03:00
else if not set -q lastItemWasPromptChar
set_color $previousColor -b normal
printf '%s' $tide_left_prompt_suffix
2020-05-20 20:05:33 +03:00
end
2020-06-30 21:49:37 +03:00
end
function _print_frame --no-scope-shadowing
if set -q lastItemWasNewline && test "$tide_left_prompt_frame_enabled" = 'true'
2020-07-04 23:47:08 +03:00
set_color $tide_left_prompt_frame_color -b normal
2020-06-30 21:49:37 +03:00
if test $currentHeight -eq 1
printf '%s' '╭─'
else if test $currentHeight -lt $_tide_left_prompt_height
printf '%s' '├─'
else
printf '%s' '╰─'
end
end
2020-05-20 20:05:33 +03:00
end