зеркало из https://github.com/microsoft/git.git
Merge branch 'sb/color-h-cleanup'
Devdoc update. * sb/color-h-cleanup: color.h: document and modernize header
This commit is contained in:
Коммит
f2fd27c6bf
7
color.c
7
color.c
|
@ -161,11 +161,6 @@ int color_parse(const char *value, char *dst)
|
||||||
return color_parse_mem(value, strlen(value), dst);
|
return color_parse_mem(value, strlen(value), dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void color_set(char *dst, const char *color_bytes)
|
|
||||||
{
|
|
||||||
xsnprintf(dst, COLOR_MAXLEN, "%s", color_bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the ANSI color codes for "c" to "out"; the string should
|
* Write the ANSI color codes for "c" to "out"; the string should
|
||||||
* already have the ANSI escape code in it. "out" should have enough
|
* already have the ANSI escape code in it. "out" should have enough
|
||||||
|
@ -399,8 +394,6 @@ static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
|
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
34
color.h
34
color.h
|
@ -76,22 +76,46 @@ int git_color_config(const char *var, const char *value, void *cb);
|
||||||
int git_color_default_config(const char *var, const char *value, void *cb);
|
int git_color_default_config(const char *var, const char *value, void *cb);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the color buffer (which must be COLOR_MAXLEN bytes)
|
* Parse a config option, which can be a boolean or one of
|
||||||
* to the raw color bytes; this is useful for initializing
|
* "never", "auto", "always". Return a constant of
|
||||||
* default color variables.
|
* GIT_COLOR_NEVER for "never" or negative boolean,
|
||||||
|
* GIT_COLOR_ALWAYS for "always" or a positive boolean,
|
||||||
|
* and GIT_COLOR_AUTO for "auto".
|
||||||
*/
|
*/
|
||||||
void color_set(char *dst, const char *color_bytes);
|
|
||||||
|
|
||||||
int git_config_colorbool(const char *var, const char *value);
|
int git_config_colorbool(const char *var, const char *value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a boolean whether to use color, where the argument 'var' is
|
||||||
|
* one of GIT_COLOR_UNKNOWN, GIT_COLOR_NEVER, GIT_COLOR_ALWAYS, GIT_COLOR_AUTO.
|
||||||
|
*/
|
||||||
int want_color(int var);
|
int want_color(int var);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Translate a Git color from 'value' into a string that the terminal can
|
||||||
|
* interpret and store it into 'dst'. The Git color values are of the form
|
||||||
|
* "foreground [background] [attr]" where fore- and background can be a color
|
||||||
|
* name ("red"), a RGB code (#0xFF0000) or a 256-color-mode from the terminal.
|
||||||
|
*/
|
||||||
int color_parse(const char *value, char *dst);
|
int color_parse(const char *value, char *dst);
|
||||||
int color_parse_mem(const char *value, int len, char *dst);
|
int color_parse_mem(const char *value, int len, char *dst);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Output the formatted string in the specified color (and then reset to normal
|
||||||
|
* color so subsequent output is uncolored). Omits the color encapsulation if
|
||||||
|
* `color` is NULL. The `color_fprintf_ln` prints a new line after resetting
|
||||||
|
* the color. The `color_print_strbuf` prints the contents of the given
|
||||||
|
* strbuf (BUG: but only up to its first NUL character).
|
||||||
|
*/
|
||||||
__attribute__((format (printf, 3, 4)))
|
__attribute__((format (printf, 3, 4)))
|
||||||
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
|
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
|
||||||
__attribute__((format (printf, 3, 4)))
|
__attribute__((format (printf, 3, 4)))
|
||||||
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
|
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
|
||||||
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);
|
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if the given color is GIT_COLOR_NIL that means "no color selected".
|
||||||
|
* The caller needs to replace the color with the actual desired color.
|
||||||
|
*/
|
||||||
int color_is_nil(const char *color);
|
int color_is_nil(const char *color);
|
||||||
|
|
||||||
#endif /* COLOR_H */
|
#endif /* COLOR_H */
|
||||||
|
|
5
grep.c
5
grep.c
|
@ -18,6 +18,11 @@ static void std_output(struct grep_opt *opt, const void *buf, size_t size)
|
||||||
fwrite(buf, size, 1, stdout);
|
fwrite(buf, size, 1, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void color_set(char *dst, const char *color_bytes)
|
||||||
|
{
|
||||||
|
xsnprintf(dst, COLOR_MAXLEN, "%s", color_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the grep_defaults template with hardcoded defaults.
|
* Initialize the grep_defaults template with hardcoded defaults.
|
||||||
* We could let the compiler do this, but without C99 initializers
|
* We could let the compiler do this, but without C99 initializers
|
||||||
|
|
Загрузка…
Ссылка в новой задаче