index b951c64c87a5345c9093efad14956b3f4c27d051..b4e4b596078919afdb620efb922590ab9f0e3620 100644 (file)
--- a/tig.c
+++ b/tig.c
cmd[valuelen] = 0;
argv[(*argc)++] = chomp_string(cmd);
- cmd += valuelen + advance;
+ cmd = chomp_string(cmd + valuelen + advance);
}
if (*argc < SIZEOF_ARG)
static struct view *display[2];
static unsigned int current_view;
-/* Reading from the prompt? */
-static bool input_mode = FALSE;
-
#define foreach_displayed_view(view, i) \
for (i = 0; i < ARRAY_SIZE(display) && (view = display[i]); i++)
return draw_field(view, LINE_DATE, date, DATE_COLS, FALSE);
}
+static bool
+draw_author(struct view *view, const char *author)
+{
+ bool trim = opt_author_cols == 0 || opt_author_cols > 5 || !author;
+
+ if (!trim) {
+ static char initials[10];
+ size_t pos;
+
+#define is_initial_sep(c) (isspace(c) || ispunct(c) || (c) == '@')
+
+ memset(initials, 0, sizeof(initials));
+ for (pos = 0; *author && pos < opt_author_cols - 1; author++, pos++) {
+ while (is_initial_sep(*author))
+ author++;
+ strncpy(&initials[pos], author, sizeof(initials) - 1 - pos);
+ while (*author && !is_initial_sep(author[1]))
+ author++;
+ }
+
+ author = initials;
+ }
+
+ return draw_field(view, LINE_MAIN_AUTHOR, author, opt_author_cols, trim);
+}
+
static bool
draw_view_line(struct view *view, unsigned int lineno)
{
struct line *line;
bool selected = (view->offset + lineno == view->lineno);
- bool draw_ok;
assert(view_is_displayed(view));
view->ops->select(view, line);
}
- scrollok(view->win, FALSE);
- draw_ok = view->ops->draw(view, line, lineno);
- scrollok(view->win, TRUE);
-
- return draw_ok;
+ return view->ops->draw(view, line, lineno);
}
static void
if (!dirty)
return;
- redrawwin(view->win);
- if (input_mode)
- wnoutrefresh(view->win);
- else
- wrefresh(view->win);
+ wnoutrefresh(view->win);
}
static void
break;
}
- redrawwin(view->win);
- if (input_mode)
- wnoutrefresh(view->win);
- else
- wrefresh(view->win);
+ wnoutrefresh(view->win);
}
static void
mvwaddnstr(view->title, 0, 0, buf, bufpos);
wclrtoeol(view->title);
- wmove(view->title, 0, view->width - 1);
-
- if (input_mode)
- wnoutrefresh(view->title);
- else
- wrefresh(view->title);
+ wnoutrefresh(view->title);
}
static void
if (!view->win)
die("Failed to create %s view", view->name);
- scrollok(view->win, TRUE);
+ scrollok(view->win, FALSE);
view->title = newwin(1, 0, offset + view->height, 0);
if (!view->title)
}
}
-static void
-update_display_cursor(struct view *view)
-{
- /* Move the cursor to the right-most column of the cursor line.
- *
- * XXX: This could turn out to be a bit expensive, but it ensures that
- * the cursor does not jump around. */
- if (view->lines) {
- wmove(view->win, view->lineno - view->offset, view->width - 1);
- wrefresh(view->win);
- }
-}
-
static void
toggle_view_option(bool *option, const char *help)
{
int line = lines > 0 ? view->height - lines : 0;
int end = line + ABS(lines);
+ scrollok(view->win, TRUE);
wscrl(view->win, lines);
+ scrollok(view->win, FALSE);
- for (; line < end; line++) {
- if (!draw_view_line(view, line))
- break;
- }
+ while (line < end && draw_view_line(view, line))
+ line++;
if (redraw_current_line)
draw_view_line(view, view->lineno - view->offset);
+ wnoutrefresh(view->win);
}
- redrawwin(view->win);
- wrefresh(view->win);
report("");
}
/* Draw the current line */
draw_view_line(view, view->lineno - view->offset);
- redrawwin(view->win);
- wrefresh(view->win);
+ wnoutrefresh(view->win);
report("");
}
if (view_is_displayed(view)) {
draw_view_line(view, old_lineno);
draw_view_line(view, view->lineno - view->offset);
- redrawwin(view->win);
- wrefresh(view->win);
+ wnoutrefresh(view->win);
} else {
view->ops->select(view, &view->line[view->lineno]);
}
if (view->lines == 0) {
time_t secs = time(NULL) - view->start_time;
- if (secs > view->update_secs) {
+ if (secs > 1 && secs > view->update_secs) {
if (view->update_secs == 0)
redraw_view(view);
update_view_title(view);
if (draw_field(view, LINE_TREE_MODE, mode, 11, TRUE))
return TRUE;
- if (opt_author &&
- draw_field(view, LINE_MAIN_AUTHOR, entry->author, opt_author_cols, TRUE))
+ if (opt_author && draw_author(view, entry->author))
return TRUE;
if (opt_date && draw_date(view, *entry->author ? &entry->time : NULL))
if (opt_date && draw_date(view, time))
return TRUE;
- if (opt_author &&
- draw_field(view, LINE_MAIN_AUTHOR, author, opt_author_cols, TRUE))
+ if (opt_author && draw_author(view, author))
return TRUE;
if (draw_field(view, LINE_BLAME_ID, id, ID_COLS, FALSE))
if (opt_date && draw_date(view, &commit->time))
return TRUE;
- if (opt_author &&
- draw_field(view, LINE_MAIN_AUTHOR, commit->author, opt_author_cols, TRUE))
+ if (opt_author && draw_author(view, commit->author))
return TRUE;
if (opt_rev_graph && commit->graph_size &&
/* The status window is used for polling keystrokes. */
static WINDOW *status_win;
-static bool status_empty = TRUE;
+/* Reading from the prompt? */
+static bool input_mode = FALSE;
+
+static bool status_empty = FALSE;
/* Update status and title window. */
static void
status_empty = TRUE;
}
wclrtoeol(status_win);
- wrefresh(status_win);
+ wnoutrefresh(status_win);
va_end(args);
}
update_view_title(view);
- update_display_cursor(view);
}
/* Controls when nodelay should be in effect when polling user input. */
nonl(); /* Tell curses not to do NL->CR/NL on output */
cbreak(); /* Take input chars one at a time, no wait for \n */
noecho(); /* Don't echo input */
- leaveok(stdscr, TRUE);
+ leaveok(stdscr, FALSE);
if (has_colors())
init_colors();
}
static int
-get_input(bool prompting)
+get_input(int prompt_position)
{
struct view *view;
- int i, key;
+ int i, key, cursor_y, cursor_x;
- if (prompting)
+ if (prompt_position)
input_mode = TRUE;
- while (true) {
+ while (TRUE) {
foreach_view (view, i)
update_view(view);
+ /* Update the cursor position. */
+ if (prompt_position) {
+ getbegyx(status_win, cursor_y, cursor_x);
+ cursor_x = prompt_position;
+ } else {
+ view = display[current_view];
+ getbegyx(view->win, cursor_y, cursor_x);
+ cursor_x = view->width - 1;
+ cursor_y += view->lineno - view->offset;
+ }
+ setsyx(cursor_y, cursor_x);
+
/* Refresh, accept single keystroke of input */
+ doupdate();
key = wgetch(status_win);
/* wgetch() with nodelay() enabled returns ERR when
* there's no input. */
if (key == ERR) {
- doupdate();
} else if (key == KEY_RESIZE) {
int height, width;
getmaxyx(stdscr, height, width);
- /* Resize the status view and let the view driver take
- * care of resizing the displayed views. */
- resize_display();
- redraw_display(TRUE);
wresize(status_win, 1, width);
mvwin(status_win, height - 1, 0);
- wrefresh(status_win);
+ wnoutrefresh(status_win);
+ resize_display();
+ redraw_display(TRUE);
} else {
input_mode = FALSE;
mvwprintw(status_win, 0, 0, "%s%.*s", prompt, pos, buf);
wclrtoeol(status_win);
- key = get_input(TRUE);
+ key = get_input(pos + 1);
switch (key) {
case KEY_RETURN:
case KEY_ENTER:
}
while (view_driver(display[current_view], request)) {
- int key = get_input(FALSE);
+ int key = get_input(0);
view = display[current_view];
request = get_keybinding(view->keymap, key);