diff options
author | Guillem Jover <guillem@debian.org> | 2012-03-20 09:39:42 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2014-08-15 03:42:58 +0200 |
commit | ced655387fa38215c61d3df5478cd4228c04b92a (patch) | |
tree | 77d04f283bc7b46035f6600456a63dee715ad913 /dselect/baselist.cc | |
parent | 271d88e37cfd30147157acd79bcbc9d5f51ecfe7 (diff) | |
download | dpkg-ced655387fa38215c61d3df5478cd4228c04b92a.tar.gz |
dselect: Rework columns code
Add a new struct to hold each column data, and helper functions to
handle it, so that we can easily add new columns w/o needing to have
to manually track the current and previous column width and similar.
Diffstat (limited to 'dselect/baselist.cc')
-rw-r--r-- | dselect/baselist.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/dselect/baselist.cc b/dselect/baselist.cc index eb1811d60..acd149249 100644 --- a/dselect/baselist.cc +++ b/dselect/baselist.cc @@ -99,6 +99,44 @@ void baselist::setupsigwinch() { ohshite(_("failed to set new SIGWINCH sigact")); } +void +baselist::add_column(column &col, const char *title, int width) +{ + col.title = title; + col.x = col_cur_x; + col.width = width; + + col_cur_x += col.width + gap_width; +} + +void +baselist::end_column(column &col, const char *title) +{ + col.title = title; + col.x = col_cur_x; + col.width = total_width - col.x; + + col_cur_x += col.width + gap_width; +} + +void +baselist::draw_column_head(column &col) +{ + mvwaddnstr(colheadspad, 0, col.x, col.title, col.width); +} + +void +baselist::draw_column_sep(column &col, int y) +{ + mvwaddch(listpad, y, col.x - 1, ' '); +} + +void +baselist::draw_column_item(column &col, int y, const char *item) +{ + mvwprintw(listpad, y, col.x, "%-*.*s", col.width, col.width, item); +} + void baselist::setheights() { int y= ymax - (title_height + colheads_height + thisstate_height); assert(y>=1); @@ -218,6 +256,7 @@ void baselist::enddisplay() { delwin(infopad); wmove(stdscr,ymax,0); wclrtoeol(stdscr); listpad = nullptr; + col_cur_x = 0; } void baselist::redrawall() { @@ -241,6 +280,7 @@ baselist::baselist(keybindings *kb) { bindings= kb; nitems= 0; + col_cur_x = 0; gap_width = 1; total_width = max(TOTAL_LIST_WIDTH, COLS); |