Skip to content

Commit e3c320a

Browse files
committed
svnbrowse: Use curses WINDOWs to position layout elements on screen.
* subversion/svnbrowse/svnbrowse.c (svn_browse__view_t): Store screen and areas for list and infobar controls, removing a TODO comment. (view_cleanup): Implement the cleanup handler. (view_layout): New function thar recalculates the layout. (view_make): Accept the parent window as an argument to initialize the view. Setup pool cleanup. (view_on_event): Call view_layout() to update layout each update. Now we can use the size of view->list directly to get the height of the scrollable area. (view_draw_item, view_draw_info_bar): Draw on a WINDOW passed as an argument. Curses API has the same functions that work with that WINDOW. They are all prefixed with a 'w'. (view_draw): Pass a window to view_draw_item() and view_draw_info_bar(). (sub_main): Pass stdscr when creating a view. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1933001 13f79535-47bb-0310-9956-ffa450edef68
1 parent b513f92 commit e3c320a

1 file changed

Lines changed: 62 additions & 27 deletions

File tree

subversion/svnbrowse/svnbrowse.c

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,54 @@ enum {
125125
};
126126

127127
typedef struct svn_browse__view_t {
128-
/* TODO: store information about terminal screen (a WINDOW* in curses world) */
129128
svn_browse__model_t *model;
129+
WINDOW *screen;
130+
WINDOW *infobar;
131+
WINDOW *list;
130132
} svn_browse__view_t;
131133

134+
static apr_status_t
135+
view_cleanup(void *ctx)
136+
{
137+
svn_browse__view_t *view = ctx;
138+
delwin(view->infobar);
139+
delwin(view->list);
140+
return APR_SUCCESS;
141+
}
142+
143+
static void
144+
view_layout(svn_browse__view_t *view)
145+
{
146+
int infobar_height = 1;
147+
int cols = getmaxx(view->screen);
148+
int rows = getmaxy(view->screen);
149+
150+
delwin(view->infobar);
151+
delwin(view->list);
152+
153+
view->infobar = subwin(view->screen, infobar_height, cols, 0, 0);
154+
view->list = subwin(view->screen, rows - infobar_height, cols,
155+
infobar_height, 0);
156+
}
157+
132158
static svn_browse__view_t *
133-
view_make(svn_browse__model_t *model, apr_pool_t *result_pool)
159+
view_make(svn_browse__model_t *model, WINDOW *win, apr_pool_t *result_pool)
134160
{
135161
svn_browse__view_t *view = apr_pcalloc(result_pool, sizeof(*view));
136162
view->model = model;
163+
view->screen = win;
164+
view_layout(view);
165+
apr_pool_cleanup_register(result_pool, view, view_cleanup, NULL);
137166
return view;
138167
}
139168

140169
static svn_error_t *
141170
view_on_event(svn_browse__view_t *view, int ch, apr_pool_t *scratch_pool)
142171
{
172+
view_layout(view);
173+
143174
/* scrollable height is one row less than the whole view */
144-
int scrollsize = getmaxy(stdscr) - 1;
175+
int scrollsize = getmaxy(view->list);
145176

146177
/* ch is received from getch() which would read the next character/key with
147178
* the following additional rules:
@@ -304,53 +335,57 @@ get_item_style(svn_node_kind_t kind, svn_boolean_t selected)
304335
}
305336

306337
static void
307-
view_draw_item(const svn_browse__item_t *item, int y, svn_boolean_t selected,
308-
apr_pool_t *scratch_pool)
338+
view_draw_item(const svn_browse__item_t *item, WINDOW *win, int y,
339+
svn_boolean_t selected, apr_pool_t *scratch_pool)
309340
{
310341
int attrs = 0;
311342
const char *prefix;
312343

313344
move(y, 0);
314-
attrset(get_item_style(item->dirent->kind, selected));
345+
wattrset(win, get_item_style(item->dirent->kind, selected));
315346

316347
/* 12 + 12 + (20 + 1) + 2 = 47 */
317348

318-
addch(' ');
319-
addstr(rightpad(format_node_name(item, scratch_pool),
320-
COLS - 47, scratch_pool));
321-
322-
attrset(get_item_style(svn_node_file, selected));
323-
addstr(leftpad(format_node_size(item, scratch_pool), 12, scratch_pool));
324-
addstr(leftpad(apr_psprintf(scratch_pool, "r%ld", item->dirent->created_rev),
325-
12, scratch_pool));
326-
addch(' ');
327-
addstr(rightpad(item->dirent->last_author, 20, scratch_pool));
328-
addch(' ');
349+
waddch(win, ' ');
350+
waddstr(win, rightpad(format_node_name(item, scratch_pool),
351+
getmaxx(win) - 47, scratch_pool));
352+
353+
wattrset(win, get_item_style(svn_node_file, selected));
354+
waddstr(win,
355+
leftpad(format_node_size(item, scratch_pool), 12, scratch_pool));
356+
waddstr(win, leftpad(apr_psprintf(scratch_pool, "r%ld",
357+
item->dirent->created_rev),
358+
12, scratch_pool));
359+
waddch(win, ' ');
360+
waddstr(win, rightpad(item->dirent->last_author, 20, scratch_pool));
361+
waddch(win, ' ');
329362
}
330363

331364
static void
332-
view_draw_info_bar(svn_browse__view_t *view, apr_pool_t *scratch_pool)
365+
view_draw_info_bar(svn_browse__view_t *view, WINDOW *win,
366+
apr_pool_t *scratch_pool)
333367
{
334368
const char *abspath = svn_path_url_add_component2(
335369
view->model->root, view->model->current->relpath, scratch_pool);
336370
svn_stringbuf_t *buf = svn_stringbuf_create_empty(scratch_pool);
337371
const char *prefix = " ";
338372
const char *suffix = "Apache Subversion ";
339373

340-
move(0, 0);
341-
attrset(COLOR_PAIR(COLOR_PAIR_INFO_BAR));
342-
addstr(prefix);
343-
addstr(rightpad(apr_psprintf(scratch_pool, "URL: %s", abspath),
344-
COLS - strlen(prefix) - strlen(suffix), scratch_pool));
345-
addstr(suffix);
374+
wmove(win, 0, 0);
375+
wattrset(win, COLOR_PAIR(COLOR_PAIR_INFO_BAR));
376+
waddstr(win, prefix);
377+
waddstr(win, rightpad(apr_psprintf(scratch_pool, "URL: %s", abspath),
378+
getmaxx(win) - strlen(prefix) - strlen(suffix),
379+
scratch_pool));
380+
waddstr(win, suffix);
346381
}
347382

348383
static void
349384
view_draw(svn_browse__view_t *view, apr_pool_t *pool)
350385
{
351386
int i;
352387

353-
view_draw_info_bar(view, pool);
388+
view_draw_info_bar(view, view->infobar, pool);
354389

355390
for (i = 0; i < view->model->current->list->nelts; i++)
356391
{
@@ -360,7 +395,7 @@ view_draw(svn_browse__view_t *view, apr_pool_t *pool)
360395
int y = i - view->model->current->scroller_offset;
361396

362397
if (0 <= y && y < LINES)
363-
view_draw_item(item, y + 1, selected, pool);
398+
view_draw_item(item, view->list, y + 1, selected, pool);
364399
}
365400
}
366401

@@ -598,7 +633,7 @@ sub_main(int *code, int argc, const char *argv[], apr_pool_t *pool)
598633
init_pair(COLOR_PAIR_FILE, -1, -1);
599634
init_pair(COLOR_PAIR_FILE_SELECTED, -1, COLOR_PRIMARY);
600635

601-
view = view_make(ctx, pool);
636+
view = view_make(ctx, stdscr, pool);
602637

603638
iterpool = svn_pool_create(pool);
604639

0 commit comments

Comments
 (0)