diff --git a/tcshrc.prompt.final b/tcshrc.prompt.final index 61ed808..1a4b385 100644 --- a/tcshrc.prompt.final +++ b/tcshrc.prompt.final @@ -14,134 +14,46 @@ _debug "Setting up dynamic colour loading..." + + # Recompute cached sgr codes from any configuration updates -if( ! $?curr_branch_color ) then - set curr_branch_color=impossible -endif -if( "${curr_branch_color}" != "${branch_color}" ) then - set curr_branch_color="${branch_color}" - set branch_color_seq="%{[`__build_sgr_code no-csi reset ${curr_branch_color}`m" -endif +set prompt_segment_kinds=( \ + branch \ + dirs \ + ahead_tracking \ + behind_tracking \ + percent \ + at \ + depth \ + line \ + path \ + host \ + date \ + time \ + text \ + brace \ + user \ + prompt \ + ) -if( ! $?curr_dirs_color ) then - set curr_dirs_color=impossible -endif -if( "${curr_dirs_color}" != "${dirs_color}" ) then - set curr_dirs_color="${dirs_color}" - set dirs_color_seq="%{[`__build_sgr_code no-csi reset ${curr_dirs_color}`m" -endif +foreach kind ( ${prompt_segment_kinds} ) + eval 'echo $?curr_'"${kind}"'_color' >& /dev/null + _debug "Eval of ${kind}" + if( $? == 0 ) then + eval "set curr_${kind}_color=impossible" + endif + eval 'set __new_this_color="${'"${kind}"'_color}"' + eval 'set __curr_this_color="${curr_'"${kind}"'_color}"' + 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 +end -if( ! $?curr_ahead_tracking_color ) then - 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 +_debug "Done with color cacheing loop" + -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..." @@ -250,7 +162,7 @@ if( $?CSHENV_SHOW_BATTERY_LEVEL ) then #set battery_prompt="%{${battery_color}%}%{${battery_level}${at_color}\%%}%{${dim}%} " 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 set battery_prefix="" set battery_prompt="" @@ -377,10 +289,10 @@ endif _debug "Up to the time, date, and battery checks..." 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 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 if( ! $?CSHENV_DISABLE_PROMPT_BATTERY ) then set battery_prompt_view="${battery_prefix}${battery_prompt}"