Skip to content

Commit 06f8cb1

Browse files
committed
svnbrowse: Add a 'status bar' in the bottom.
Now there is little confusion between the info bar and the status bar. The info bar is the thing on top and status bar is behind the list. I find a better name for them in a following commit. The status bar will display the action that is currently running. For example, when we are fetching stuff from server, the text will be updated from 'Ready' to something else. Which is not yet implemented and it always displays fixed title. On the right hand side, there is information about the scroller. Its design is almost fully stolen from vim; it shows percentage of current page's scrolling offset with custom title when displaying the whole directory on a single page and the most top & bottom positioning. The 'branding' title is now moved to the status bar so it doesn't take space from URL. * subversion/svnbrowse/svnbrowse.c (COLOR_PAIR_STATUS_BAR): New constant. (svn_browse__view_t): Add statusbar to the struct. (view_layout): Setup layout for the new statusbar; it takes one more line from the list. (view_draw_info_bar): Remove branding. (format_percentage_scroll): New function to handle thaf scroller title logic. (view_draw_status_bar): New function for rendering the status bar. (view_draw): Call view_draw_status_bar(). (sub_main): Initialize the COLOR_PAIR_STATUS_BAR color pair. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1933121 13f79535-47bb-0310-9956-ffa450edef68
1 parent 96b44ae commit 06f8cb1

1 file changed

Lines changed: 58 additions & 4 deletions

File tree

subversion/svnbrowse/svnbrowse.c

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const apr_getopt_option_t svn_browse__options[] =
117117

118118
enum {
119119
COLOR_PAIR_INFO_BAR = 1,
120+
COLOR_PAIR_STATUS_BAR,
120121
COLOR_PAIR_DIR,
121122
COLOR_PAIR_DIR_SELECTED,
122123
COLOR_PAIR_FILE,
@@ -128,6 +129,7 @@ typedef struct svn_browse__view_t {
128129
svn_browse__model_t *model;
129130
WINDOW *screen;
130131
WINDOW *infobar;
132+
WINDOW *statusbar;
131133
WINDOW *list;
132134
} svn_browse__view_t;
133135

@@ -143,16 +145,20 @@ view_cleanup(void *ctx)
143145
static void
144146
view_layout(svn_browse__view_t *view)
145147
{
146-
int infobar_height = 1;
147148
int cols = getmaxx(view->screen);
148149
int rows = getmaxy(view->screen);
150+
int infobar_height = 1;
151+
int statusbar_height = 1;
152+
int list_height = rows - infobar_height - statusbar_height;
149153

150154
delwin(view->infobar);
155+
delwin(view->statusbar);
151156
delwin(view->list);
152157

153158
view->infobar = subwin(view->screen, infobar_height, cols, 0, 0);
154-
view->list = subwin(view->screen, rows - infobar_height, cols,
155-
infobar_height, 0);
159+
view->list = subwin(view->screen, list_height, cols, infobar_height, 0);
160+
view->statusbar = subwin(view->screen, statusbar_height, cols,
161+
infobar_height + list_height, 0);
156162
}
157163

158164
static svn_browse__view_t *
@@ -369,7 +375,7 @@ view_draw_info_bar(svn_browse__view_t *view, WINDOW *win,
369375
view->model->root, view->model->current->relpath, scratch_pool);
370376
svn_stringbuf_t *buf = svn_stringbuf_create_empty(scratch_pool);
371377
const char *prefix = " ";
372-
const char *suffix = "Apache Subversion ";
378+
const char *suffix = " ";
373379

374380
wmove(win, 0, 0);
375381
wattrset(win, COLOR_PAIR(COLOR_PAIR_INFO_BAR));
@@ -380,12 +386,59 @@ view_draw_info_bar(svn_browse__view_t *view, WINDOW *win,
380386
waddstr(win, suffix);
381387
}
382388

389+
static char *
390+
format_percentage_scroll(int scroll, int size, int height, apr_pool_t *pool)
391+
{
392+
if (size <= height)
393+
return "All";
394+
else if (scroll <= 0)
395+
return "Top";
396+
else if (scroll + height >= size)
397+
return "Bot";
398+
else
399+
{
400+
/* Oops, if size and heigth perfectly line up, we would segfault to
401+
* division by zero. Nope... We wouldn not. There is a check right
402+
* above. */
403+
404+
int percentage = (scroll) * 100 / (size - height);
405+
return apr_psprintf(pool, "%d%%", percentage);
406+
}
407+
}
408+
409+
static void
410+
view_draw_status_bar(svn_browse__view_t *view, WINDOW *win,
411+
apr_pool_t *scratch_pool)
412+
{
413+
const char *brand = "Apache Subversion ";
414+
const svn_browse__state_t *state = view->model->current;
415+
416+
wmove(win, 0, 0);
417+
wattrset(win, COLOR_PAIR(COLOR_PAIR_STATUS_BAR));
418+
waddstr(win, " ");
419+
waddstr(win, rightpad(apr_psprintf(scratch_pool, "Ready"),
420+
getmaxx(win) - 4 - strlen(brand) - 16,
421+
scratch_pool));
422+
waddstr(win, brand);
423+
waddstr(win, leftpad(apr_psprintf(scratch_pool, "%d/%d",
424+
state->selection + 1, state->list->nelts),
425+
8, scratch_pool));
426+
waddstr(win, leftpad(format_percentage_scroll(state->scroller_offset,
427+
state->list->nelts,
428+
getmaxy(view->list),
429+
scratch_pool),
430+
8, scratch_pool));
431+
waddstr(win, " ");
432+
}
433+
434+
383435
static void
384436
view_draw(svn_browse__view_t *view, apr_pool_t *pool)
385437
{
386438
int i;
387439

388440
view_draw_info_bar(view, view->infobar, pool);
441+
view_draw_status_bar(view, view->statusbar, pool);
389442

390443
for (i = 0; i < view->model->current->list->nelts; i++)
391444
{
@@ -629,6 +682,7 @@ sub_main(int *code, int argc, const char *argv[], apr_pool_t *pool)
629682
use_default_colors();
630683

631684
init_pair(COLOR_PAIR_INFO_BAR, COLOR_YELLOW, COLOR_BRANDING);
685+
init_pair(COLOR_PAIR_STATUS_BAR, COLOR_YELLOW, COLOR_SECONDARY);
632686
init_pair(COLOR_PAIR_DIR, COLOR_CYAN, -1);
633687
init_pair(COLOR_PAIR_DIR_SELECTED, COLOR_CYAN, COLOR_PRIMARY);
634688
init_pair(COLOR_PAIR_FILE, -1, -1);

0 commit comments

Comments
 (0)