nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH] Statusbar plus


From: Matteo Sasso
Subject: [Nano-devel] [PATCH] Statusbar plus
Date: Mon, 20 Apr 2015 14:36:23 +0200

Hi,
I wrote a patch to have a different color for the status bar when warnings are shown, so that we can catch the user's attention. Right now, the only piece of code that makes use of this is the part that deals with read-only files, but I can easily extend this to other warnings and errors.

It's also trivial to have yet another color for errors, but I don't know how useful that would be. Right now the default color is black on yellow.

Right now there's an issue: on monochrome terminals the normal statusbar is black-on-white while the warning statusbar is just bold. Can't figure out why.

Here it is, thanks in advance for your comments.




Index: src/color.c
===================================================================
--- src/color.c (revision 5208)
+++ src/color.c (working copy)
@@ -62,11 +62,17 @@
            interface_color_pair[i].pairnum = COLOR_PAIR(i + 1);
        }
        else {
-           interface_color_pair[i].bright = FALSE;
-           if (i != FUNCTION_TAG)
-               interface_color_pair[i].pairnum = hilite_attribute;
-           else
-               interface_color_pair[i].pairnum = A_NORMAL;
+           if (i == STATUS_BAR_WARNING && has_colors()) {
+               interface_color_pair[i].bright = TRUE;
+               init_pair(STATUS_BAR_WARNING + 1, COLOR_BLACK, COLOR_YELLOW);
+               interface_color_pair[i].pairnum = COLOR_PAIR(i + 1);
+           } else {
+               interface_color_pair[i].bright = FALSE;
+               if (i != FUNCTION_TAG)
+                   interface_color_pair[i].pairnum = hilite_attribute;
+               else
+                   interface_color_pair[i].pairnum = A_NORMAL;
+           }
        }

        if (specified_color_combo[i] != NULL) {
Index: src/files.c
===================================================================
--- src/files.c (revision 5208)
+++ src/files.c (working copy)
@@ -875,7 +875,7 @@
                "Read %lu lines (Converted from DOS and Mac format)",
                (unsigned long)num_lines), (unsigned long)num_lines);
        else
-           statusbar(
+           statusbar_warning(
                P_("Read %lu line (Converted from DOS and Mac format - Warning: No write permission)",
                "Read %lu lines (Converted from DOS and Mac format - Warning: No write permission)",
                (unsigned long)num_lines), (unsigned long)num_lines);
@@ -886,7 +886,7 @@
                "Read %lu lines (Converted from Mac format)",
                (unsigned long)num_lines), (unsigned long)num_lines);
        else
-           statusbar(P_("Read %lu line (Converted from Mac format - Warning: No write permission)",
+           statusbar_warning(P_("Read %lu line (Converted from Mac format - Warning: No write permission)",
                "Read %lu lines (Converted from Mac format - Warning: No write permission)",
                (unsigned long)num_lines), (unsigned long)num_lines);
     } else if (format == 1) {
@@ -896,7 +896,7 @@
                "Read %lu lines (Converted from DOS format)",
                (unsigned long)num_lines), (unsigned long)num_lines);
        else
-           statusbar(P_("Read %lu line (Converted from DOS format - Warning: No write permission)",
+           statusbar_warning(P_("Read %lu line (Converted from DOS format - Warning: No write permission)",
                "Read %lu lines (Converted from DOS format - Warning: No write permission)",
                (unsigned long)num_lines), (unsigned long)num_lines);
     } else
@@ -905,7 +905,7 @@
            statusbar(P_("Read %lu line", "Read %lu lines",
                (unsigned long)num_lines), (unsigned long)num_lines);
        else
-           statusbar(P_("Read %lu line ( Warning: No write permission)",
+           statusbar_warning(P_("Read %lu line ( Warning: No write permission)",
                "Read %lu lines (Warning: No write permission)",
                (unsigned long)num_lines), (unsigned long)num_lines);
 }
Index: src/nano.c
===================================================================
--- src/nano.c  (revision 5208)
+++ src/nano.c  (working copy)
@@ -2686,10 +2686,12 @@
 #else
     interface_color_pair[TITLE_BAR].pairnum = hilite_attribute;
     interface_color_pair[STATUS_BAR].pairnum = hilite_attribute;
+    interface_color_pair[STATUS_BAR_WARNING].pairnum = hilite_attribute;
     interface_color_pair[KEY_COMBO].pairnum = hilite_attribute;
     interface_color_pair[FUNCTION_TAG].pairnum = A_NORMAL;
     interface_color_pair[TITLE_BAR].bright = FALSE;
     interface_color_pair[STATUS_BAR].bright = FALSE;
+    interface_color_pair[STATUS_BAR_WARNING].bright = FALSE;
     interface_color_pair[KEY_COMBO].bright = FALSE;
     interface_color_pair[FUNCTION_TAG].bright = FALSE;
 #endif
Index: src/nano.h
===================================================================
--- src/nano.h  (revision 5208)
+++ src/nano.h  (working copy)
@@ -493,6 +493,7 @@
     STATUS_BAR,
     KEY_COMBO,
     FUNCTION_TAG,
+    STATUS_BAR_WARNING,
     NUMBER_OF_ELEMENTS
 };

Index: src/proto.h
===================================================================
--- src/proto.h (revision 5208)
+++ src/proto.h (working copy)
@@ -783,6 +783,7 @@
 void titlebar(const char *path);
 extern void set_modified(void);
 void statusbar(const char *msg, ...);
+void statusbar_warning(const char *msg, ...);
 void bottombars(int menu);
 void onekey(const char *keystroke, const char *desc, size_t len);
 void reset_cursor(void);
Index: src/rcfile.c
===================================================================
--- src/rcfile.c        (revision 5208)
+++ src/rcfile.c        (working copy)
@@ -102,6 +102,7 @@
 #ifndef DISABLE_COLOR
     {"titlecolor", 0},
     {"statuscolor", 0},
+    {"statuscolorwarning", 0},
     {"keycolor", 0},
     {"functioncolor", 0},
 #endif
@@ -1237,6 +1238,8 @@
                            specified_color_combo[TITLE_BAR] = option;
                        else if (strcasecmp(rcopts[i].name, "statuscolor") == 0)
                            specified_color_combo[STATUS_BAR] = option;
+                       else if (strcasecmp(rcopts[i].name, "statuscolorwarning") == 0)
+                           specified_color_combo[STATUS_BAR_WARNING] = option;
                        else if (strcasecmp(rcopts[i].name, "keycolor") == 0)
                            specified_color_combo[KEY_COMBO] = option;
                        else if (strcasecmp(rcopts[i].name, "functioncolor") == 0)
Index: src/winio.c
===================================================================
--- src/winio.c (revision 5208)
+++ src/winio.c (working copy)
@@ -2273,7 +2273,7 @@
 /* Display a message on the statusbar, and set disable_cursorpos to
  * TRUE, so that the message won't be immediately overwritten if
  * constant cursor position display is on. */
-void statusbar(const char *msg, ...)
+void statusbar_plus(int color, const char *msg, ...)
 {
     va_list ap;
     char *bar, *foo;
@@ -2310,15 +2310,15 @@
     start_x = (COLS - strlenpt(foo) - 4) / 2;

     wmove(bottomwin, 0, start_x);
-    if (interface_color_pair[STATUS_BAR].bright)
+    if (interface_color_pair[color].bright)
        wattron(bottomwin, A_BOLD);
-    wattron(bottomwin, interface_color_pair[STATUS_BAR].pairnum);
+    wattron(bottomwin, interface_color_pair[color].pairnum);
     waddstr(bottomwin, "[ ");
     waddstr(bottomwin, foo);
     free(foo);
     waddstr(bottomwin, " ]");
     wattroff(bottomwin, A_BOLD);
-    wattroff(bottomwin, interface_color_pair[STATUS_BAR].pairnum);
+    wattroff(bottomwin, interface_color_pair[color].pairnum);
     wnoutrefresh(bottomwin);
     reset_cursor();
     wnoutrefresh(edit);
@@ -2338,6 +2338,26 @@
        26;
 }

+/* Display a regular message on the statusbar */
+void statusbar(const char *msg, ...)
+{
+    va_list ap;
+
+    va_start(ap, msg);
+    statusbar_plus(STATUS_BAR, msg, ap);
+    va_end(ap);
+}
+
+/* Display a warning message on the statusbar */
+void statusbar_warning(const char *msg, ...)
+{
+    va_list ap;
+
+    va_start(ap, msg);
+    statusbar_plus(STATUS_BAR_WARNING, msg, ap);
+    va_end(ap);
+}
+
 /* Display the shortcut list in s on the last two rows of the bottom
  * portion of the window. */
 void bottombars(int menu)




reply via email to

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