commit de425062f40d95fbd30d0ab030969cb6a1251c12
parent 115505b227c98a70b98301e82fdc00c3da9ec582
Author: hhvn <dev@hhvn.uk>
Date: Tue, 22 Feb 2022 13:01:32 +0000
Only pad author section by amount needed.
Diffstat:
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/sfeed_curses.c b/sfeed_curses.c
@@ -50,6 +50,8 @@ static char *yankercmd = "xclip -r"; /* env variable: $SFEED_YANKER */
static char *markreadcmd = "sfeed_markread read"; /* env variable: $SFEED_MARK_READ */
static char *markunreadcmd = "sfeed_markread unread"; /* env variable: $SFEED_MARK_UNREAD */
+static int maxauthwidth = 30; /* maximum width to pad author section */
+
enum {
ATTR_RESET = 0, ATTR_BOLD_ON = 1, ATTR_FAINT_ON = 2, ATTR_REVERSE_ON = 7
};
@@ -120,12 +122,14 @@ struct item {
int timeok;
int isnew;
off_t offset; /* line offset in file for lazyload */
+ struct items *parent;
};
struct items {
struct item *items; /* array of items */
size_t len; /* amount of items */
size_t cap; /* available capacity */
+ size_t mauthw; /* max width of FieldAuthor */
};
struct feed {
@@ -1097,6 +1101,7 @@ feed_items_get(struct feed *f, FILE *fp, struct items *itemsret)
ssize_t linelen;
off_t offset;
int ret = -1;
+ size_t mauthw = 0;
cap = nitems = 0;
offset = 0;
@@ -1108,6 +1113,7 @@ feed_items_get(struct feed *f, FILE *fp, struct items *itemsret)
if ((linelen = getline(&line, &linesize, fp)) > 0) {
item = &items[i];
+ item->parent = itemsret;
item->offset = offset;
offset += linelen;
@@ -1127,7 +1133,8 @@ feed_items_get(struct feed *f, FILE *fp, struct items *itemsret)
#else
linetoitem(estrdup(line), item);
#endif
-
+ if (maxauthwidth && strlen(item->fields[FieldAuthor]) > mauthw)
+ mauthw = strlen(item->fields[FieldAuthor]);
nitems++;
}
if (ferror(fp))
@@ -1141,6 +1148,7 @@ err:
itemsret->cap = cap;
itemsret->items = items;
itemsret->len = nitems;
+ itemsret->mauthw = mauthw < maxauthwidth ? mauthw : maxauthwidth;
free(line);
if (ret)
@@ -1585,15 +1593,17 @@ item_row_format(struct pane *p, struct row *row)
item = (struct item *)row->data;
if (item->timeok && localtime_r(&(item->timestamp), &tm)) {
- snprintf(text, sizeof(text), "%c %-20s %04d-%02d-%02d %02d:%02d %s",
+ snprintf(text, sizeof(text), "%c %-*s %04d-%02d-%02d %02d:%02d %s",
item->fields[FieldEnclosure][0] ? '@' : ' ',
+ item->parent->mauthw,
item->fields[FieldAuthor],
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
- tm.tm_hour, tm.tm_min,
+ tm.tm_hour, tm.tm_min,
item->fields[FieldTitle]);
} else {
- snprintf(text, sizeof(text), "%c %-20s %s",
+ snprintf(text, sizeof(text), "%c %-*s %s",
item->fields[FieldEnclosure][0] ? '@' : ' ',
+ item->parent->mauthw,
item->fields[FieldAuthor],
item->fields[FieldTitle]);
}