cfdisk: use tree-mode for extended, colorize freesapce
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
036439315f
commit
45333e9d71
|
@ -57,11 +57,13 @@
|
||||||
/* colors */
|
/* colors */
|
||||||
enum {
|
enum {
|
||||||
CFDISK_CL_NONE = 0,
|
CFDISK_CL_NONE = 0,
|
||||||
CFDISK_CL_WARNING
|
CFDISK_CL_WARNING,
|
||||||
|
CFDISK_CL_FREESPACE,
|
||||||
};
|
};
|
||||||
static const int color_pairs[][2] = {
|
static const int color_pairs[][2] = {
|
||||||
/* color foreground, background */
|
/* color foreground, background */
|
||||||
[CFDISK_CL_WARNING] = { COLOR_RED, -1 },
|
[CFDISK_CL_WARNING] = { COLOR_RED, -1 },
|
||||||
|
[CFDISK_CL_FREESPACE] = { COLOR_GREEN, -1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cfdisk;
|
struct cfdisk;
|
||||||
|
@ -173,8 +175,10 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
|
||||||
struct fdisk_label *lb;
|
struct fdisk_label *lb;
|
||||||
struct fdisk_iter *itr = NULL;
|
struct fdisk_iter *itr = NULL;
|
||||||
struct tt *tt = NULL;
|
struct tt *tt = NULL;
|
||||||
|
struct tt_line *ln_cont = NULL;
|
||||||
char *res = NULL;
|
char *res = NULL;
|
||||||
size_t i;
|
size_t i, cont;
|
||||||
|
int tree = 0;
|
||||||
|
|
||||||
DBG(FRONTEND, dbgprint("table: convert to string"));
|
DBG(FRONTEND, dbgprint("table: convert to string"));
|
||||||
|
|
||||||
|
@ -186,25 +190,41 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
|
||||||
lb = fdisk_context_get_label(cf->cxt, NULL);
|
lb = fdisk_context_get_label(cf->cxt, NULL);
|
||||||
assert(lb);
|
assert(lb);
|
||||||
|
|
||||||
tt = tt_new_table(TT_FL_FREEDATA | TT_FL_MAX);
|
|
||||||
if (!tt)
|
|
||||||
goto done;
|
|
||||||
itr = fdisk_new_iter(FDISK_ITER_FORWARD);
|
itr = fdisk_new_iter(FDISK_ITER_FORWARD);
|
||||||
if (!itr)
|
if (!itr)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
/* get container (e.g. extended partition) */
|
||||||
|
while (fdisk_table_next_partition(tb, itr, &pa) == 0) {
|
||||||
|
if (fdisk_partition_is_nested(pa)) {
|
||||||
|
DBG(FRONTEND, dbgprint("table: nested detected, using tree"));
|
||||||
|
fdisk_partition_get_parent(pa, &cont);
|
||||||
|
tree = TT_FL_TREE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fdisk_reset_iter(itr, FDISK_ITER_FORWARD);
|
||||||
|
|
||||||
|
tt = tt_new_table(TT_FL_FREEDATA | TT_FL_MAX | tree);
|
||||||
|
if (!tt)
|
||||||
|
goto done;
|
||||||
|
|
||||||
/* headers */
|
/* headers */
|
||||||
for (i = 0; i < cf->ncols; i++) {
|
for (i = 0; i < cf->ncols; i++) {
|
||||||
col = fdisk_label_get_column(lb, cf->cols[i]);
|
col = fdisk_label_get_column(lb, cf->cols[i]);
|
||||||
if (col)
|
if (col) {
|
||||||
tt_define_column(tt, col->name,
|
int fl = col->tt_flags;
|
||||||
col->width,
|
|
||||||
col->tt_flags);
|
if (tree && col->id == FDISK_COL_DEVICE)
|
||||||
|
fl |= TT_FL_TREE;
|
||||||
|
tt_define_column(tt, col->name, col->width, fl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* data */
|
/* data */
|
||||||
while (fdisk_table_next_partition(tb, itr, &pa) == 0) {
|
while (fdisk_table_next_partition(tb, itr, &pa) == 0) {
|
||||||
struct tt_line *ln = tt_add_line(tt, NULL);
|
struct tt_line *ln = tt_add_line(tt,
|
||||||
|
fdisk_partition_is_nested(pa) ? ln_cont : NULL);
|
||||||
if (!ln)
|
if (!ln)
|
||||||
goto done;
|
goto done;
|
||||||
for (i = 0; i < cf->ncols; i++) {
|
for (i = 0; i < cf->ncols; i++) {
|
||||||
|
@ -217,6 +237,8 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
|
||||||
continue;
|
continue;
|
||||||
tt_line_set_data(ln, i, cdata);
|
tt_line_set_data(ln, i, cdata);
|
||||||
}
|
}
|
||||||
|
if (!ln_cont && tree && fdisk_partition_get_partno(pa) == cont)
|
||||||
|
ln_cont = ln;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tt_is_empty(tt)) {
|
if (!tt_is_empty(tt)) {
|
||||||
|
@ -288,6 +310,17 @@ static struct fdisk_partition *get_current_partition(struct cfdisk *cf)
|
||||||
return fdisk_table_get_partition(cf->table, cf->lines_idx);
|
return fdisk_table_get_partition(cf->table, cf->lines_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_freespace(struct cfdisk *cf, size_t i)
|
||||||
|
{
|
||||||
|
struct fdisk_partition *pa;
|
||||||
|
|
||||||
|
assert(cf);
|
||||||
|
assert(cf->table);
|
||||||
|
|
||||||
|
pa = fdisk_table_get_partition(cf->table, i);
|
||||||
|
return fdisk_partition_is_freespace(pa);
|
||||||
|
}
|
||||||
|
|
||||||
/* converts libfdisk FDISK_ASKTYPE_MENU to cfdisk menu and returns user's
|
/* converts libfdisk FDISK_ASKTYPE_MENU to cfdisk menu and returns user's
|
||||||
* responseback to libfdisk
|
* responseback to libfdisk
|
||||||
*/
|
*/
|
||||||
|
@ -900,8 +933,16 @@ static void ui_draw_partition(struct cfdisk *cf, size_t i)
|
||||||
mvaddstr(ln, cl, cf->lines[i + 1]);
|
mvaddstr(ln, cl, cf->lines[i + 1]);
|
||||||
standend();
|
standend();
|
||||||
} else {
|
} else {
|
||||||
|
int at = 0;
|
||||||
|
|
||||||
|
if (is_freespace(cf, i)) {
|
||||||
|
attron(COLOR_PAIR(CFDISK_CL_FREESPACE));
|
||||||
|
at = 1;
|
||||||
|
}
|
||||||
mvaddstr(ln, 0, ARROW_CURSOR_DUMMY);
|
mvaddstr(ln, 0, ARROW_CURSOR_DUMMY);
|
||||||
mvaddstr(ln, cl, cf->lines[i + 1]);
|
mvaddstr(ln, cl, cf->lines[i + 1]);
|
||||||
|
if (at)
|
||||||
|
attroff(COLOR_PAIR(CFDISK_CL_FREESPACE));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue