[tin-dev] [PATCH] Display of article score when article is read
Dennis Preiser
dennis at d--p.de
Wed Nov 8 12:14:54 CET 2023
The attached patch adds a feature that displays the article score in the
bottom left corner of the article display.
The feature is controlled by tinrc.show_art_score resp. the
corresponding attributes setting. Color can be adjusted with
tinrc.col_score_neg and tinrc.col_score_pos for negative/positive score.
Dennis
-------------- next part --------------
--- a/doc/tin.1
+++ b/doc/tin.1
@@ -1741,6 +1739,12 @@ in the article viewer.
.B Color of signatures (col_signature)
Color of signatures
.TP
+.B Color of negative score (col_score_neg)
+Color of signatures
+.TP
+.B Color of positive score (col_score_pos)
+Color of signatures
+.TP
.B Color of urls highlight (col_urls)
Color of urls highlight
.TP
@@ -2452,6 +2438,10 @@ is OFF.
.B Display signatures (show_signatures)
If OFF don't show signatures when displaying articles. Default is ON.
.TP
+.B Display score (show_art_score)
+If ON show article score in the upper left corner when displaying articles.
+Default is OFF.
+.TP
.B Prepend signature with '\en\-\- \en' (sigdashes)
If ON prepend the signature with sigdashes. Default is ON.
.TP
--- a/doc/tin.5
+++ b/doc/tin.5
@@ -592,15 +592,15 @@ Identical to the tinrc variable of the same name
.B show_signatures
Identical to the tinrc variable of the same name
.TP
+.B show_art_score
+Identical to the tinrc variable of the same name
+.TP
.B sigdashes
Identical to the tinrc variable of the same name
.TP
@@ -1456,6 +1456,12 @@ in the article viewer.
.B col_signature
Color of signatures
.TP
+.B col_score_neg
+Color of negative score
+.TP
+.B col_score_pos
+Color of positive score
+.TP
.B col_urls
Color of urls highlight
.TP
@@ -2210,6 +2198,10 @@ is OFF.
.B show_signatures
If OFF don't show signatures when displaying articles. Default is ON.
.TP
+.B show_art_score
+If ON show article score in the upper left corner when displaying articles.
+Default is OFF.
+.TP
.B sigdashes
If ON prepend the signature with sigdashes. Default is ON.
.TP
--- a/include/extern.h
+++ b/include/extern.h
@@ -479,6 +479,7 @@ extern constext txt_art_parent_none[];
extern constext txt_art_parent_unavail[];
extern constext txt_art_posted[];
extern constext txt_art_rejected[];
+extern constext txt_art_score[];
extern constext txt_art_thread_regex_tag[];
extern constext txt_art_unavailable[];
extern constext txt_art_x_of_n[];
@@ -1883,6 +1884,7 @@ extern struct opttxt txt_show_help_mail_sign;
extern struct opttxt txt_show_only_unread_arts;
extern struct opttxt txt_show_only_unread_groups;
extern struct opttxt txt_show_signatures;
+extern struct opttxt txt_show_art_score;
extern struct opttxt txt_sigdashes;
extern struct opttxt txt_sigfile;
extern struct opttxt txt_signature_repost;
@@ -1962,6 +1964,8 @@ extern struct opttxt txt_xpost_quote_format;
extern struct opttxt txt_col_from;
extern struct opttxt txt_col_title;
extern struct opttxt txt_col_signature;
+ extern struct opttxt txt_col_score_neg;
+ extern struct opttxt txt_col_score_pos;
extern struct opttxt txt_col_urls;
extern struct opttxt txt_col_verbatim;
extern struct opttxt txt_col_markstar;
--- a/include/tin.h
+++ b/include/tin.h
@@ -1759,6 +1759,7 @@ struct t_attribute {
IntField(thread_perc); /* percentage threading threshold */
IntField(show_author); /* 0=none, 1=name, 2=addr, 3=both */
BoolField(show_signatures); /* 0=none, 1=show signatures */
+ BoolField(show_art_score); /* 0=none, 1=show score */
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
BoolField(suppress_soft_hyphens); /* set TRUE to remove soft hyphens (U+00AD) from articles */
#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
@@ -1846,6 +1847,7 @@ struct t_attribute_state {
BoolField(show_author);
BoolField(show_only_unread_arts);
BoolField(show_signatures);
+ BoolField(show_art_score);
BoolField(sigdashes);
BoolField(sigfile);
BoolField(signature_repost);
--- a/include/tinrc.h
+++ b/include/tinrc.h
@@ -195,6 +195,8 @@ struct t_config {
int col_extquote; /* color of quoted external text */
int col_response; /* color of response counter */
int col_signature; /* color of signature */
+ int col_score_neg; /* color of negative article score */
+ int col_score_pos; /* color of positive article score */
int col_urls; /* color of urls highlight */
int col_verbatim; /* color of verbatim blocks */
int col_subject; /* color of article subject */
@@ -247,6 +249,7 @@ struct t_config {
t_bool show_only_unread_arts; /* show only new/unread arts or all arts */
t_bool show_only_unread_groups; /* set TRUE to see only subscribed groups with new news */
t_bool show_signatures; /* show signatures when displaying articles */
+ t_bool show_art_score; /* show article score when displaying articles */
t_bool sigdashes; /* set TRUE to prepend every signature with dashes */
t_bool signature_repost; /* set TRUE to add signature when reposting articles */
# ifndef USE_CURSES
@@ -369,6 +372,7 @@ struct t_config {
t_bool attrib_prompt_followupto;
t_bool attrib_show_only_unread_arts;
t_bool attrib_show_signatures;
+ t_bool attrib_show_art_score;
t_bool attrib_sigdashes;
t_bool attrib_signature_repost;
# if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
--- a/src/attrib.c
+++ b/src/attrib.c
@@ -120,6 +120,7 @@ set_default_attributes(
CopyBits(sort_threads_type, tinrc.sort_threads_type);
CopyBits(show_author, tinrc.show_author);
CopyBool(show_signatures, tinrc.show_signatures);
+ CopyBool(show_art_score, tinrc.show_art_score);
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
CopyBool(suppress_soft_hyphens, tinrc.suppress_soft_hyphens);
#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
@@ -229,6 +230,7 @@ set_default_state(
state->show_author = FALSE;
state->show_only_unread_arts = FALSE;
state->show_signatures = FALSE;
+ state->show_art_score = FALSE;
state->sigdashes = FALSE;
state->sigfile = FALSE;
state->signature_repost = FALSE;
@@ -476,6 +478,7 @@ read_attributes_file(
MATCH_INTEGER("show_author=", OPT_ATTRIB_SHOW_AUTHOR, SHOW_FROM_BOTH);
MATCH_BOOLEAN("show_only_unread_arts=", OPT_ATTRIB_SHOW_ONLY_UNREAD_ARTS);
MATCH_BOOLEAN("show_signatures=", OPT_ATTRIB_SHOW_SIGNATURES);
+ MATCH_BOOLEAN("show_art_score=", OPT_ATTRIB_SHOW_ART_SCORE);
MATCH_BOOLEAN("sigdashes=", OPT_ATTRIB_SIGDASHES);
MATCH_BOOLEAN("signature_repost=", OPT_ATTRIB_SIGNATURE_REPOST);
MATCH_STRING("sigfile=", OPT_ATTRIB_SIGFILE);
@@ -858,6 +861,9 @@ set_attrib(
case OPT_ATTRIB_SHOW_SIGNATURES:
SET_BOOLEAN(show_signatures);
+ case OPT_ATTRIB_SHOW_ART_SCORE:
+ SET_BOOLEAN(show_art_score);
+
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
case OPT_ATTRIB_SUPPRESS_SOFT_HYPHENS:
SET_BOOLEAN(suppress_soft_hyphens);
@@ -1062,6 +1068,7 @@ assign_attributes_to_groups(
SET_ATTRIB(sort_threads_type);
SET_ATTRIB(show_author);
SET_ATTRIB(show_signatures);
+ SET_ATTRIB(show_art_score);
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
SET_ATTRIB(suppress_soft_hyphens);
#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
@@ -1320,6 +1327,7 @@ write_attributes_file(
SHOW_FROM_NAME, _(txt_show_from[SHOW_FROM_NAME]),
SHOW_FROM_BOTH, _(txt_show_from[SHOW_FROM_BOTH]));
fprintf(fp, "%s", _("# show_signatures=ON/OFF\n"));
+ fprintf(fp, "%s", _("# show_art_score=ON/OFF\n"));
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
fprintf(fp, "%s", _("# suppress_soft_hyphens=ON/OFF\n"));
#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
@@ -1538,6 +1546,8 @@ write_attributes_file(
fprintf(fp, "show_only_unread_arts=%s\n", print_boolean(scope->attribute->show_only_unread_arts));
if (scope->state->show_signatures)
fprintf(fp, "show_signatures=%s\n", print_boolean(scope->attribute->show_signatures));
+ if (scope->state->show_art_score)
+ fprintf(fp, "show_art_score=%s\n", print_boolean(scope->attribute->show_art_score));
if (scope->state->sigdashes)
fprintf(fp, "sigdashes=%s\n", print_boolean(scope->attribute->sigdashes));
if (scope->state->sigfile && scope->attribute->sigfile)
@@ -1670,6 +1680,7 @@ skip_scope(
|| scope->state->show_author
|| scope->state->show_only_unread_arts
|| scope->state->show_signatures
+ || scope->state->show_art_score
|| scope->state->sigdashes
|| (scope->state->sigfile && scope->attribute->sigfile)
|| scope->state->signature_repost
@@ -1801,6 +1812,7 @@ dump_attributes(
debug_print_file("ATTRIBUTES", "\tsort_threads_type=%d", group->attribute->sort_threads_type);
debug_print_file("ATTRIBUTES", "\tshow_author=%d", group->attribute->show_author);
debug_print_file("ATTRIBUTES", "\tshow_signatures=%s", print_boolean(group->attribute->show_signatures));
+ debug_print_file("ATTRIBUTES", "\tshow_art_score=%s", print_boolean(group->attribute->show_art_score));
debug_print_file("ATTRIBUTES", "\tsigdashes=%s", print_boolean(group->attribute->sigdashes));
debug_print_file("ATTRIBUTES", "\tsignature_repost=%s", print_boolean(group->attribute->signature_repost));
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
@@ -1918,6 +1930,7 @@ dump_scopes(
debug_print_file(fname, "\t%ssort_threads_type=%d", DEBUG_PRINT_STATE(sort_threads_type), scope->attribute->sort_threads_type);
debug_print_file(fname, "\t%sshow_author=%d", DEBUG_PRINT_STATE(show_author), scope->attribute->show_author);
debug_print_file(fname, "\t%sshow_signatures=%s", DEBUG_PRINT_STATE(show_signatures), print_boolean(scope->attribute->show_signatures));
+ debug_print_file(fname, "\t%sshow_art_score=%s", DEBUG_PRINT_STATE(show_art_score), print_boolean(scope->attribute->show_art_score));
debug_print_file(fname, "\t%ssigdashes=%s", DEBUG_PRINT_STATE(sigdashes), print_boolean(scope->attribute->sigdashes));
debug_print_file(fname, "\t%ssignature_repost=%s", DEBUG_PRINT_STATE(signature_repost), print_boolean(scope->attribute->signature_repost));
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
--- a/src/config.c
+++ b/src/config.c
@@ -283,6 +283,12 @@ read_config_file(
if (match_color(buf, "col_signature=", &tinrc.col_signature, MAX_COLOR))
break;
+ if (match_color(buf, "col_score_neg=", &tinrc.col_score_neg, MAX_COLOR))
+ break;
+
+ if (match_color(buf, "col_score_pos=", &tinrc.col_score_pos, MAX_COLOR))
+ break;
+
if (match_color(buf, "col_urls=", &tinrc.col_urls, MAX_COLOR))
break;
@@ -733,6 +739,9 @@ read_config_file(
if (match_boolean(buf, "show_signatures=", &tinrc.show_signatures))
break;
+ if (match_boolean(buf, "show_art_score=", &tinrc.show_art_score))
+ break;
+
if (match_string(buf, "slashes_regex=", tinrc.slashes_regex, sizeof(tinrc.slashes_regex)))
break;
@@ -1184,6 +1193,9 @@ write_config_file(
fprintf(fp, "%s", _(txt_show_signatures.tinrc));
fprintf(fp, "show_signatures=%s\n\n", print_boolean(tinrc.show_signatures));
+ fprintf(fp, "%s", _(txt_show_art_score.tinrc));
+ fprintf(fp, "show_art_score=%s\n\n", print_boolean(tinrc.show_art_score));
+
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
fprintf(fp, "%s", _(txt_suppress_soft_hyphens.tinrc));
fprintf(fp, "suppress_soft_hyphens=%s\n\n", print_boolean(tinrc.suppress_soft_hyphens));
@@ -1353,6 +1365,12 @@ write_config_file(
fprintf(fp, "%s", _(txt_col_signature.tinrc));
fprintf(fp, "col_signature=%d\n\n", tinrc.col_signature);
+ fprintf(fp, "%s", _(txt_col_score_neg.tinrc));
+ fprintf(fp, "col_score_neg=%d\n\n", tinrc.col_score_neg);
+
+ fprintf(fp, "%s", _(txt_col_score_pos.tinrc));
+ fprintf(fp, "col_score_pos=%d\n\n", tinrc.col_score_pos);
+
fprintf(fp, "%s", _(txt_col_urls.tinrc));
fprintf(fp, "col_urls=%d\n\n", tinrc.col_urls);
--- a/src/init.c
+++ b/src/init.c
@@ -334,6 +334,8 @@ struct t_config tinrc = {
0, /* col_extquote (initialised later) */
0, /* col_response (initialised later) */
0, /* col_signature (initialised later) */
+ 0, /* col_score_neg (initialised later) */
+ 0, /* col_score_pos (initialised later) */
0, /* col_urls (initialised later) */
0, /* col_verbatim (initialised later) */
0, /* col_subject (initialised later) */
@@ -394,6 +396,7 @@ struct t_config tinrc = {
TRUE, /* show_only_unread_arts */
FALSE, /* show_only_unread_groups */
TRUE, /* show_signatures */
+ FALSE, /* show_art_score */
TRUE, /* sigdashes */
TRUE, /* signature_repost */
#ifndef USE_CURSES
@@ -512,6 +515,7 @@ struct t_config tinrc = {
FALSE, /* attrib_prompt_followupto */
TRUE, /* attrib_show_only_unread_arts */
TRUE, /* attrib_show_signatures */
+ FALSE, /* attrib_show_art_score */
TRUE, /* attrib_sigdashes */
TRUE, /* attrib_signature_repost */
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
@@ -613,6 +617,8 @@ static const struct {
{ &tinrc.col_extquote, 5 },
{ &tinrc.col_response, 2 },
{ &tinrc.col_signature, 4 },
+ { &tinrc.col_score_neg, 1 },
+ { &tinrc.col_score_pos, 2 },
{ &tinrc.col_urls, DFT_FORE },
{ &tinrc.col_verbatim, 5 },
{ &tinrc.col_subject, 6 },
--- a/src/lang.c
+++ b/src/lang.c
@@ -818,6 +818,7 @@ constext txt_resp_to_poster[] = N_("Responses have been directed to poster. %s=m
constext txt_return_key[] = N_("Press <RETURN> to continue...");
+constext txt_art_score[] = N_("Score: %s");
constext txt_select_from[] = N_("Select From [%s] (y/n): ");
constext txt_select_lines[] = N_("Select Lines: (</>num): ");
constext txt_select_menu[] = N_("Auto-select Article Menu");
@@ -1967,6 +1968,12 @@ struct opttxt txt_show_signatures = {
N_("# If OFF don't show signatures when displaying articles\n")
};
+struct opttxt txt_show_art_score = {
+ N_("Display article score. <SPACE> toggles & <CR> sets."),
+ N_("Display article score"),
+ N_("# If ON show article score when displaying articles\n")
+};
+
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
struct opttxt txt_suppress_soft_hyphens = {
N_("Remove soft hyphens. <SPACE> toggles & <CR> sets."),
@@ -2398,6 +2405,20 @@ struct opttxt txt_col_signature = {
# Default: 4 (blue)\n")
};
+struct opttxt txt_col_score_neg = {
+ N_("<SPACE> toggles, <CR> sets, <ESC> cancels."),
+ N_("Color of negative score"),
+ N_("# Color of negative score\n\
+# Default: 1 (red)\n")
+};
+
+struct opttxt txt_col_score_pos = {
+ N_("<SPACE> toggles, <CR> sets, <ESC> cancels."),
+ N_("Color of positive score"),
+ N_("# Color of positive score\n\
+# Default: 1 (red)\n")
+};
+
struct opttxt txt_col_urls = {
N_("<SPACE> toggles, <CR> sets, <ESC> cancels."),
N_("Color of highlighted URLs"),
--- a/src/options_menu.c
+++ b/src/options_menu.c
@@ -221,6 +221,8 @@ option_is_visible(
case OPT_COL_EXTQUOTE:
case OPT_COL_RESPONSE:
case OPT_COL_SIGNATURE:
+ case OPT_COL_SCORE_NEG:
+ case OPT_COL_SCORE_POS:
case OPT_COL_SUBJECT:
case OPT_COL_TEXT:
case OPT_COL_TITLE:
@@ -342,6 +344,7 @@ option_is_visible(
case OPT_ATTRIB_SHOW_AUTHOR:
case OPT_ATTRIB_SHOW_ONLY_UNREAD_ARTS:
case OPT_ATTRIB_SHOW_SIGNATURES:
+ case OPT_ATTRIB_SHOW_ART_SCORE:
case OPT_ATTRIB_SIGDASHES:
case OPT_ATTRIB_SIGFILE:
case OPT_ATTRIB_SIGNATURE_REPOST:
@@ -1461,6 +1464,13 @@ config_page(
}
break;
+ case OPT_SHOW_ART_SCORE:
+ if (prompt_option_on_off(option)) {
+ UPDATE_BOOL_ATTRIBUTES(show_art_score);
+ changed |= DISPLAY_OPTS;
+ }
+ break;
+
case OPT_SIGDASHES:
if (prompt_option_on_off(option))
UPDATE_BOOL_ATTRIBUTES(sigdashes);
@@ -1778,6 +1788,13 @@ config_page(
}
break;
+ case OPT_ATTRIB_SHOW_ART_SCORE:
+ if (prompt_option_on_off(option)) {
+ SET_BOOL_ATTRIBUTE(show_art_score);
+ changed |= DISPLAY_OPTS;
+ }
+ break;
+
case OPT_ATTRIB_SIGDASHES:
if (prompt_option_on_off(option))
SET_BOOL_ATTRIBUTE(sigdashes);
@@ -1851,6 +1868,8 @@ config_page(
case OPT_COL_EXTQUOTE:
case OPT_COL_RESPONSE:
case OPT_COL_SIGNATURE:
+ case OPT_COL_SCORE_NEG:
+ case OPT_COL_SCORE_POS:
case OPT_COL_SUBJECT:
case OPT_COL_TEXT:
case OPT_COL_TITLE:
@@ -3266,6 +3285,8 @@ check_state(
return curr_scope->state->show_only_unread_arts;
case OPT_ATTRIB_SHOW_SIGNATURES:
return curr_scope->state->show_signatures;
+ case OPT_ATTRIB_SHOW_ART_SCORE:
+ return curr_scope->state->show_art_score;
case OPT_ATTRIB_SIGDASHES:
return curr_scope->state->sigdashes;
case OPT_ATTRIB_SIGFILE:
@@ -3559,6 +3580,10 @@ reset_state(
curr_scope->state->show_signatures = FALSE;
tinrc.attrib_show_signatures = default_scope->attribute->show_signatures;
break;
+ case OPT_ATTRIB_SHOW_ART_SCORE:
+ curr_scope->state->show_art_score = FALSE;
+ tinrc.attrib_show_art_score = default_scope->attribute->show_art_score;
+ break;
case OPT_ATTRIB_SIGDASHES:
curr_scope->state->sigdashes = FALSE;
tinrc.attrib_sigdashes = default_scope->attribute->sigdashes;
@@ -3710,6 +3735,7 @@ initialize_attributes(
INITIALIZE_NUM_ATTRIBUTE(show_author);
INITIALIZE_NUM_ATTRIBUTE(show_only_unread_arts);
INITIALIZE_NUM_ATTRIBUTE(show_signatures);
+ INITIALIZE_NUM_ATTRIBUTE(show_art_score);
INITIALIZE_NUM_ATTRIBUTE(sigdashes);
INITIALIZE_NUM_ATTRIBUTE(signature_repost);
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
--- a/src/page.c
+++ b/src/page.c
@@ -1289,6 +1289,43 @@ draw_page(
} else
draw_percent_mark(curr_line + ARTLINES, artlines);
+ if (CURR_GROUP.attribute->show_art_score && arts[this_resp].score != 0) {
+ char *buf;
+#ifdef HAVE_COLOR
+ int tmp_col = tinrc.col_invers_bg;
+#endif /* HAVE_COLOR */
+ size_t buflen = strlen(_(txt_art_score)) + 3;
+
+ buf = my_malloc(buflen + 1);
+ snprintf(buf, buflen, _(txt_art_score), tin_ltoa(arts[this_resp].score, 4));
+ MoveCursor(cLINES, 0);
+#ifdef HAVE_COLOR
+ fcol(tinrc.col_normal);
+ if (tinrc.inverse_okay) {
+ if (arts[this_resp].score < 0)
+ tinrc.col_invers_bg = tinrc.col_score_neg;
+ else
+ tinrc.col_invers_bg = tinrc.col_score_pos;
+ } else {
+ if (arts[this_resp].score < 0)
+ fcol(tinrc.col_score_neg);
+ else
+ fcol(tinrc.col_score_pos);
+ }
+#endif /* HAVE_COLOR */
+ StartInverse();
+ my_fputs(buf, stdout);
+ EndInverse();
+ my_flush();
+#ifdef HAVE_COLOR
+ if (tinrc.inverse_okay)
+ tinrc.col_invers_bg = tmp_col;
+ else
+ fcol(tinrc.col_normal);
+#endif /* HAVE_COLOR */
+ free(buf);
+ }
+
#ifdef XFACE_ABLE
if (tinrc.use_slrnface && !show_raw_article)
slrnface_display_xface(note_h->xface);
--- a/src/tincfg.tbl
+++ b/src/tincfg.tbl
@@ -74,6 +74,7 @@
thread_score txt_thread_score_type
scroll_lines OPT_NUM
show_signatures OPT_ON_OFF
+ show_art_score OPT_ON_OFF
news_headers_to_display OPT_STRING
news_headers_to_not_display OPT_STRING
alternative_handling OPT_ON_OFF
@@ -108,6 +109,7 @@
attrib_auto_select OPT_ON_OFF
attrib_wrap_on_next_unread OPT_ON_OFF
attrib_show_signatures OPT_ON_OFF
+ attrib_show_art_score OPT_ON_OFF
attrib_news_headers_to_display OPT_STRING
attrib_news_headers_to_not_display OPT_STRING
attrib_alternative_handling OPT_ON_OFF
@@ -168,6 +170,8 @@
col_from txt_colors
col_title txt_colors
col_signature txt_colors
+ col_score_neg txt_colors
+ col_score_pos txt_colors
col_urls txt_colors
col_verbatim txt_colors
col_extquote txt_colors
More information about the tin-dev
mailing list