From 9cff7a1689c917d9d6a77be4479b5b8e66b3b318 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@justemail.net> Date: Tue, 25 Apr 2017 13:41:35 +0200 Subject: [PATCH] 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. --- src/help.c | 9 +++++++++ syntax/Makefile.am | 1 + syntax/nanohelp.nanorc | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 syntax/nanohelp.nanorc diff --git a/src/help.c b/src/help.c index 3849aec4..533838b4 100644 --- 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 index 5e662e2f..4140dee0 100644 --- 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 new file mode 100644 index 00000000..d6e27e24 --- /dev/null +++ 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-)'" -- GitLab