]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cfdisk: fix slang usage
authorKarel Zak <kzak@redhat.com>
Mon, 10 Mar 2014 13:44:50 +0000 (14:44 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:15 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
disk-utils/cfdisk.c

index 59830e71f832f871574e05bfca98003bcd91e390..9d792317bc1d31a8dbf5394becec658180af9e24 100644 (file)
@@ -613,10 +613,12 @@ AS_IF([test "x$with_ncurses" != xno], [
     NCURSES_LIBS=${NCURSESW_LIBS}
     NCURSES_CFLAGS=${NCURSESW_CFLAGS}
     AC_DEFINE([HAVE_LIBNCURSESW])
+    CURSES_LIB_NAME="ncursesw"
   ], [
     PKG_CHECK_MODULES(NCURSES, [ncurses], [
       have_ncurses=yes
       AC_DEFINE([HAVE_LIBNCURSES])
+      CURSES_LIB_NAME="ncursesw"
     ], [:])
   ])
 
@@ -634,12 +636,14 @@ AS_IF([test "x$with_ncurses" != xno], [
        AS_IF([test "x$have_ncurses" = xyes], [
          AC_CHECK_HEADERS([ncursesw/ncurses.h])
          NCURSES_LIBS="-lncursesw"
+         CURSES_LIB_NAME="ncursesw"
        ])
       ])
       AS_IF([test "x$have_ncurses" = xno], [
        UL_CHECK_LIB(ncurses, initscr)
        AS_IF([test "x$have_ncurses" = xyes], [
          NCURSES_LIBS="-lncurses"
+         CURSES_LIB_NAME="ncurses"
        ])
       ])
     ])
@@ -669,13 +673,21 @@ AS_IF([test "x$with_slang" = xyes], [
 #endif
 ])
   AS_IF([test "x$have_slang" = xno], [
-    AC_MSG_ERROR([slang selected but slcurses.h not found])
+    AC_MSG_ERROR([slang selected but slcurses.h not found])],
+    [CURSES_LIB_NAME=slang
   ])
 ])
 AM_CONDITIONAL([HAVE_SLANG], [test "x$have_slang" = xyes])
 
 AM_CONDITIONAL([BUILD_CFDISK], [test "x$have_slang" = xyes -o "x$have_ncurses" = xyes])
 
+AS_IF([test "x$have_slang" = xyes -o "x$have_ncurses" = xyes], [
+       AC_CHECK_LIB([$CURSES_LIB_NAME], use_default_colors, [
+                    AC_DEFINE(HAVE_USE_DEFAULT_COLORS, 1,
+                              [Define if curses library has the use_default_colors command.])
+       ])
+])
+
 
 dnl Try pkg-config for libtinfo
 PKG_CHECK_MODULES(TINFO, [tinfo], [have_tinfo=yes], [
index 0fd64bf61b48a329f56bc7899b58e953709640e5..47b7678739dc19169b800570d95816525799614e 100644 (file)
@@ -25,6 +25,7 @@
 
 #ifdef HAVE_WIDECHAR
 # include <wctype.h>
+# include <wchar.h>
 #endif
 
 #include "c.h"
@@ -486,7 +487,9 @@ static void ui_warnx(const char *fmt, ...)
        va_list ap;
        va_start(ap, fmt);
        if (ui_enabled)
-               ui_vprint_center(INFO_LINE, COLOR_PAIR(CFDISK_CL_WARNING), fmt, ap);
+               ui_vprint_center(INFO_LINE,
+                       colors_wanted() ? COLOR_PAIR(CFDISK_CL_WARNING) : 0,
+                       fmt, ap);
        else
                vfprintf(stderr, fmt, ap);
        va_end(ap);
@@ -501,7 +504,9 @@ static void ui_warn(const char *fmt, ...)
 
        va_start(ap, fmt);
        if (ui_enabled)
-               ui_vprint_center(INFO_LINE, COLOR_PAIR(CFDISK_CL_WARNING), fmt_m, ap);
+               ui_vprint_center(INFO_LINE,
+                       colors_wanted() ? COLOR_PAIR(CFDISK_CL_WARNING) : 0,
+                       fmt_m, ap);
        else
                vfprintf(stderr, fmt_m, ap);
        va_end(ap);
@@ -682,15 +687,18 @@ static int ui_init(struct cfdisk *cf __attribute__((__unused__)))
        ui_enabled = 1;
        initscr();
 
+#ifdef HAVE_USE_DEFAULT_COLORS
        if (colors_wanted() && has_colors()) {
                size_t i;
 
                start_color();
                use_default_colors();
-
                for (i = 1; i < ARRAY_SIZE(color_pairs); i++)           /* yeah, start from 1! */
                        init_pair(i, color_pairs[i][0], color_pairs[i][1]);
        }
+#else
+       colors_init(UL_COLORMODE_NEVER);
+#endif
 
        cbreak();
        noecho();
@@ -1018,7 +1026,7 @@ static void ui_draw_partition(struct cfdisk *cf, size_t i)
        } else {
                int at = 0;
 
-               if (is_freespace(cf, i)) {
+               if (colors_wanted() && is_freespace(cf, i)) {
                        attron(COLOR_PAIR(CFDISK_CL_FREESPACE));
                        at = 1;
                }
@@ -1151,7 +1159,7 @@ static ssize_t ui_get_string(struct cfdisk *cf, const char *prompt,
        clrtoeol();
 
        if (prompt) {
-               mvaddstr(ln, cl, prompt);
+               mvaddstr(ln, cl, (char *) prompt);
                cl += mbs_safe_width(prompt);
        }
 
@@ -1568,7 +1576,9 @@ static int main_menu_action(struct cfdisk *cf, int key)
                        ref = 1;
                break;
        }
+#ifdef KEY_DC
        case KEY_DC:
+#endif
        case 'd': /* Delete */
                if (fdisk_delete_partition(cf->cxt, n) != 0)
                        warn = _("Could not delete partition %zu.");
@@ -1811,6 +1821,8 @@ int main(int argc, char *argv[])
                }
        }
 
+
+
        colors_init(colormode);
 
        fdisk_init_debug(0);