[tin-dev] [PATCH] Group level title too long for narrow terminal

Dennis Preiser dennis at d--p.de
Wed Feb 9 20:38:57 CET 2022


Hi,

If the group name is very long and the terminal window is relatively
narrow, the title in the group level is not shortened appropriately
(independent of tinrc.abbreviate_groupname). I noticed this with
gmane.linux.debian.alioth.pkg-gnupg.general on news.gmane.io (tin -g
news.gmane.io gmane.linux.debian.alioth.pkg-gnupg.general).

The attached patch should fix this.

Interestingly, the maximum possible room for the title cannot be used,
since txt_you_have_mail and txt_type_h_for_help are defined with leading
spaces:

txt_you_have_mail:   "    You have mail"
txt_type_h_for_help: "           h=help"

Is there any reason for those leading spaces?

Dennis
-------------- next part --------------
diff -Nurp tin-2.6.2_r3/src/group.c tin-2.6.2_r4/src/group.c
--- tin-2.6.2_r3/src/group.c	2021-12-22 14:24:50.000000000 +0100
+++ tin-2.6.2_r4/src/group.c	2022-02-09 20:05:45.000000000 +0100
@@ -1469,7 +1469,11 @@ show_group_title(
 	t_bool clear_title)
 {
 	char buf[LEN], tmp[LEN], flag;
-	int i, art_cnt = 0, recent_art_cnt = 0, selected_art_cnt = 0, read_selected_art_cnt = 0, killed_art_cnt = 0;
+	char *grpname;
+	int i, len, art_cnt = 0, recent_art_cnt = 0, selected_art_cnt = 0, read_selected_art_cnt = 0, killed_art_cnt = 0;
+#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
+	wchar_t *wtmp, *wtmp2;
+#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
 
 	for_each_art(i) {
 		if (arts[i].thread == ART_EXPIRED)
@@ -1502,10 +1506,9 @@ show_group_title(
 	/*
 	 * build the group title
 	 */
-	/* group name and thread count */
-	snprintf(buf, sizeof(buf), "%s (%d%c",
-		curr_group->name, grpmenu.max,
-		*txt_threading[curr_group->attribute->thread_articles]);
+	/* thread count */
+	snprintf(buf, sizeof(buf), " (%d%c",
+		grpmenu.max, *txt_threading[curr_group->attribute->thread_articles]);
 
 	/* article count */
 	if ((cmdline.args & CMDLINE_GETART_LIMIT) ? cmdline.getart_limit : tinrc.getart_limit)
@@ -1553,12 +1556,48 @@ show_group_title(
 		snprintf(tmp, sizeof(tmp), ") %c", flag);
 	if (sizeof(buf) > strlen(buf) + strlen(tmp))
 		strcat(buf, tmp);
+	/*
+	 * determine max len for centered group name
+	 * we lose room here due to the leading spaces
+	 * txt_you_have_mail:   "    You have mail"
+	 * txt_type_h_for_help: "           h=help"
+	 */
+	len = cCOLS - (2 * MAX(strwidth(_(txt_type_h_for_help)), strwidth(_(txt_you_have_mail))) + strwidth(buf) + 1);
+
+	/* group name */
+#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
+	if ((wtmp = char2wchar_t(curr_group->name)) != NULL) {
+		if (tinrc.abbreviate_groupname)
+			wtmp2 = abbr_wcsgroupname(wtmp, len);
+		else
+			wtmp2 = wstrunc(wtmp, len);
+		grpname = wchar_t2char(wtmp2);
+		free(wtmp);
+		free(wtmp2);
+		if (grpname) {
+			STRCPY(tmp, grpname);
+			strcat(tmp, buf);
+			free(grpname);
+		} else {
+			STRCPY(tmp, buf);
+		}
+	} else
+		STRCPY(tmp, buf);
+#else 
+	if (tinrc.abbreviate_groupname)
+		grpname = abbr_groupname(curr_group->name, len);
+	else
+		grpname = strunc(curr_group->name, len);
+	STRCPY(tmp, grpname);
+	strcat(tmp, buf);
+	free(grpname);
+#endif /* MULTIBYTE_ABLE || NO_LOCALE */
 
 	if (clear_title) {
 		MoveCursor(0, 0);
 		CleartoEOLN();
 	}
-	show_title(buf);
+	show_title(tmp);
 }
 
 


More information about the tin-dev mailing list