From f1512be8a5d732e809f5ad80edf3a83a8877fc6c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 10 Mar 2014 14:44:50 +0100 Subject: cfdisk: fix slang usage Signed-off-by: Karel Zak --- configure.ac | 14 +++++++++++++- disk-utils/cfdisk.c | 22 +++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 59830e71f..9d792317b 100644 --- a/configure.ac +++ b/configure.ac @@ -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], [ diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index 0fd64bf61..47b767873 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -25,6 +25,7 @@ #ifdef HAVE_WIDECHAR # include +# include #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); -- cgit v1.2.3-55-g7522