mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Merge branch 'js/diff-color-words'
* js/diff-color-words: Change the spelling of "wordregex". color-words: Support diff.wordregex config option color-words: make regex configurable via attributes color-words: expand docs with precise semantics color-words: enable REG_NEWLINE to help user color-words: take an optional regular expression describing words color-words: change algorithm to allow for 0-character word boundaries color-words: refactor word splitting and use ALLOC_GROW() Add color_fwrite_lines(), a function coloring each line individually
This commit is contained in:
28
color.c
28
color.c
@@ -202,3 +202,31 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
|
||||
va_end(args);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function splits the buffer by newlines and colors the lines individually.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
*/
|
||||
int color_fwrite_lines(FILE *fp, const char *color,
|
||||
size_t count, const char *buf)
|
||||
{
|
||||
if (!*color)
|
||||
return fwrite(buf, count, 1, fp) != 1;
|
||||
while (count) {
|
||||
char *p = memchr(buf, '\n', count);
|
||||
if (p != buf && (fputs(color, fp) < 0 ||
|
||||
fwrite(buf, p ? p - buf : count, 1, fp) != 1 ||
|
||||
fputs(COLOR_RESET, fp) < 0))
|
||||
return -1;
|
||||
if (!p)
|
||||
return 0;
|
||||
if (fputc('\n', fp) < 0)
|
||||
return -1;
|
||||
count -= p + 1 - buf;
|
||||
buf = p + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user