Update pager colors, tweak pager.cpp

Adds a color reset thing, to ensure fish tries to use hard colors during
testing.

Also, work on a discrepancy (not introduced by my changes, afaik) when
with some combinations of color settings, and usage of --bold, caused super
flakey color paninting in the pager. Downwards movements that trigger
scrolling vs. upwards movement in the pager would only apply bold to
selections when moving upwards. The bold state of the command completions in
the pager was flipping flops on and off, depending on if there is a description
on the preceding line.

Implement a lame fix by reseting the color to normal and applying a
different style on the rightmost ')' which seems to be what was influencing it.

Makes fish use terminfo for coloring the newline glich char.
This commit is contained in:
Aaron Gyes 2016-09-10 20:28:06 -07:00
parent af95813514
commit 90e535f66f
4 changed files with 61 additions and 44 deletions

View file

@ -1,8 +1,6 @@
# Main file for fish command completions. This file contains various # Main file for fish command completions. This file contains various
# common helper functions for the command completions. All actual # common helper functions for the command completions. All actual
# completions are located in the completions subdirectory. # completions are located in the completions subdirectory.
#
# #
# Set default field separators # Set default field separators
# #
@ -15,6 +13,8 @@ function __fish_default_command_not_found_handler
echo "fish: Unknown command '$argv'" >&2 echo "fish: Unknown command '$argv'" >&2
end end
set -g version $FISH_VERSION
if status --is-interactive if status --is-interactive
# The user has seemingly explicitly launched an old fish with too-new scripts installed. # The user has seemingly explicitly launched an old fish with too-new scripts installed.
if not contains "string" (builtin -n) if not contains "string" (builtin -n)

View file

@ -22,16 +22,28 @@ function __fish_config_interactive -d "Initializations that should be performed
set userdatadir $XDG_DATA_HOME set userdatadir $XDG_DATA_HOME
end end
if not set -q fish_greeting
set -l line1 (printf (_ 'Welcome to fish, the friendly interactive shell' ))
if not set -q __fish_init_2_3_0
set -l line2 \n(printf (_ 'Type %shelp%s for instructions on how to use fish %s') (set_color green) (set_color normal))
else
set -l line2 ''
end
set -U fish_greeting $line1$line2
end
# #
# If we are starting up for the first time, set various defaults # If we are starting up for the first time, set various defaults
# #
if not set -q __fish_init_1_50_0 if not set -q __fish_init_2_39_8 # bump this to 2_4_0 when rolling release if anything changes after 9/10/2016
if not set -q fish_greeting set -g colors_backup "$HOME/fish_previous_colors-(date).txt"
set -l line1 (printf (_ 'Welcome to fish, the friendly interactive shell') )
set -l line2 (printf (_ 'Type %shelp%s for instructions on how to use fish') (set_color green) (set_color normal)) echo Backing up uvars to:\n (set_color --underline)$colors_backup(set_color normal)
set -U fish_greeting $line1\n$line2 set -U >>$colors_backup
for option in (set -Un | string match "fish*color_*")
set -eU $option
end end
set -U __fish_init_1_50_0 echo \"Normalized\" colors on upgrade.
# Regular syntax highlighting colors # Regular syntax highlighting colors
set -q fish_color_normal set -q fish_color_normal
@ -41,7 +53,7 @@ function __fish_config_interactive -d "Initializations that should be performed
set -q fish_color_param set -q fish_color_param
or set -U fish_color_param cyan or set -U fish_color_param cyan
set -q fish_color_redirection set -q fish_color_redirection
or set -U fish_color_redirection normal or set -U fish_color_redirection brblue
set -q fish_color_comment set -q fish_color_comment
or set -U fish_color_comment red or set -U fish_color_comment red
set -q fish_color_error set -q fish_color_error
@ -49,13 +61,13 @@ function __fish_config_interactive -d "Initializations that should be performed
set -q fish_color_escape set -q fish_color_escape
or set -U fish_color_escape bryellow or set -U fish_color_escape bryellow
set -q fish_color_operator set -q fish_color_operator
or set -U fish_color_operator cyan or set -U fish_color_operator bryellow
set -q fish_color_end set -q fish_color_end
or set -U fish_color_end green or set -U fish_color_end brmagenta
set -q fish_color_quote set -q fish_color_quote
or set -U fish_color_quote yellow or set -U fish_color_quote yellow
set -q fish_color_autosuggestion set -q fish_color_autosuggestion
or set -U fish_color_autosuggestion 222 brblack or set -U fish_color_autosuggestion 555 brblack
set -q fish_color_user set -q fish_color_user
or set -U fish_color_user brgreen or set -U fish_color_user brgreen
@ -71,31 +83,34 @@ function __fish_config_interactive -d "Initializations that should be performed
# Background color for matching quotes and parenthesis # Background color for matching quotes and parenthesis
set -q fish_color_match set -q fish_color_match
or set -U fish_color_match brwhite or set -U fish_color_match --background=blue
# Background color for search matches # Background color for search matches
set -q fish_color_search_match set -q fish_color_search_match
or set -U fish_color_search_match --background=magenta or set -U fish_color_search_match bryellow --background=brgrey
# Background color for selections # Background color for selections
set -q fish_color_selection set -q fish_color_selection
or set -U fish_color_selection --background=magenta or set -U fish_color_selection white --bold --background=brgrey
# Pager colors # Pager colors
set -q fish_pager_color_prefix set -q fish_pager_color_prefix
or set -U fish_pager_color_prefix brcyan or set -U fish_pager_color_prefix white --bold --underline
set -q fish_pager_color_completion #set -q fish_pager_color_completion
or set -U fish_pager_color_completion normal #or set -U fish_pager_color_completion
set -q fish_pager_color_description set -q fish_pager_color_description
or set -U fish_pager_color_description brblack or set -U fish_pager_color_description B3A06D yellow
set -q fish_pager_color_progress set -q fish_pager_color_progress
or set -U fish_pager_color_progress cyan or set -U fish_pager_color_progress brwhite --background=cyan
# #
# Directory history colors # Directory history colors
# #
set -q fish_color_history_current set -q fish_color_history_current
or set -U fish_color_history_current cyan or set -U fish_color_history_current --bold
set -U __fish_init_2_39_8
end end
# #
@ -210,15 +225,14 @@ function __fish_config_interactive -d "Initializations that should be performed
commandline -f repaint commandline -f repaint
end end
# Notify terminals when $PWD changes (issue #906)
# Notify vte-based terminals when $PWD changes (issue #906)
if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal" if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
function __update_vte_cwd --on-variable PWD --description 'Notify VTE of change to $PWD' function __update_cwd_osc --on-variable PWD --description 'Notify VTE of change to $PWD'
status --is-command-substitution status --is-command-substitution
and return and return
printf '\033]7;file://%s%s\a' (hostname) (pwd | __fish_urlencode) printf \e\]7\;file://\%s\%s\a (hostname) (pwd | __fish_urlencode)
end end
__update_vte_cwd # Run once because we might have already inherited a PWD from an old tab __update_cwd_osc # Run once because we might have already inherited a PWD from an old tab
end end
### Command-not-found handlers ### Command-not-found handlers

View file

@ -130,9 +130,10 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s
{ {
written += print_max(L" ", packed_color, 1, false, &line_data); written += print_max(L" ", packed_color, 1, false, &line_data);
} }
print_max(L"(", packed_color, 1, false, &line_data); // hack - this just works around the issue
print_max(L"(", highlight_spec_pager_completion | highlight_make_background(bg_color), 1, false, &line_data);
print_max(c->desc, packed_color, desc_width, false, &line_data); print_max(c->desc, packed_color, desc_width, false, &line_data);
print_max(L")", packed_color, 1, false, &line_data); print_max(L")", highlight_spec_pager_completion | highlight_make_background(bg_color), 1, false, &line_data);
} else { } else {
while (written < width) { while (written < width) {
written += print_max(L" ", 0, 1, false, &line_data); written += print_max(L" ", 0, 1, false, &line_data);

View file

@ -205,7 +205,7 @@ size_t escape_code_length(const wchar_t *code) {
bool found = false; bool found = false;
if (cur_term != NULL) { if (cur_term != NULL) {
// Detect these terminfo color escapes with parameter value 0..7, all of which don't move // Detect these terminfo color escapes with parameter value 0..16, all of which don't move
// the cursor. // the cursor.
char *const esc[] = { char *const esc[] = {
set_a_foreground, set_a_background, set_foreground, set_background, set_a_foreground, set_a_background, set_foreground, set_background,
@ -232,12 +232,15 @@ size_t escape_code_length(const wchar_t *code) {
enter_superscript_mode, exit_superscript_mode, enter_blink_mode, enter_superscript_mode, exit_superscript_mode, enter_blink_mode,
enter_italics_mode, exit_italics_mode, enter_reverse_mode, enter_italics_mode, exit_italics_mode, enter_reverse_mode,
enter_shadow_mode, exit_shadow_mode, enter_standout_mode, enter_shadow_mode, exit_shadow_mode, enter_standout_mode,
exit_standout_mode, enter_secure_mode}; exit_standout_mode, enter_secure_mode, enter_dim_mode,
enter_blink_mode, enter_protected_mode, enter_alt_charset_mode,
exit_alt_charset_mode};
for (size_t p = 0; p < sizeof esc2 / sizeof *esc2 && !found; p++) { for (size_t p = 0; p < sizeof esc2 / sizeof *esc2 && !found; p++) {
if (!esc2[p]) continue; if (!esc2[p]) continue;
// Test both padded and unpadded version, just to be safe. Most versions of tparm don't // Test both padded and unpadded version, just to be safe. Most versions of tparm don't
// actually seem to do anything these days. // actually seem to do anything these days.
size_t len = maxi(try_sequence(tparm(esc2[p]), code), try_sequence(esc2[p], code)); size_t len = maxi(try_sequence(tparm(esc2[p]), code), try_sequence(esc2[p], code));
if (len) { if (len) {
resulting_length = len; resulting_length = len;
@ -601,9 +604,8 @@ static bool perform_any_impending_soft_wrap(screen_t *scr, int x, int y) {
/// Make sure we don't soft wrap. /// Make sure we don't soft wrap.
static void invalidate_soft_wrap(screen_t *scr) { scr->soft_wrap_location = INVALID_LOCATION; } static void invalidate_soft_wrap(screen_t *scr) { scr->soft_wrap_location = INVALID_LOCATION; }
// Various code for testing term behavior.
#if 0 #if 0
/// Various code for testing term behavior.
static bool test_stuff(screen_t *scr) static bool test_stuff(screen_t *scr)
{ {
data_buffer_t output; data_buffer_t output;
@ -1186,18 +1188,18 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) {
// omitted_newline_char in common.cpp. // omitted_newline_char in common.cpp.
int non_space_width = fish_wcwidth(omitted_newline_char); int non_space_width = fish_wcwidth(omitted_newline_char);
if (screen_width >= non_space_width) { if (screen_width >= non_space_width) {
bool has_256_colors = output_get_color_support() & color_support_term256; if (enter_dim_mode) {
if (has_256_colors) { // Use dim if they have it, so the color will be based on their actual normal color and the background of the termianl.
// Draw the string in term256 gray. abandon_line_string.append(str2wcstring(tparm(enter_dim_mode)));
abandon_line_string.append(L"\x1b[38;5;245m");
} else {
// Draw in "bright black" (gray).
abandon_line_string.append(
L"\x1b[0m" // bright
L"\x1b[30;1m"); // black
} }
else if (set_a_foreground && max_colors >= 8) {
// Draw the string in gray.
abandon_line_string.append(str2wcstring(tparm(set_a_foreground, 8)));
}
abandon_line_string.push_back(omitted_newline_char); abandon_line_string.push_back(omitted_newline_char);
abandon_line_string.append(L"\x1b[0m"); // normal text ANSI escape sequence if (exit_attribute_mode)
abandon_line_string.append(str2wcstring(tparm(exit_attribute_mode))); // normal text ANSI escape sequence
abandon_line_string.append(screen_width - non_space_width, L' '); abandon_line_string.append(screen_width - non_space_width, L' ');
} }
abandon_line_string.push_back(L'\r'); abandon_line_string.push_back(L'\r');