index 4a42cf7bbb7656d7c67b9bc57b366e58425156cf..e58a6b65f2f3e3c5e50f15c7c275f569fbdd11aa 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;
- /* Default command arguments. */
- const char **argv;
/* Open and reads in all view content. */
bool (*open)(struct view *view, enum open_flags flags);
/* Read one line; updates view->line. */
#define VIEW_MAX_LEN(view) ((view)->width + (view)->yoffset - (view)->col)
-static int
+static bool
draw_chars(struct view *view, enum line_type type, const char *string,
int max_len, bool use_tilde)
{
size_t skip = view->yoffset > view->col ? view->yoffset - view->col : 0;
if (max_len <= 0)
- return 0;
+ return VIEW_MAX_LEN(view) <= 0;
len = utf8_length(&string, skip, &col, max_len, &trimmed, use_tilde, opt_tab_size);
}
}
- return col;
+ view->col += col;
+ return VIEW_MAX_LEN(view) <= 0;
}
-static int
+static bool
draw_space(struct view *view, enum line_type type, int max, int spaces)
{
static char space[] = " ";
- int col = 0;
spaces = MIN(max, spaces);
while (spaces > 0) {
int len = MIN(spaces, sizeof(space) - 1);
- col += draw_chars(view, type, space, len, FALSE);
+ if (draw_chars(view, type, space, len, FALSE))
+ return TRUE;
spaces -= len;
}
- return col;
+ return VIEW_MAX_LEN(view) <= 0;
}
static bool
do {
size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);
- view->col += draw_chars(view, type, text, VIEW_MAX_LEN(view), TRUE);
+ if (draw_chars(view, type, text, VIEW_MAX_LEN(view), TRUE))
+ return TRUE;
string += pos;
- } while (*string && VIEW_MAX_LEN(view) > 0);
+ } while (*string);
return VIEW_MAX_LEN(view) <= 0;
}
draw_field(struct view *view, enum line_type type, const char *text, int len, bool trim)
{
int max = MIN(VIEW_MAX_LEN(view), len);
- int col;
+ int col = view->col;
- if (text)
- col = draw_chars(view, type, text, max - 1, trim);
- else
- col = draw_space(view, type, max - 1, max - 1);
+ if (!text)
+ return draw_space(view, type, max, max);
- view->col += col;
- view->col += draw_space(view, LINE_DEFAULT, max - col, max - col);
- return VIEW_MAX_LEN(view) <= 0;
+ return draw_chars(view, type, text, max - 1, trim)
+ || draw_space(view, LINE_DEFAULT, max - (view->col - col), max);
}
static bool
text = number;
}
if (text)
- view->col += draw_chars(view, LINE_LINE_NUMBER, text, max, TRUE);
+ draw_chars(view, LINE_LINE_NUMBER, text, max, TRUE);
else
- view->col += draw_space(view, LINE_LINE_NUMBER, max, digits3);
+ draw_space(view, LINE_LINE_NUMBER, max, digits3);
return draw_graphic(view, LINE_DEFAULT, &separator, 1, TRUE);
}
}
static bool
-begin_update(struct view *view, const char *dir, enum open_flags flags)
+begin_update(struct view *view, const char *dir, const char **argv, enum open_flags flags)
{
bool reload = !!(flags & (OPEN_RELOAD | OPEN_REFRESH | OPEN_PREPARED));
bool refresh = flags & (OPEN_REFRESH | OPEN_PREPARED);
end_update(view, TRUE);
if (!refresh) {
- if (!prepare_io(view, dir, view->ops->argv, TRUE))
+ if (!prepare_io(view, dir, argv, TRUE))
return FALSE;
/* Put the current ref_* value to the view title ref
static bool
view_open(struct view *view, enum open_flags flags)
{
- return begin_update(view, NULL, flags);
+ return begin_update(view, NULL, NULL, flags);
}
static bool
static struct view_ops pager_ops = {
"line",
- NULL,
view_open,
pager_read,
pager_draw,
pager_select,
};
-static const char *log_argv[SIZEOF_ARG] = {
- "git", "log", "--no-color", "--cc", "--stat", "-n100", "%(head)", NULL
-};
+static bool
+log_open(struct view *view, enum open_flags flags)
+{
+ static const char *log_argv[] = {
+ "git", "log", "--no-color", "--cc", "--stat", "-n100", "%(head)", NULL
+ };
+
+ return begin_update(view, NULL, log_argv, flags);
+}
static enum request
log_request(struct view *view, enum request request, struct line *line)
static struct view_ops log_ops = {
"line",
- log_argv,
- view_open,
+ log_open,
pager_read,
pager_draw,
log_request,
pager_select,
};
-static const char *diff_argv[SIZEOF_ARG] = {
- "git", "show", "--pretty=fuller", "--no-color", "--root",
- "--patch-with-stat", "--find-copies-harder", "-C",
- "%(diffargs)", "%(commit)", "--", "%(fileargs)", NULL
-};
+static bool
+diff_open(struct view *view, enum open_flags flags)
+{
+ static const char *diff_argv[] = {
+ "git", "show", "--pretty=fuller", "--no-color", "--root",
+ "--patch-with-stat", "--find-copies-harder", "-C",
+ "%(diffargs)", "%(commit)", "--", "%(fileargs)", NULL
+ };
+
+ return begin_update(view, NULL, diff_argv, flags);
+}
static bool
diff_read(struct view *view, char *data)
static struct view_ops diff_ops = {
"line",
- diff_argv,
- view_open,
+ diff_open,
diff_read,
pager_draw,
pager_request,
static struct view_ops help_ops = {
"line",
- NULL,
help_open,
NULL,
pager_draw,
static bool
tree_open(struct view *view, enum open_flags flags)
{
+ static const char *tree_argv[] = {
+ "git", "ls-tree", "%(commit)", "%(directory)", NULL
+ };
+
if (view->lines == 0 && opt_prefix[0]) {
char *pos = opt_prefix;
opt_path[0] = 0;
}
- return begin_update(view, opt_cdup, flags);
+ return begin_update(view, opt_cdup, tree_argv, flags);
}
-static const char *tree_argv[SIZEOF_ARG] = {
- "git", "ls-tree", "%(commit)", "%(directory)", NULL
-};
-
static struct view_ops tree_ops = {
"file",
- tree_argv,
tree_open,
tree_read,
tree_draw,
tree_select,
};
+static bool
+blob_open(struct view *view, enum open_flags flags)
+{
+ static const char *blob_argv[] = {
+ "git", "cat-file", "blob", "%(blob)", NULL
+ };
+
+ return begin_update(view, NULL, blob_argv, flags);
+}
+
static bool
blob_read(struct view *view, char *line)
{
}
}
-static const char *blob_argv[SIZEOF_ARG] = {
- "git", "cat-file", "blob", "%(blob)", NULL
-};
-
static struct view_ops blob_ops = {
"line",
- blob_argv,
- view_open,
+ blob_open,
blob_read,
pager_draw,
blob_request,
static struct view_ops blame_ops = {
"line",
- NULL,
blame_open,
blame_read,
blame_draw,
static struct view_ops branch_ops = {
"branch",
- NULL,
branch_open,
branch_read,
branch_draw,
static struct view_ops status_ops = {
"file",
- NULL,
status_open,
NULL,
status_draw,
static struct view_ops stage_ops = {
"line",
- NULL,
view_open,
pager_read,
pager_draw,
struct graph_canvas graph; /* Ancestry chain graphics. */
};
-static const char *main_argv[SIZEOF_ARG] = {
- "git", "log", "--no-color", "--pretty=raw", "--parents",
- "--topo-order", "%(diffargs)", "%(revargs)",
- "--", "%(fileargs)", NULL
-};
+static bool
+main_open(struct view *view, enum open_flags flags)
+{
+ static const char *main_argv[] = {
+ "git", "log", "--no-color", "--pretty=raw", "--parents",
+ "--topo-order", "%(diffargs)", "%(revargs)",
+ "--", "%(fileargs)", NULL
+ };
+
+ return begin_update(view, NULL, main_argv, flags);
+}
static bool
main_draw(struct view *view, struct line *line, unsigned int lineno)
static struct view_ops main_ops = {
"commit",
- main_argv,
- view_open,
+ main_open,
main_read,
main_draw,
main_request,