summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2463b4e)
raw | patch | inline | side by side (parent: 2463b4e)
author | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 29 May 2007 23:18:31 +0000 (01:18 +0200) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 29 May 2007 23:18:42 +0000 (01:18 +0200) |
Use it to turn open_help_view into help_open and make a backend for the
help view.
help view.
tig.c | patch | blob | history |
index dde4369f183744548ce57e4c3b98c707919d387b..be4b80c774d44902a1160f271d5bc4c8a11bdef8 100644 (file)
--- a/tig.c
+++ b/tig.c
struct view_ops {
/* What type of content being displayed. Used in the title bar. */
const char *type;
- /* Draw one line; @lineno must be < view->height. */
- bool (*draw)(struct view *view, struct line *line, unsigned int lineno, bool selected);
+ /* Open and reads in all view content. */
+ bool (*open)(struct view *view);
/* Read one line; updates view->line. */
bool (*read)(struct view *view, char *data);
+ /* Draw one line; @lineno must be < view->height. */
+ bool (*draw)(struct view *view, struct line *line, unsigned int lineno, bool selected);
/* Depending on view, change display based on current line. */
bool (*enter)(struct view *view, struct line *line);
/* Search for regex in a line. */
static struct view_ops main_ops;
static struct view_ops tree_ops;
static struct view_ops blob_ops;
+static struct view_ops help_ops;
#define VIEW_STR(name, cmd, env, ref, ops, map) \
{ name, cmd, #env, ref, ops, map}
VIEW_(LOG, "log", &pager_ops, ref_head),
VIEW_(TREE, "tree", &tree_ops, ref_commit),
VIEW_(BLOB, "blob", &blob_ops, ref_blob),
- VIEW_(HELP, "help", &pager_ops, ""),
+ VIEW_(HELP, "help", &help_ops, ""),
VIEW_(PAGER, "pager", &pager_ops, ""),
};
* View opening
*/
-static void open_help_view(struct view *view)
-{
- char buf[BUFSIZ];
- int lines = ARRAY_SIZE(req_info) + 2;
- int i;
-
- if (view->lines > 0)
- return;
-
- for (i = 0; i < ARRAY_SIZE(req_info); i++)
- if (!req_info[i].request)
- lines++;
-
- view->line = calloc(lines, sizeof(*view->line));
- if (!view->line) {
- report("Allocation failure");
- return;
- }
-
- add_line_text(view, "Quick reference for tig keybindings:", LINE_DEFAULT);
-
- for (i = 0; i < ARRAY_SIZE(req_info); i++) {
- char *key;
-
- if (!req_info[i].request) {
- add_line_text(view, "", LINE_DEFAULT);
- add_line_text(view, req_info[i].help, LINE_DEFAULT);
- continue;
- }
-
- key = get_key(req_info[i].request);
- if (!string_format(buf, " %-25s %s", key, req_info[i].help))
- continue;
-
- add_line_text(view, buf, LINE_DEFAULT);
- }
-}
-
enum open_flags {
OPEN_DEFAULT = 0, /* Use default view switching. */
OPEN_SPLIT = 1, /* Split current view. */
return;
}
- if (view == VIEW(REQ_VIEW_HELP)) {
- open_help_view(view);
+ if (view->ops->open) {
+ if (!view->ops->open(view)) {
+ report("Failed to load %s view", view->name);
+ return;
+ }
} else if ((reload || strcmp(view->vid, view->id)) &&
!begin_update(view)) {
static struct view_ops pager_ops = {
"line",
- pager_draw,
+ NULL,
pager_read,
+ pager_draw,
+ pager_enter,
+ pager_grep,
+ pager_select,
+};
+
+
+/*
+ * Help backend
+ */
+
+static bool
+help_open(struct view *view)
+{
+ char buf[BUFSIZ];
+ int lines = ARRAY_SIZE(req_info) + 2;
+ int i;
+
+ if (view->lines > 0)
+ return TRUE;
+
+ for (i = 0; i < ARRAY_SIZE(req_info); i++)
+ if (!req_info[i].request)
+ lines++;
+
+ view->line = calloc(lines, sizeof(*view->line));
+ if (!view->line)
+ return FALSE;
+
+ add_line_text(view, "Quick reference for tig keybindings:", LINE_DEFAULT);
+
+ for (i = 0; i < ARRAY_SIZE(req_info); i++) {
+ char *key;
+
+ if (!req_info[i].request) {
+ add_line_text(view, "", LINE_DEFAULT);
+ add_line_text(view, req_info[i].help, LINE_DEFAULT);
+ continue;
+ }
+
+ key = get_key(req_info[i].request);
+ if (!string_format(buf, " %-25s %s", key, req_info[i].help))
+ continue;
+
+ add_line_text(view, buf, LINE_DEFAULT);
+ }
+
+ return TRUE;
+}
+
+static struct view_ops help_ops = {
+ "line",
+ help_open,
+ NULL,
+ pager_draw,
pager_enter,
pager_grep,
pager_select,
static struct view_ops tree_ops = {
"file",
- pager_draw,
+ NULL,
tree_read,
+ pager_draw,
tree_enter,
pager_grep,
tree_select,
static struct view_ops blob_ops = {
"line",
- pager_draw,
+ NULL,
blob_read,
+ pager_draw,
pager_enter,
pager_grep,
pager_select,
static struct view_ops main_ops = {
"commit",
- main_draw,
+ NULL,
main_read,
+ main_draw,
main_enter,
main_grep,
main_select,