summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 12c9cbf)
raw | patch | inline | side by side (parent: 12c9cbf)
author | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 22 Apr 2008 12:11:33 +0000 (14:11 +0200) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 22 Apr 2008 12:27:46 +0000 (14:27 +0200) |
This requires that utf8_length() makes the width/column available to
draw_text().
draw_text().
tig.c | patch | blob | history |
index 7144fdbbebc546be3e5600eaad5d07f08e364125..1ea408b3387dc04231d5476d02158601a92b22d8 100644 (file)
--- a/tig.c
+++ b/tig.c
static void report(const char *msg, ...);
static int read_properties(FILE *pipe, const char *separators, int (*read)(char *, size_t, char *, size_t));
static void set_nonblocking_input(bool loading);
-static size_t utf8_length(const char *string, size_t max_width, int *trimmed, bool reserve);
+static size_t utf8_length(const char *string, int *width, size_t max_width, int *trimmed, bool reserve);
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
int max_len, bool use_tilde)
{
int len = 0;
+ int col = 0;
int trimmed = FALSE;
if (max_len <= 0)
return 0;
if (opt_utf8) {
- len = utf8_length(string, max_len, &trimmed, use_tilde);
+ len = utf8_length(string, &col, max_len, &trimmed, use_tilde);
} else {
- len = strlen(string);
+ col = len = strlen(string);
if (len > max_len) {
if (use_tilde) {
max_len -= 1;
}
- len = max_len;
+ col = len = max_len;
trimmed = TRUE;
}
}
if (trimmed && use_tilde) {
set_view_attr(view, LINE_DELIMITER);
waddch(view->win, '~');
- len++;
+ col++;
}
- return len;
+ return col;
}
static int
}
if (opt_author) {
- int max = MIN(AUTHOR_COLS - 1, view->width - col);
+ int max = view->width - col;
- set_view_attr(view, LINE_MAIN_AUTHOR);
- if (author)
- draw_text(view, LINE_MAIN_AUTHOR, author, max, TRUE);
- col += AUTHOR_COLS;
+ col += draw_field(view, LINE_MAIN_AUTHOR, author, AUTHOR_COLS, max, TRUE);
if (col >= view->width)
return TRUE;
- wmove(view->win, lineno, col);
}
{
}
if (opt_author) {
- int max_len;
+ int max = view->width - col;
- max_len = view->width - col;
- if (max_len > AUTHOR_COLS - 1)
- max_len = AUTHOR_COLS - 1;
- draw_text(view, LINE_MAIN_AUTHOR, commit->author, max_len, TRUE);
- col += AUTHOR_COLS;
+ col += draw_field(view, LINE_MAIN_AUTHOR, commit->author, AUTHOR_COLS, max, TRUE);
if (col >= view->width)
return TRUE;
- wmove(view->win, lineno, col);
}
if (opt_rev_graph && commit->graph_size) {
*
* Returns the number of bytes to output from string to satisfy max_width. */
static size_t
-utf8_length(const char *string, size_t max_width, int *trimmed, bool reserve)
+utf8_length(const char *string, int *width, size_t max_width, int *trimmed, bool reserve)
{
const char *start = string;
const char *end = strchr(string, '\0');
unsigned char last_bytes = 0;
- size_t width = 0;
+ size_t last_ucwidth = 0;
+ *width = 0;
*trimmed = 0;
while (string < end) {
@@ -5288,17 +5281,20 @@ utf8_length(const char *string, size_t max_width, int *trimmed, bool reserve)
break;
ucwidth = unicode_width(unicode);
- width += ucwidth;
- if (width > max_width) {
+ *width += ucwidth;
+ if (*width > max_width) {
*trimmed = 1;
- if (reserve && width - ucwidth == max_width) {
+ *width -= ucwidth;
+ if (reserve && *width == max_width) {
string -= last_bytes;
+ *width -= last_ucwidth;
}
break;
}
string += bytes;
last_bytes = bytes;
+ last_ucwidth = ucwidth;
}
return string - start;