Shortening \033[0m -> \033[m
This commit is contained in:
parent
f3eb2e99cd
commit
393778ffab
4
bp.c
4
bp.c
@ -94,7 +94,7 @@ static file_t *backup_file;
|
|||||||
static inline void fprint_filename(FILE *out, const char *filename)
|
static inline void fprint_filename(FILE *out, const char *filename)
|
||||||
{
|
{
|
||||||
if (!filename[0]) return;
|
if (!filename[0]) return;
|
||||||
if (options.format == FORMAT_FANCY) fprintf(out, "\033[0;1;4;33m%s\033[0m\n", filename);
|
if (options.format == FORMAT_FANCY) fprintf(out, "\033[0;1;4;33m%s\033[m\n", filename);
|
||||||
else fprintf(out, "%s:\n", filename);
|
else fprintf(out, "%s:\n", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ static int process_file(def_t *defs, const char *filename, pat_t *pattern)
|
|||||||
|
|
||||||
cache_destroy(f);
|
cache_destroy(f);
|
||||||
if (recycle_all_matches() != 0)
|
if (recycle_all_matches() != 0)
|
||||||
fprintf(stderr, "\033[33;1mMemory leak: there should no longer be any matches in use at this point.\033[0m\n");
|
fprintf(stderr, "\033[33;1mMemory leak: there should no longer be any matches in use at this point.\033[m\n");
|
||||||
destroy_file(&f);
|
destroy_file(&f);
|
||||||
(void)fflush(stdout);
|
(void)fflush(stdout);
|
||||||
return matches;
|
return matches;
|
||||||
|
12
explain.c
12
explain.c
@ -74,7 +74,7 @@ static void _explain_matches(match_node_t *firstmatch, int depth, const char *te
|
|||||||
if (viz_type >= text && viz_type <= &text[textlen])
|
if (viz_type >= text && viz_type <= &text[textlen])
|
||||||
printf("\033[0;2m\"");
|
printf("\033[0;2m\"");
|
||||||
|
|
||||||
printf("\033[0m");
|
printf("\033[m");
|
||||||
|
|
||||||
match_node_t *children = NULL;
|
match_node_t *children = NULL;
|
||||||
match_node_t **nextchild = &children;
|
match_node_t **nextchild = &children;
|
||||||
@ -102,7 +102,7 @@ static void _explain_matches(match_node_t *firstmatch, int depth, const char *te
|
|||||||
else
|
else
|
||||||
printf("%c", *c);
|
printf("%c", *c);
|
||||||
}
|
}
|
||||||
printf("\033[0;2m%s\033[0m", V);
|
printf("\033[0;2m%s\033[m", V);
|
||||||
} else {
|
} else {
|
||||||
*nextchild = new(match_node_t);
|
*nextchild = new(match_node_t);
|
||||||
(*nextchild)->m = m->m;
|
(*nextchild)->m = m->m;
|
||||||
@ -112,7 +112,7 @@ static void _explain_matches(match_node_t *firstmatch, int depth, const char *te
|
|||||||
printf(" ");
|
printf(" ");
|
||||||
if (m->m->end > m->m->start)
|
if (m->m->end > m->m->start)
|
||||||
printf("\033[0;2m%s", V);
|
printf("\033[0;2m%s", V);
|
||||||
printf("\033[0m");
|
printf("\033[m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,9 +120,9 @@ static void _explain_matches(match_node_t *firstmatch, int depth, const char *te
|
|||||||
for (match_node_t *m = firstmatch; m; m = m->next) {
|
for (match_node_t *m = firstmatch; m; m = m->next) {
|
||||||
if (m->m->end > m->m->start) continue;
|
if (m->m->end > m->m->start) continue;
|
||||||
if (RIGHT_TYPE(m)) {
|
if (RIGHT_TYPE(m)) {
|
||||||
printf("\033[%ldG\033[7;%sm▒\033[0m", 1+2*(m->m->start - text), color);
|
printf("\033[%ldG\033[7;%sm▒\033[m", 1+2*(m->m->start - text), color);
|
||||||
} else {
|
} else {
|
||||||
printf("\033[%ldG\033[0;2m%s\033[0m", 1+2*(m->m->start - text), V);
|
printf("\033[%ldG\033[0;2m%s\033[m", 1+2*(m->m->start - text), V);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ static void _explain_matches(match_node_t *firstmatch, int depth, const char *te
|
|||||||
const char *h = RIGHT_TYPE(m) ? H : " ";
|
const char *h = RIGHT_TYPE(m) ? H : " ";
|
||||||
for (ssize_t n = (ssize_t)(2*(m->m->end - m->m->start) - 1); n > 0; n--)
|
for (ssize_t n = (ssize_t)(2*(m->m->end - m->m->start) - 1); n > 0; n--)
|
||||||
printf("%s", h);
|
printf("%s", h);
|
||||||
printf("%s\033[0m", r);
|
printf("%s\033[m", r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef RIGHT_TYPE
|
#undef RIGHT_TYPE
|
||||||
|
6
files.c
6
files.c
@ -233,7 +233,7 @@ void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, cons
|
|||||||
if (end > f->end) end = f->end;
|
if (end > f->end) end = f->end;
|
||||||
size_t linenum = get_line_number(f, start);
|
size_t linenum = get_line_number(f, start);
|
||||||
const char *line = get_line(f, linenum);
|
const char *line = get_line(f, linenum);
|
||||||
fprintf(dest, "\033[1m%s:%lu:\033[0m ", f->filename[0] ? f->filename : "stdin", linenum);
|
fprintf(dest, "\033[1m%s:%lu:\033[m ", f->filename[0] ? f->filename : "stdin", linenum);
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@ -243,7 +243,7 @@ void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, cons
|
|||||||
|
|
||||||
const char *eol = linenum == f->nlines ? strchr(line, '\0') : strchr(line, '\n');
|
const char *eol = linenum == f->nlines ? strchr(line, '\0') : strchr(line, '\n');
|
||||||
if (end == NULL || end > eol) end = eol;
|
if (end == NULL || end > eol) end = eol;
|
||||||
fprintf(dest, "\033[2m%5lu\033(0\x78\033(B\033[0m%.*s\033[41;30m%.*s\033[0m%.*s\n",
|
fprintf(dest, "\033[2m%5lu\033(0\x78\033(B\033[m%.*s\033[41;30m%.*s\033[m%.*s\n",
|
||||||
linenum,
|
linenum,
|
||||||
(int)(start - line), line,
|
(int)(start - line), line,
|
||||||
(int)(end - start), start,
|
(int)(end - start), start,
|
||||||
@ -258,7 +258,7 @@ void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, cons
|
|||||||
fprintf(dest, "^^^^^^^^\033[8D\033[I\033[K");
|
fprintf(dest, "^^^^^^^^\033[8D\033[I\033[K");
|
||||||
else
|
else
|
||||||
(void)fputc('^', dest);
|
(void)fputc('^', dest);
|
||||||
fprintf(dest, "\033[0m\n");
|
fprintf(dest, "\033[m\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
4
print.c
4
print.c
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
static const char *color_match = "\033[0;31;1m";
|
static const char *color_match = "\033[0;31;1m";
|
||||||
static const char *color_replace = "\033[0;34;1m";
|
static const char *color_replace = "\033[0;34;1m";
|
||||||
static const char *color_normal = "\033[0m";
|
static const char *color_normal = "\033[m";
|
||||||
static const char *current_color = NULL;
|
static const char *current_color = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -267,7 +267,7 @@ int print_errors(file_t *f, match_t *m)
|
|||||||
fprintf(stderr, "\033[31;1m");
|
fprintf(stderr, "\033[31;1m");
|
||||||
printer_t tmp = {.file = f, .context_before=NO_CONTEXT, .context_after=NO_CONTEXT}; // No bells and whistles
|
printer_t tmp = {.file = f, .context_before=NO_CONTEXT, .context_after=NO_CONTEXT}; // No bells and whistles
|
||||||
print_match(stderr, &tmp, m); // Error message
|
print_match(stderr, &tmp, m); // Error message
|
||||||
fprintf(stderr, "\033[0m\n");
|
fprintf(stderr, "\033[m\n");
|
||||||
fprint_line(stderr, f, m->start, m->end, " ");
|
fprint_line(stderr, f, m->start, m->end, " ");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
14
tutorial.sh
14
tutorial.sh
@ -8,17 +8,17 @@ for t in $([ $# -gt 0 ] && echo "$@" || ls -v tests/*.sh); do
|
|||||||
echo
|
echo
|
||||||
printf "\033[1m"
|
printf "\033[1m"
|
||||||
sed -n 's/^# //p' "$t"
|
sed -n 's/^# //p' "$t"
|
||||||
printf "\033[0m"
|
printf "\033[m"
|
||||||
printf "\033[33;1mGiven these lines: Give this output:\033[0m\n"
|
printf "\033[33;1mGiven these lines: Give this output:\033[m\n"
|
||||||
diff -y -W60 --color=always "${t/.sh/.in}" "${t/.sh/.out}"
|
diff -y -W60 --color=always "${t/.sh/.in}" "${t/.sh/.out}"
|
||||||
while true; do
|
while true; do
|
||||||
printf "\n\033[1mbp pattern: \033[0m"
|
printf "\n\033[1mbp pattern: \033[m"
|
||||||
read -r pat
|
read -r pat
|
||||||
printf "\033[0;2mRunning: \033[32m%s\033[0m\n\n" "bp -p '$pat'"
|
printf "\033[0;2mRunning: \033[32m%s\033[m\n\n" "bp -p '$pat'"
|
||||||
printf "\033[33;1mExpected output: Your pattern's output:\033[0m\n"
|
printf "\033[33;1mExpected output: Your pattern's output:\033[m\n"
|
||||||
bp -p "$pat" < "${t/.sh/.in}" 2>"$tmpfile" | diff -y -W60 --color=always "${t/.sh/.out}" - && break
|
bp -p "$pat" < "${t/.sh/.in}" 2>"$tmpfile" | diff -y -W60 --color=always "${t/.sh/.out}" - && break
|
||||||
cat "$tmpfile"
|
cat "$tmpfile"
|
||||||
printf "\n\033[0;1;31mSorry, try again!\033[0m\n"
|
printf "\n\033[0;1;31mSorry, try again!\033[m\n"
|
||||||
done
|
done
|
||||||
printf "\n\033[0;1;32mCorrect!\033[0m\n"
|
printf "\n\033[0;1;32mCorrect!\033[m\n"
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user