commit 9cff7a1689c917d9d6a77be4479b5b8e66b3b318
parent ae15fc9bb261aa14379a504099c5783cd2802f62
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Tue, 25 Apr 2017 13:41:35 +0200
help: use a dedicated syntax to color shortcuts in a help text
This avoids applying the default syntax, or the syntax specified
with --syntax, to a ^G help text.
Diffstat:
3 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/help.c b/src/help.c
@@ -108,6 +108,9 @@ void do_help(void)
int saved_margin = margin;
/* For avoiding the line numbers on the help screen. */
ssize_t was_tabsize = tabsize;
+#ifndef DISABLE_COLOR
+ char *was_syntax = syntaxstr;
+#endif
char *saved_answer = (answer != NULL) ? strdup(answer) : NULL;
/* Store current answer when user invokes help at the prompt. */
unsigned stash[sizeof(flags) / sizeof(flags[0])];
@@ -173,6 +176,9 @@ void do_help(void)
++ptr;
start_of_text = ptr;
+#ifndef DISABLE_COLOR
+ syntaxstr = "nanohelp";
+#endif
display_the_help_text(FALSE);
curs_set(0);
edit_refresh();
@@ -270,6 +276,9 @@ void do_help(void)
free(answer);
answer = saved_answer;
tabsize = was_tabsize;
+#ifndef DISABLE_COLOR
+ syntaxstr = was_syntax;
+#endif
remove(tempfilename);
free(tempfilename);
diff --git a/syntax/Makefile.am b/syntax/Makefile.am
@@ -22,6 +22,7 @@ pkgdata_DATA = asm.nanorc \
man.nanorc \
mgp.nanorc \
mutt.nanorc \
+ nanohelp.nanorc \
nanorc.nanorc \
nftables.nanorc \
objc.nanorc \
diff --git a/syntax/nanohelp.nanorc b/syntax/nanohelp.nanorc
@@ -0,0 +1,12 @@
+## This is meant for highlighting key combos in a nano help text.
+
+# It should not apply to any normal file, so no fileregex.
+syntax "nanohelp"
+
+# Key combos:
+color brightblue "\^([]A-Z^\_←→↑↓]|Home|End)" "[←→↑↓]"
+color brightblue "\<(Tab|Enter|Home|End|Ins|Del|Bsp|PgUp|PgDn)\>"
+color brightblue "\<M-." "\<F1?[0-9]" "(\^|M-)Space"
+
+# Quoted indicators:
+color brightred "'(\^|M-)'"