diff options
Diffstat (limited to 'colors.c')
-rw-r--r-- | colors.c | 56 |
1 files changed, 42 insertions, 14 deletions
@@ -2,8 +2,8 @@ Modified by Chet Ramey for Readline. - Copyright (C) 1985, 1988, 1990-1991, 1995-2010, 2012 Free Software Foundation, - Inc. + Copyright (C) 1985, 1988, 1990-1991, 1995-2010, 2012, 2015 + Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -98,9 +98,29 @@ _rl_set_normal_color (void) } } +bool +_rl_print_prefix_color (void) +{ + struct bin_str *s; + + /* What do we want to use for the prefix? Let's try cyan first, see colors.h */ + s = &_rl_color_indicator[C_PREFIX]; + if (s->string != NULL) + { + if (is_colored (C_NORM)) + restore_default_color (); + _rl_put_indicator (&_rl_color_indicator[C_LEFT]); + _rl_put_indicator (s); + _rl_put_indicator (&_rl_color_indicator[C_RIGHT]); + return 0; + } + else + return 1; +} + /* Returns whether any color sequence was printed. */ bool -_rl_print_color_indicator (char *f) +_rl_print_color_indicator (const char *f) { enum indicator_no colored_filetype; COLOR_EXT_TYPE *ext; /* Color extension */ @@ -108,10 +128,9 @@ _rl_print_color_indicator (char *f) const char* name; char *filename; - struct stat astat; + struct stat astat, linkstat; mode_t mode; - int linkok; - + int linkok; /* 1 == ok, 0 == dangling symlink, -1 == missing */ int stat_ok; name = f; @@ -130,10 +149,20 @@ _rl_print_color_indicator (char *f) #else stat_ok = stat(name, &astat); #endif - if( stat_ok == 0 ) { - mode = astat.st_mode; - linkok = 1; //f->linkok; - } + if (stat_ok == 0) + { + mode = astat.st_mode; +#if defined (HAVE_LSTAT) + if (S_ISLNK (mode)) + { + linkok = stat (name, &linkstat) == 0; + if (linkok && strncmp (_rl_color_indicator[C_LINK].string, "target", 6) == 0) + mode = linkstat.st_mode; + } + else +#endif + linkok = 1; + } else linkok = -1; @@ -141,6 +170,8 @@ _rl_print_color_indicator (char *f) if (linkok == -1 && _rl_color_indicator[C_MISSING].string != NULL) colored_filetype = C_MISSING; + else if (linkok == 0 && S_ISLNK(mode) && _rl_color_indicator[C_ORPHAN].string != NULL) + colored_filetype = C_ORPHAN; /* dangling symlink */ else if(stat_ok != 0) { static enum indicator_no filetype_indicator[] = FILETYPE_INDICATORS; @@ -181,10 +212,7 @@ _rl_print_color_indicator (char *f) #endif } else if (S_ISLNK (mode)) - colored_filetype = ((linkok == 0 - && (!strncmp (_rl_color_indicator[C_LINK].string, "target", 6) - || _rl_color_indicator[C_ORPHAN].string)) - ? C_ORPHAN : C_LINK); + colored_filetype = C_LINK; else if (S_ISFIFO (mode)) colored_filetype = C_FIFO; else if (S_ISSOCK (mode)) |