Code

Add an option (and toggle) for shortening the date column by skipping the time.
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index 60d73d52cdb0e8d58629c41b5bfa798268e1a883..55e022468ee15d7add89caa417d6b5b811a66caa 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -72,6 +72,7 @@ static size_t utf8_length(const char **string, size_t col, int *width, size_t ma
 
 #define ABS(x)         ((x) >= 0  ? (x) : -(x))
 #define MIN(x, y)      ((x) < (y) ? (x) :  (y))
+#define MAX(x, y)      ((x) > (y) ? (x) :  (y))
 
 #define ARRAY_SIZE(x)  (sizeof(x) / sizeof(x[0]))
 #define STRING_SIZE(x) (sizeof(x) - 1)
@@ -102,16 +103,11 @@ static size_t utf8_length(const char **string, size_t col, int *width, size_t ma
 /* The format and size of the date column in the main view. */
 #define DATE_FORMAT    "%Y-%m-%d %H:%M"
 #define DATE_COLS      STRING_SIZE("2006-04-29 14:21 ")
+#define DATE_SHORT_COLS        STRING_SIZE("2006-04-29 ")
 
-#define AUTHOR_COLS    20
 #define ID_COLS                8
 
-/* The default interval between line numbers. */
-#define NUMBER_INTERVAL        5
-
-#define TAB_SIZE       8
-
-#define        SCALE_SPLIT_VIEW(height)        ((height) * 2 / 3)
+#define MIN_VIEW_HEIGHT 4
 
 #define NULL_ID                "0000000000000000000000000000000000000000"
 
@@ -842,6 +838,7 @@ run_io_load(const char **argv, const char *separators,
        REQ_(OPTIONS,           "Open option menu"), \
        REQ_(TOGGLE_LINENO,     "Toggle line numbers"), \
        REQ_(TOGGLE_DATE,       "Toggle date display"), \
+       REQ_(TOGGLE_DATE_SHORT, "Toggle short (date-only) dates"), \
        REQ_(TOGGLE_AUTHOR,     "Toggle author display"), \
        REQ_(TOGGLE_REV_GRAPH,  "Toggle revision graph visualization"), \
        REQ_(TOGGLE_REFS,       "Toggle reference display (tags/branches)"), \
@@ -906,15 +903,17 @@ get_request(const char *name)
 
 /* Option and state variables. */
 static bool opt_date                   = TRUE;
+static bool opt_date_short             = FALSE;
 static bool opt_author                 = TRUE;
 static bool opt_line_number            = FALSE;
 static bool opt_line_graphics          = TRUE;
 static bool opt_rev_graph              = FALSE;
 static bool opt_show_refs              = TRUE;
-static int opt_num_interval            = NUMBER_INTERVAL;
+static int opt_num_interval            = 5;
 static double opt_hscroll              = 0.50;
-static int opt_tab_size                        = TAB_SIZE;
-static int opt_author_cols             = AUTHOR_COLS-1;
+static double opt_scale_split_view     = 2.0 / 3.0;
+static int opt_tab_size                        = 8;
+static int opt_author_cols             = 19;
 static char opt_path[SIZEOF_STR]       = "";
 static char opt_file[SIZEOF_STR]       = "";
 static char opt_ref[SIZEOF_REF]                = "";
@@ -1158,6 +1157,7 @@ static const struct keybinding default_keybindings[] = {
        { 'o',          REQ_OPTIONS },
        { '.',          REQ_TOGGLE_LINENO },
        { 'D',          REQ_TOGGLE_DATE },
+       { 'T',          REQ_TOGGLE_DATE_SHORT },
        { 'A',          REQ_TOGGLE_AUTHOR },
        { 'g',          REQ_TOGGLE_REV_GRAPH },
        { 'F',          REQ_TOGGLE_REFS },
@@ -1492,7 +1492,7 @@ option_color_command(int argc, const char *argv[])
 {
        struct line_info *info;
 
-       if (argc != 3 && argc != 4) {
+       if (argc < 3) {
                config_msg = "Wrong number of arguments given to color command";
                return ERR;
        }
@@ -1519,9 +1519,15 @@ option_color_command(int argc, const char *argv[])
                return ERR;
        }
 
-       if (argc == 4 && !set_attribute(&info->attr, argv[3])) {
-               config_msg = "Unknown attribute";
-               return ERR;
+       info->attr = 0;
+       while (argc-- > 3) {
+               int attr;
+
+               if (!set_attribute(&attr, argv[argc])) {
+                       config_msg = "Unknown attribute";
+                       return ERR;
+               }
+               info->attr |= attr;
        }
 
        return OK;
@@ -1573,6 +1579,9 @@ option_set_command(int argc, const char *argv[])
        if (!strcmp(argv[0], "show-date"))
                return parse_bool(&opt_date, argv[2]);
 
+       if (!strcmp(argv[0], "date-short"))
+               return parse_bool(&opt_date_short, argv[2]);
+
        if (!strcmp(argv[0], "show-rev-graph"))
                return parse_bool(&opt_rev_graph, argv[2]);
 
@@ -1594,6 +1603,9 @@ option_set_command(int argc, const char *argv[])
        if (!strcmp(argv[0], "horizontal-scroll"))
                return parse_step(&opt_hscroll, argv[2]);
 
+       if (!strcmp(argv[0], "split-view-height"))
+               return parse_step(&opt_scale_split_view, argv[2]);
+
        if (!strcmp(argv[0], "tab-size"))
                return parse_int(&opt_tab_size, argv[2], 1, 1024);
 
@@ -1609,7 +1621,7 @@ static int
 option_bind_command(int argc, const char *argv[])
 {
        enum request request;
-       int keymap;
+       int keymap = -1;
        int key;
 
        if (argc < 3) {
@@ -2021,8 +2033,9 @@ static bool
 draw_date(struct view *view, time_t *time)
 {
        const char *date = mkdate(time);
+       int cols = opt_date_short ? DATE_SHORT_COLS : DATE_COLS;
 
-       return draw_field(view, LINE_DATE, date, DATE_COLS, FALSE);
+       return draw_field(view, LINE_DATE, date, cols, FALSE);
 }
 
 static bool
@@ -2223,6 +2236,15 @@ update_view_title(struct view *view)
        wnoutrefresh(view->title);
 }
 
+static int
+apply_step(double step, int value)
+{
+       if (step >= 1)
+               return (int) step;
+       value *= step + 0.01;
+       return value ? value : 1;
+}
+
 static void
 resize_display(void)
 {
@@ -2240,7 +2262,9 @@ resize_display(void)
        if (view != base) {
                /* Horizontal split. */
                view->width   = base->width;
-               view->height  = SCALE_SPLIT_VIEW(base->height);
+               view->height  = apply_step(opt_scale_split_view, base->height);
+               view->height  = MAX(view->height, MIN_VIEW_HEIGHT);
+               view->height  = MIN(view->height, base->height - MIN_VIEW_HEIGHT);
                base->height -= view->height;
 
                /* Make room for the title bar. */
@@ -2353,15 +2377,6 @@ goto_view_line(struct view *view, unsigned long offset, unsigned long lineno)
        return FALSE;
 }
 
-static int
-apply_step(double step, int value)
-{
-       if (step >= 1)
-               return (int) step;
-       value *= step + 0.01;
-       return value ? value : 1;
-}
-
 /* Scrolling backend */
 static void
 do_scroll_view(struct view *view, int lines)
@@ -3315,6 +3330,10 @@ view_driver(struct view *view, enum request request)
                toggle_view_option(&opt_date, "date display");
                break;
 
+       case REQ_TOGGLE_DATE_SHORT:
+               toggle_view_option(&opt_date_short, "date shortening");
+               break;
+
        case REQ_TOGGLE_AUTHOR:
                toggle_view_option(&opt_author, "author display");
                break;
@@ -3530,7 +3549,7 @@ open_commit_parent_menu(char buf[SIZEOF_STR], int *parents)
        int i;
 
        items = calloc(*parents + 1, sizeof(*items));
-       if (items)
+       if (!items)
                return FALSE;
 
        for (i = 0; i < *parents; i++) {
@@ -5478,7 +5497,7 @@ status_update_files(struct view *view, struct line *line)
        struct line *pos = view->line + view->lines;
        int files = 0;
        int file, done;
-       int cursor_y, cursor_x;
+       int cursor_y = -1, cursor_x = -1;
 
        if (!status_update_prepare(&io, line->type))
                return FALSE;