Code

Refactor file mode drawing; rename tree-mode color to mode
authorJonas Fonseca <fonseca@diku.dk>
Wed, 4 Feb 2009 17:40:15 +0000 (18:40 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 5 Feb 2009 08:34:17 +0000 (09:34 +0100)
tig.c
tigrc.5.txt

diff --git a/tig.c b/tig.c
index bd9a7a4bf0852cd23413adf32c5eb3282beaadde..f1c8211f830a661e62acad81f3eecb61fc0ff06c 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -927,6 +927,7 @@ LINE(CURSOR,           "",                  COLOR_WHITE,    COLOR_GREEN,    A_BOLD), \
 LINE(STATUS,      "",                  COLOR_GREEN,    COLOR_DEFAULT,  0), \
 LINE(DELIMITER,           "",                  COLOR_MAGENTA,  COLOR_DEFAULT,  0), \
 LINE(DATE,         "",                 COLOR_BLUE,     COLOR_DEFAULT,  0), \
+LINE(MODE,         "",                 COLOR_CYAN,     COLOR_DEFAULT,  0), \
 LINE(LINE_NUMBER,  "",                 COLOR_CYAN,     COLOR_DEFAULT,  0), \
 LINE(TITLE_BLUR,   "",                 COLOR_WHITE,    COLOR_BLUE,     0), \
 LINE(TITLE_FOCUS,  "",                 COLOR_WHITE,    COLOR_BLUE,     A_BOLD), \
@@ -939,7 +940,6 @@ LINE(MAIN_REF,     "",                      COLOR_CYAN,     COLOR_DEFAULT,  0), \
 LINE(MAIN_HEAD,    "",                 COLOR_CYAN,     COLOR_DEFAULT,  A_BOLD), \
 LINE(MAIN_REVGRAPH,"",                 COLOR_MAGENTA,  COLOR_DEFAULT,  0), \
 LINE(TREE_PARENT,  "",                 COLOR_DEFAULT,  COLOR_DEFAULT,  A_BOLD), \
-LINE(TREE_MODE,    "",                 COLOR_CYAN,     COLOR_DEFAULT,  0), \
 LINE(TREE_DIR,     "",                 COLOR_YELLOW,   COLOR_DEFAULT,  A_NORMAL), \
 LINE(TREE_FILE,    "",                 COLOR_DEFAULT,  COLOR_DEFAULT,  A_NORMAL), \
 LINE(STAT_HEAD,    "",                 COLOR_YELLOW,   COLOR_DEFAULT,  0), \
@@ -2035,6 +2035,27 @@ draw_author(struct view *view, const char *author)
        return draw_field(view, LINE_AUTHOR, author, opt_author_cols, trim);
 }
 
+static bool
+draw_mode(struct view *view, mode_t mode)
+{
+       static const char dir_mode[]    = "drwxr-xr-x";
+       static const char link_mode[]   = "lrwxrwxrwx";
+       static const char exe_mode[]    = "-rwxr-xr-x";
+       static const char file_mode[]   = "-rw-r--r--";
+       const char *str;
+
+       if (S_ISDIR(mode))
+               str = dir_mode;
+       else if (S_ISLNK(mode))
+               str = link_mode;
+       else if (mode & S_IXUSR)
+               str = exe_mode;
+       else
+               str = file_mode;
+
+       return draw_field(view, LINE_MODE, str, sizeof(file_mode), FALSE);
+}
+
 static bool
 draw_view_line(struct view *view, unsigned int lineno)
 {
@@ -3966,23 +3987,7 @@ tree_draw(struct view *view, struct line *line, unsigned int lineno)
                if (draw_text(view, line->type, "Directory path /", TRUE))
                        return TRUE;
        } else {
-               char mode[11] = "-r--r--r--";
-
-               if (S_ISDIR(entry->mode)) {
-                       mode[3] = mode[6] = mode[9] = 'x';
-                       mode[0] = 'd';
-               }
-               if (S_ISLNK(entry->mode))
-                       mode[0] = 'l';
-               if (entry->mode & S_IWUSR)
-                       mode[2] = 'w';
-               if (entry->mode & S_IXUSR)
-                       mode[3] = 'x';
-               if (entry->mode & S_IXGRP)
-                       mode[6] = 'x';
-               if (entry->mode & S_IXOTH)
-                       mode[9] = 'x';
-               if (draw_field(view, LINE_TREE_MODE, mode, 11, TRUE))
+               if (draw_mode(view, entry->mode))
                        return TRUE;
 
                if (opt_author && draw_author(view, entry->author))
index 2beb269c11ab369e7402e784e1720478a2d84186..149fcd7a9fedf08532ea950515933bee1ad8f872 100644 (file)
@@ -371,6 +371,7 @@ delimiter           Delimiter shown for truncated lines.
 line-number            Line numbers.
 date                   The commit date.
 author                 The commit author.
+mode                   The file mode holding the permissions and type.
 ------------------------------------------------------------------------------
 
 ifdef::backend-xhtml11[]
@@ -411,6 +412,17 @@ Blame view:
 blame-id               The commit ID.
 ------------------------------------------------------------------------------
 
+ifdef::backend-xhtml11[]
+[frame="none"]
+`-----------------------`-----------------------------------------------------
+endif::backend-xhtml11[]
+Tree view:
+------------------------------------------------------------------------------
+tree-head              The "Directory /"-line
+tree-dir               The directory name.
+tree-file              The file name.
+------------------------------------------------------------------------------
+
 Highlighting
 ~~~~~~~~~~~~