nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] possible new feature: option --edgecolumn that show


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] possible new feature: option --edgecolumn that shows a vertical guiding bar
Date: Wed, 20 Feb 2019 17:18:48 +0100

Option -J (--edgecolumn) takes a column number as argument and then
shows a vertical, colored bar over the entire height of the buffer,
to aid the user in controling the width of the text when the terminal
is wider than this desired width.

[The color needs to become configurable, and would by default just
change the background color, not the foreground color.  But that is
something for a later patch.  It also needs to add documentation, of
course.  Suggestions for a better name for the option are welcome.]

This fulfills https://bugs.debian.org/916392.
Requested-by: Arturo Borrero González <address@hidden>
And fulfills https://savannah.gnu.org/bugs/?55315.
Requested-by: Bryan Christ <address@hidden>
---
 src/global.c |  2 ++
 src/nano.c   | 17 ++++++++++++++++-
 src/proto.h  |  1 +
 src/rcfile.c |  8 ++++++++
 src/winio.c  |  9 +++++++++
 5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/global.c b/src/global.c
index b40fc8fb..ca1ea9bd 100644
--- a/src/global.c
+++ b/src/global.c
@@ -111,6 +111,8 @@ int editwincols = -1;
                /* The number of usable columns in the edit window: COLS - 
margin. */
 int margin = 0;
                /* The amount of space reserved at the left for line numbers. */
+ssize_t edge_col = 0;
+               /* The column at which a vertical bar of color will be drawn. */
 
 filestruct *cutbuffer = NULL;
                /* The buffer where we store cut text. */
diff --git a/src/nano.c b/src/nano.c
index 230983cc..9c4cbe80 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -797,6 +797,10 @@ void usage(void)
 #endif
 #ifdef ENABLE_NANORC
        print_opt("-I", "--ignorercfiles", N_("Don't look at nanorc files"));
+#endif
+#ifndef NANO_TINY
+       print_opt("-J <number>", "--edgecolumn=<number>",
+                                       N_("Show a guiding bar at this 
column"));
 #endif
        print_opt("-K", "--rawsequences",
                                        N_("Fix numeric keypad key confusion 
problem"));
@@ -2029,6 +2033,7 @@ int main(int argc, char **argv)
                {"wordchars", 1, NULL, 'X'},
                {"zap", 0, NULL, 'Z'},
                {"atblanks", 0, NULL, 'a'},
+               {"edgecolumn", 1, NULL, 'e'},
                {"autoindent", 0, NULL, 'i'},
                {"cutfromcursor", 0, NULL, 'k'},
                {"unix", 0, NULL, 'u'},
@@ -2092,7 +2097,7 @@ int main(int argc, char **argv)
 
        while ((optchr =
                getopt_long(argc, argv,
-                               
"ABC:DEFGHIKLMNOPQ:RST:UVWX:Y:Zabcdefghijklmno:pr:s:tuvwxyz$",
+                               
"ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Zabcdefghijklmno:pr:s:tuvwxyz$",
                                long_options, NULL)) != -1) {
                switch (optchr) {
 #ifndef NANO_TINY
@@ -2134,6 +2139,13 @@ int main(int argc, char **argv)
                                ignore_rcfiles = TRUE;
                                break;
 #endif
+                       case 'J':
+                               if (!parse_num(optarg, &edge_col) || edge_col 
<= 0) {
+                                       fprintf(stderr, _("Edge column \"%s\" 
is invalid"), optarg);
+                                       fprintf(stderr, "\n");
+                                       exit(1);
+                               }
+                               break;
                        case 'K':
                                SET(RAW_SEQUENCES);
                                break;
@@ -2330,6 +2342,7 @@ int main(int argc, char **argv)
                ssize_t fill_cmdline = fill;
 #endif
 #ifndef NANO_TINY
+               size_t edgecol_cmdline = edge_col;
                char *backup_dir_cmdline = backup_dir;
                char *word_chars_cmdline = word_chars;
 #endif
@@ -2376,6 +2389,8 @@ int main(int argc, char **argv)
                        fill = fill_cmdline;
 #endif
 #ifndef NANO_TINY
+               if (edgecol_cmdline > 0)
+                       edge_col = edgecol_cmdline;
                if (backup_dir_cmdline != NULL) {
                        free(backup_dir);
                        backup_dir = backup_dir_cmdline;
diff --git a/src/proto.h b/src/proto.h
index 20c0b8d2..52cec88f 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -88,6 +88,7 @@ extern WINDOW *bottomwin;
 extern int editwinrows;
 extern int editwincols;
 extern int margin;
+extern ssize_t edge_col;
 
 extern filestruct *cutbuffer;
 extern filestruct *cutbottom;
diff --git a/src/rcfile.c b/src/rcfile.c
index 295a94d5..d1a65b4a 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -102,6 +102,7 @@ static const rcoption rcopts[] = {
        {"backupdir", 0},
        {"casesensitive", CASE_SENSITIVE},
        {"cutfromcursor", CUT_FROM_CURSOR},
+       {"edgecolumn", 0},
        {"locking", LOCKING},
        {"matchbrackets", 0},
        {"noconvert", NO_CONVERT},
@@ -1116,6 +1117,13 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
                } else
 #endif
 #ifndef NANO_TINY
+               if (strcasecmp(rcopts[i].name, "edgecolumn") == 0) {
+                       if (!parse_num(option, &edge_col) || edge_col <= 0) {
+                               rcfile_error(N_("Edge column \"%s\" is 
invalid"), option);
+                               edge_col = 0;
+                       }
+                       free(option);
+               }
                if (strcasecmp(rcopts[i].name, "matchbrackets") == 0) {
                        matchbrackets = option;
                        if (has_blank_mbchars(matchbrackets)) {
diff --git a/src/winio.c b/src/winio.c
index 18ae548e..2c19791e 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2680,6 +2680,15 @@ void edit_draw(filestruct *fileptr, const char 
*converted,
        }
 #endif /* ENABLE_COLOR */
 
+       if (edge_col > 0) {
+               const char *text = converted + actual_x(converted, edge_col - 
1);
+               const char *edge_char = (*text == '\0') ? " " : text;
+
+               wattron(edit, interface_color_pair[ERROR_MESSAGE]);
+               mvwaddnstr(edit, row, margin + edge_col - 1, edge_char, 1);
+               wattroff(edit, interface_color_pair[ERROR_MESSAGE]);
+       }
+
 #ifndef NANO_TINY
        /* If the mark is on, and fileptr is at least partially selected, we
         * need to paint it. */
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]