Skip to content

Commit 3a58c1f

Browse files
committed
svnbrowse: Rework application lifetime; Handle all updates directly in
view_update() instead of having two separate function to process keystrokes and update the screen. It's much for convenient to put all that stuff into the same function in case we need to make an intermediate update as an example. * subversion/svnbrowse/svnbrowse.c (view_on_event): Renamed to view_update and moved down. (view_draw): Remove and put all the code from it to the end of view_update(). (view_update): Collects logic from view_on_event() and view_draw(), add few more comments. (sub_main): Update the main loop to use right functions. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1936141 13f79535-47bb-0310-9956-ffa450edef68
1 parent 47329d5 commit 3a58c1f

1 file changed

Lines changed: 121 additions & 109 deletions

File tree

subversion/svnbrowse/svnbrowse.c

Lines changed: 121 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -249,104 +249,6 @@ view_make(svn_browse__model_t *model, svn_browse__style_t *style, WINDOW *win,
249249
return view;
250250
}
251251

252-
static svn_error_t *
253-
view_on_event(svn_browse__view_t *view, int ch, apr_pool_t *scratch_pool)
254-
{
255-
int scrollsize;
256-
view_layout(view);
257-
258-
/* scrollable height is one row less than the whole view */
259-
scrollsize = getmaxy(view->list);
260-
261-
/* ch is received from getch() which would read the next character/key with
262-
* the following additional rules:
263-
* 1. as we configured it to use keypad(), arrows and other special keys
264-
* are handled as KEY_XXX.
265-
* 2. Control (CTRL) version are handled as literal 1-26 values of ch where
266-
* 1 is <C-A> and 26 is <C-Z>.
267-
* 3. The rest of keys remain as their equivalents on the current layout.
268-
* 4. If shift is held, they just become uppercased.
269-
*/
270-
271-
switch (ch)
272-
{
273-
case KEY_BACKSPACE:
274-
case '-':
275-
case 'u':
276-
SVN_ERR(svn_browse__model_go_up(view->model, scratch_pool));
277-
view->model->current->scroller_offset =
278-
view->model->current->selection - scrollsize / 2;
279-
break;
280-
case 'q':
281-
case KEY_ESC:
282-
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
283-
default:
284-
break;
285-
}
286-
287-
if (view->model->current->type == svn_browse__state_dir)
288-
{
289-
switch (ch)
290-
{
291-
case KEY_UP:
292-
case 'k':
293-
case CTRL('p'):
294-
SVN_ERR(svn_browse__model_move_selection(view->model, -1));
295-
break;
296-
case KEY_DOWN:
297-
case 'j':
298-
case CTRL('n'):
299-
SVN_ERR(svn_browse__model_move_selection(view->model, 1));
300-
break;
301-
case '\n':
302-
case '\r':
303-
SVN_ERR(svn_browse__model_go_enter(view->model, scratch_pool));
304-
break;
305-
case CTRL('e'):
306-
view->model->current->scroller_offset += 1;
307-
break;
308-
case CTRL('y'):
309-
view->model->current->scroller_offset -= 1;
310-
break;
311-
case CTRL('d'):
312-
SVN_ERR(svn_browse__model_move_selection(view->model,
313-
scrollsize / 2));
314-
break;
315-
case CTRL('f'):
316-
case KEY_NPAGE:
317-
SVN_ERR(svn_browse__model_move_selection(view->model,
318-
scrollsize));
319-
break;
320-
case CTRL('u'):
321-
SVN_ERR(svn_browse__model_move_selection(view->model,
322-
-scrollsize / 2));
323-
break;
324-
case CTRL('b'):
325-
case KEY_PPAGE:
326-
SVN_ERR(svn_browse__model_move_selection(view->model,
327-
-scrollsize));
328-
break;
329-
case 'g':
330-
case KEY_HOME:
331-
view->model->current->selection = 0;
332-
break;
333-
case 'G':
334-
case KEY_END:
335-
view->model->current->selection =
336-
view->model->current->list->nelts - 1;
337-
break;
338-
case 'z':
339-
view->model->current->scroller_offset =
340-
view->model->current->selection - scrollsize / 2;
341-
break;
342-
}
343-
344-
SVN_ERR(svn_browse__model_scroll_in_view(view->model, scrollsize));
345-
}
346-
347-
return SVN_NO_ERROR;
348-
}
349-
350252
static const char *
351253
format_node_size(const svn_browse__item_t *item, apr_pool_t *pool)
352254
{
@@ -534,23 +436,131 @@ file_draw(svn_browse__view_t *view, apr_pool_t *pool)
534436
svn_time_to_human_cstring(state->this_dirent->time, pool));
535437
}
536438

537-
static void
538-
view_draw(svn_browse__view_t *view, apr_pool_t *pool)
439+
static svn_error_t *
440+
view_update(svn_browse__view_t *view, int ch, apr_pool_t *scratch_pool)
539441
{
540-
view_draw_header(view, view->header, pool);
541-
view_draw_footer(view, view->footer, pool);
442+
int scrollsize;
443+
444+
/* 1. Make sure inner views are layed out properly. */
445+
view_layout(view);
446+
447+
/* scrollable height is one row less than the whole view */
448+
scrollsize = getmaxy(view->list);
449+
450+
/* 2. Handle the event. Some of them we consider of being relevant no matter
451+
* what state we're in, while others might be specific for either file or
452+
* directory views */
453+
454+
/* ch is received from getch() which would read the next character/key with
455+
* the following additional rules:
456+
* 1. as we configured it to use keypad(), arrows and other special keys
457+
* are handled as KEY_XXX.
458+
* 2. Control (CTRL) version are handled as literal 1-26 values of ch where
459+
* 1 is <C-A> and 26 is <C-Z>.
460+
* 3. The rest of keys remain as their equivalents on the current layout.
461+
* 4. If shift is held, they just become uppercased.
462+
*/
463+
464+
switch (ch)
465+
{
466+
case KEY_BACKSPACE:
467+
case '-':
468+
case 'u':
469+
SVN_ERR(svn_browse__model_go_up(view->model, scratch_pool));
470+
view->model->current->scroller_offset =
471+
view->model->current->selection - scrollsize / 2;
472+
break;
473+
case 'q':
474+
case KEY_ESC:
475+
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
476+
default:
477+
break;
478+
}
479+
480+
if (view->model->current->type == svn_browse__state_dir)
481+
{
482+
switch (ch)
483+
{
484+
case KEY_UP:
485+
case 'k':
486+
case CTRL('p'):
487+
SVN_ERR(svn_browse__model_move_selection(view->model, -1));
488+
break;
489+
case KEY_DOWN:
490+
case 'j':
491+
case CTRL('n'):
492+
SVN_ERR(svn_browse__model_move_selection(view->model, 1));
493+
break;
494+
case '\n':
495+
case '\r':
496+
SVN_ERR(svn_browse__model_go_enter(view->model, scratch_pool));
497+
break;
498+
case CTRL('e'):
499+
view->model->current->scroller_offset += 1;
500+
break;
501+
case CTRL('y'):
502+
view->model->current->scroller_offset -= 1;
503+
break;
504+
case CTRL('d'):
505+
SVN_ERR(svn_browse__model_move_selection(view->model,
506+
scrollsize / 2));
507+
break;
508+
case CTRL('f'):
509+
case KEY_NPAGE:
510+
SVN_ERR(svn_browse__model_move_selection(view->model,
511+
scrollsize));
512+
break;
513+
case CTRL('u'):
514+
SVN_ERR(svn_browse__model_move_selection(view->model,
515+
-scrollsize / 2));
516+
break;
517+
case CTRL('b'):
518+
case KEY_PPAGE:
519+
SVN_ERR(svn_browse__model_move_selection(view->model,
520+
-scrollsize));
521+
break;
522+
case 'g':
523+
case KEY_HOME:
524+
view->model->current->selection = 0;
525+
break;
526+
case 'G':
527+
case KEY_END:
528+
view->model->current->selection =
529+
view->model->current->list->nelts - 1;
530+
break;
531+
case 'z':
532+
view->model->current->scroller_offset =
533+
view->model->current->selection - scrollsize / 2;
534+
break;
535+
}
536+
537+
SVN_ERR(svn_browse__model_scroll_in_view(view->model, scrollsize));
538+
}
539+
540+
/* 3. Update the screen. */
541+
542+
/* ### TODO: We don't actually need it. */
543+
clear();
544+
545+
view_draw_header(view, view->header, scratch_pool);
546+
view_draw_footer(view, view->footer, scratch_pool);
542547

543548
switch (view->model->current->type)
544549
{
545550
case svn_browse__state_dir:
546-
dir_draw(view, pool);
551+
dir_draw(view, scratch_pool);
547552
break;
548553
case svn_browse__state_file:
549-
file_draw(view, pool);
554+
file_draw(view, scratch_pool);
550555
break;
551556
}
557+
558+
refresh();
559+
560+
return SVN_NO_ERROR;
552561
}
553562

563+
554564
static svn_error_t *
555565
show_usage(apr_pool_t *scratch_pool)
556566
{
@@ -802,19 +812,21 @@ sub_main(int *code, int argc, const char *argv[], apr_pool_t *pool)
802812

803813
iterpool = svn_pool_create(pool);
804814

815+
/* Draw the initial state to the screen.
816+
*
817+
* ### Maybe there is a better way to make it do nothing but draw without
818+
* ### strangely looking "hack" with a null-char. It should be fine IMO. */
819+
err = view_update(view, '\0', iterpool);
820+
805821
/* Loop forever, unless we're not in an error state. */
806822
while (! err)
807823
{
808824
int ch;
809825

810826
svn_pool_clear(iterpool);
811827

812-
clear();
813-
view_draw(view, iterpool);
814-
refresh();
815-
816828
ch = getch();
817-
err = view_on_event(view, ch, iterpool);
829+
err = view_update(view, ch, iterpool);
818830
}
819831

820832
endwin();

0 commit comments

Comments
 (0)