Code

Add VIEW_MAX_LEN macro to aid when drawing
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index f56547455c50dcf170dbdb0f8424915a9db2c40e..a7dd9154dd5f609da7f65e44746230d73197f199 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -1378,7 +1378,6 @@ enum view_type {
 struct view {
        enum view_type type;    /* View type */
        const char *name;       /* View name */
-       const char *cmd_env;    /* Command line set via environment */
        const char *id;         /* Points to either of ref_{head,commit,blob} */
 
        struct view_ops *ops;   /* View operations */
@@ -1463,11 +1462,11 @@ static struct view_ops status_ops;
 static struct view_ops tree_ops;
 static struct view_ops branch_ops;
 
-#define VIEW_STR(type, name, env, ref, ops, map, git) \
-       { type, name, #env, ref, ops, map, git }
+#define VIEW_STR(type, name, ref, ops, map, git) \
+       { type, name, ref, ops, map, git }
 
 #define VIEW_(id, name, ops, git, ref) \
-       VIEW_STR(VIEW_##id, name, TIG_##id##_CMD, ref, ops, KEYMAP_##id, git)
+       VIEW_STR(VIEW_##id, name, ref, ops, KEYMAP_##id, git)
 
 static struct view views[] = {
        VIEW_(MAIN,   "main",   &main_ops,   TRUE,  ref_head),
@@ -1514,6 +1513,8 @@ set_view_attr(struct view *view, enum line_type type)
        }
 }
 
+#define VIEW_MAX_LEN(view) ((view)->width + (view)->yoffset - (view)->col)
+
 static int
 draw_chars(struct view *view, enum line_type type, const char *string,
           int max_len, bool use_tilde)
@@ -1585,18 +1586,18 @@ draw_text(struct view *view, enum line_type type, const char *string)
        do {
                size_t pos = string_expand(text, sizeof(text), string, opt_tab_size);
 
-               view->col += draw_chars(view, type, text, view->width + view->yoffset - view->col, TRUE);
+               view->col += draw_chars(view, type, text, VIEW_MAX_LEN(view), TRUE);
                string += pos;
-       } while (*string && view->width + view->yoffset > view->col);
+       } while (*string && VIEW_MAX_LEN(view) > 0);
 
-       return view->width + view->yoffset <= view->col;
+       return VIEW_MAX_LEN(view) <= 0;
 }
 
 static bool
 draw_graphic(struct view *view, enum line_type type, const chtype graphic[], size_t size, bool separator)
 {
        size_t skip = view->yoffset > view->col ? view->yoffset - view->col : 0;
-       int max = view->width + view->yoffset - view->col;
+       int max = VIEW_MAX_LEN(view);
        int i;
 
        if (max < size)
@@ -1615,13 +1616,13 @@ draw_graphic(struct view *view, enum line_type type, const chtype graphic[], siz
                view->col++;
        }
 
-       return view->width + view->yoffset <= view->col;
+       return VIEW_MAX_LEN(view) <= 0;
 }
 
 static bool
 draw_field(struct view *view, enum line_type type, const char *text, int len, bool trim)
 {
-       int max = MIN(view->width + view->yoffset - view->col, len);
+       int max = MIN(VIEW_MAX_LEN(view), len);
        int col;
 
        if (text)
@@ -1631,7 +1632,7 @@ draw_field(struct view *view, enum line_type type, const char *text, int len, bo
 
        view->col += col;
        view->col += draw_space(view, LINE_DEFAULT, max - col, max - col);
-       return view->width + view->yoffset <= view->col;
+       return VIEW_MAX_LEN(view) <= 0;
 }
 
 static bool
@@ -1681,7 +1682,7 @@ draw_lineno(struct view *view, unsigned int lineno)
 {
        char number[10];
        int digits3 = view->digits < 3 ? 3 : view->digits;
-       int max = MIN(view->width + view->yoffset - view->col, digits3);
+       int max = MIN(VIEW_MAX_LEN(view), digits3);
        char *text = NULL;
        chtype separator = opt_line_graphics ? ACS_VLINE : '|';
 
@@ -6874,7 +6875,6 @@ main(int argc, const char *argv[])
        const char *codeset = "UTF-8";
        enum request request = parse_options(argc, argv);
        struct view *view;
-       size_t i;
 
        signal(SIGINT, quit);
        signal(SIGPIPE, SIG_IGN);
@@ -6911,16 +6911,6 @@ main(int argc, const char *argv[])
        if (load_refs() == ERR)
                die("Failed to load refs.");
 
-       foreach_view (view, i) {
-               if (getenv(view->cmd_env))
-                       warn("Use of the %s environment variable is deprecated,"
-                            " use options or TIG_DIFF_ARGS instead",
-                            view->cmd_env);
-               if (!argv_from_env(view->ops->argv, view->cmd_env))
-                       die("Too many arguments in the `%s` environment variable",
-                           view->cmd_env);
-       }
-
        init_display();
 
        while (view_driver(display[current_view], request)) {