Dynamic prompt colors cacheing loop

This commit is contained in:
2026-06-23 19:10:18 -04:00
parent a75180f622
commit 5d12f2dc32
+36 -124
View File
@@ -14,134 +14,46 @@
_debug "Setting up dynamic colour loading..." _debug "Setting up dynamic colour loading..."
# Recompute cached sgr codes from any configuration updates # Recompute cached sgr codes from any configuration updates
if( ! $?curr_branch_color ) then set prompt_segment_kinds=( \
set curr_branch_color=impossible branch \
endif dirs \
if( "${curr_branch_color}" != "${branch_color}" ) then ahead_tracking \
set curr_branch_color="${branch_color}" behind_tracking \
set branch_color_seq="%{[`__build_sgr_code no-csi reset ${curr_branch_color}`m" percent \
endif at \
depth \
line \
path \
host \
date \
time \
text \
brace \
user \
prompt \
)
if( ! $?curr_dirs_color ) then foreach kind ( ${prompt_segment_kinds} )
set curr_dirs_color=impossible eval 'echo $?curr_'"${kind}"'_color' >& /dev/null
_debug "Eval of ${kind}"
if( $? == 0 ) then
eval "set curr_${kind}_color=impossible"
endif endif
if( "${curr_dirs_color}" != "${dirs_color}" ) then eval 'set __new_this_color="${'"${kind}"'_color}"'
set curr_dirs_color="${dirs_color}" eval 'set __curr_this_color="${curr_'"${kind}"'_color}"'
set dirs_color_seq="%{[`__build_sgr_code no-csi reset ${curr_dirs_color}`m" if( "${__new_this_color}" != ${__curr_this_color} ) then
eval 'set curr_'"${kind}"'_color="'${__new_this_color}'"'
set __this_color_seq="%{[`__build_sgr_code no-csi reset ${__new_this_color}`m%}"
eval 'set '"${kind}"'_color_seq="'"${__this_color_seq}"'"'
endif endif
end
if( ! $?curr_ahead_tracking_color ) then _debug "Done with color cacheing loop"
set curr_ahead_tracking_color=impossible
endif
if( "${curr_ahead_tracking_color}" != "${ahead_tracking_color}" ) then
set curr_ahead_tracking_color="${ahead_tracking_color}"
set ahead_tracking_color_seq="^[[`__build_sgr_code no-csi reset ${curr_ahead_tracking_color}`m"
endif
if( ! $?curr_behind_tracking_color ) then
set curr_behind_tracking_color=impossible
endif
if( "${curr_behind_tracking_color}" != "${behind_tracking_color}" ) then
set curr_behind_tracking_color="${behind_tracking_color}"
set behind_tracking_color_seq="^[[`__build_sgr_code no-csi reset ${curr_behind_tracking_color}`m"
endif
if( ! $?curr_percent_color ) then
set curr_percent_color=impossible
endif
if( "${curr_percent_color}" != "${percent_color}" ) then
set curr_percent_color="${percent_color}"
set percent_color_seq="[`__build_sgr_code no-csi reset ${curr_percent_color}`m"
endif
if( ! $?curr_at_color ) then
set curr_at_color=impossible
endif
if( "${curr_at_color}" != "${at_color}" ) then
set curr_at_color="${at_color}"
set at_color_seq="%{[`__build_sgr_code no-csi reset ${curr_at_color}`m%}"
endif
if( ! $?curr_depth_color ) then
set curr_depth_color=impossible
endif
if( "${curr_depth_color}" != "${depth_color}" ) then
set curr_depth_color="${depth_color}"
set depth_color_seq="%{[`__build_sgr_code no-csi reset ${curr_depth_color}`m%}"
endif
if( ! $?curr_line_color ) then
set curr_line_color=impossible
endif
if( "${curr_line_color}" != "${line_color}" ) then
set curr_line_color="${line_color}"
set line_color_seq="%{[`__build_sgr_code no-csi reset ${curr_line_color}`m%}"
endif
if( ! $?curr_path_color ) then
set curr_path_color=impossible
endif
if( "${curr_path_color}" != "${path_color}" ) then
set curr_path_color="${path_color}"
set path_color_seq="%{[`__build_sgr_code no-csi reset ${curr_path_color}`m%}"
endif
if( ! $?curr_host_color ) then
set curr_host_color=impossible
endif
if( "${curr_host_color}" != "${host_color}" ) then
set curr_host_color="${host_color}"
set host_color_seq="%{[`__build_sgr_code no-csi reset ${curr_host_color}`m%}"
endif
if( ! $?curr_date_color ) then
set curr_date_color=impossible
endif
if( "${curr_date_color}" != "${date_color}" ) then
set curr_date_color="${date_color}"
set date_color_seq="[`__build_sgr_code no-csi reset ${curr_date_color}`m"
endif
if( ! $?curr_time_color ) then
set curr_time_color=impossible
endif
if( "${curr_time_color}" != "${time_color}" ) then
set curr_time_color="${time_color}"
set time_color_seq="[`__build_sgr_code no-csi reset ${curr_time_color}`m"
endif
if( ! $?curr_text_color ) then
set curr_text_color=impossible
endif
if( "${curr_text_color}" != "${text_color}" ) then
set curr_text_color="${text_color}"
set text_color_seq="[`__build_sgr_code no-csi reset ${curr_text_color}`m"
endif
if( ! $?curr_brace_color ) then
set curr_brace_color=impossible
endif
if( "${curr_brace_color}" != "${brace_color}" ) then
set curr_brace_color="${brace_color}"
set brace_color_seq="%{[`__build_sgr_code no-csi reset ${curr_brace_color}`m%}"
endif
if( ! $?curr_user_color ) then
set curr_user_color=impossible
endif
if( "${curr_user_color}" != "${user_color}" ) then
set curr_user_color="${user_color}"
set user_color_seq="%{[`__build_sgr_code no-csi reset ${curr_user_color}`m%}"
endif
if( ! $?curr_prompt_color ) then
set curr_prompt_color=impossible
endif
if( "${curr_prompt_color}" != "${prompt_color}" ) then
set curr_prompt_color="${prompt_color}"
set prompt_color_seq="%{[`__build_sgr_code no-csi reset ${curr_prompt_color}`m%}"
endif
_debug "Dynamic color loading processed..." _debug "Dynamic color loading processed..."
@@ -250,7 +162,7 @@ if( $?CSHENV_SHOW_BATTERY_LEVEL ) then
#set battery_prompt="%{${battery_color}%}%{${battery_level}${at_color}\%%}%{${dim}%} " #set battery_prompt="%{${battery_color}%}%{${battery_level}${at_color}\%%}%{${dim}%} "
set battery_prefix="%{${csi}m${csi}28D%}" set battery_prefix="%{${csi}m${csi}28D%}"
set battery_prompt="%{${csi}38;2;128;128;255;3mBattery Level:${sgr_reset} ${battery_color}${battery_level}${percent_color_seq}%${sgr_reset} %}" set battery_prompt="%{${csi}38;2;128;128;255;3mBattery Level:${sgr_reset} ${battery_color}${battery_level}%}${percent_color_seq}%{%${sgr_reset} %}"
else else
set battery_prefix="" set battery_prefix=""
set battery_prompt="" set battery_prompt=""
@@ -377,10 +289,10 @@ endif
_debug "Up to the time, date, and battery checks..." _debug "Up to the time, date, and battery checks..."
if( ! $?CSHENV_DISABLE_PROMPT_TIME ) then if( ! $?CSHENV_DISABLE_PROMPT_TIME ) then
set time_prompt_view="%{${time_color_seq}%}${time_prompt}%{${sgr_reset}%}" set time_prompt_view="${time_color_seq}${time_prompt}%{${sgr_reset}%}"
endif endif
if( ! $?CSHENV_DISABLE_PROMPT_DATE ) then if( ! $?CSHENV_DISABLE_PROMPT_DATE ) then
set date_prompt_view="%{${date_color_seq}%}${date_prompt}%{${sgr_reset}%}" set date_prompt_view="${date_color_seq}${date_prompt}%{${sgr_reset}%}"
endif endif
if( ! $?CSHENV_DISABLE_PROMPT_BATTERY ) then if( ! $?CSHENV_DISABLE_PROMPT_BATTERY ) then
set battery_prompt_view="${battery_prefix}${battery_prompt}" set battery_prompt_view="${battery_prefix}${battery_prompt}"