summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-07-13 15:22:42 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-07-13 16:02:56 -0400
commitc5a2bfd924445dfccd943ea34374a5d1266f5cb9 (patch)
tree107939d8c2b35a799a23ae6806f62c98ad6efcc9 /src
parentb577bedfd37d93cb802c36beb93cf6581af51930 (diff)
downloadbfs-c5a2bfd924445dfccd943ea34374a5d1266f5cb9.tar.xz
color: TTY-escape filenames
Diffstat (limited to 'src')
-rw-r--r--src/color.c10
-rw-r--r--src/color.h1
-rw-r--r--src/printf.c4
3 files changed, 12 insertions, 3 deletions
diff --git a/src/color.c b/src/color.c
index 00d7920..6593f5b 100644
--- a/src/color.c
+++ b/src/color.c
@@ -922,9 +922,12 @@ static int print_colored(CFILE *cfile, const struct esc_seq *esc, const char *st
if (print_esc(cfile, esc) != 0) {
return -1;
}
- if (dstrxcat(&cfile->buffer, str, len) != 0) {
+
+ // Don't let the string itself interfere with the colors
+ if (print_wordesc(cfile, str, len, WESC_TTY) != 0) {
return -1;
}
+
if (print_reset(cfile) != 0) {
return -1;
}
@@ -1242,6 +1245,11 @@ static int cvbuff(CFILE *cfile, const char *format, va_list args) {
return -1;
}
break;
+ case 'Q':
+ if (print_wordesc(cfile, va_arg(args, const char *), SIZE_MAX, WESC_TTY) != 0) {
+ return -1;
+ }
+ break;
case 'F':
if (print_name(cfile, va_arg(args, const struct BFTW *)) != 0) {
diff --git a/src/color.h b/src/color.h
index 932d551..0d46c33 100644
--- a/src/color.h
+++ b/src/color.h
@@ -87,6 +87,7 @@ int cfclose(CFILE *cfile);
* %zu: A size_t
* %m: strerror(errno)
* %pq: A shell-escaped string, like bash's printf %q
+ * %pQ: A TTY-escaped string.
* %pF: A colored file name, from a const struct BFTW * argument
* %pP: A colored file path, from a const struct BFTW * argument
* %pL: A colored link target, from a const struct BFTW * argument
diff --git a/src/printf.c b/src/printf.c
index 6520d2d..f0910fa 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -298,7 +298,7 @@ static int bfs_printf_h(CFILE *cfile, const struct bfs_printf *directive, const
int ret;
if (should_color(cfile, directive)) {
- ret = cfprintf(cfile, "${di}%s${rs}", buf);
+ ret = cfprintf(cfile, "${di}%pQ${rs}", buf);
} else {
ret = dyn_fprintf(cfile->file, directive, buf);
}
@@ -313,7 +313,7 @@ static int bfs_printf_H(CFILE *cfile, const struct bfs_printf *directive, const
if (ftwbuf->depth == 0) {
return cfprintf(cfile, "%pP", ftwbuf);
} else {
- return cfprintf(cfile, "${di}%s${rs}", ftwbuf->root);
+ return cfprintf(cfile, "${di}%pQ${rs}", ftwbuf->root);
}
} else {
return dyn_fprintf(cfile->file, directive, ftwbuf->root);