degesch: make the unread marker look a bit fancier

Upstreamed after who knows how long, in a slightly modified form.
The marker looks fairly ugly without this and defaults should be
desirable.

It's possible to get the previous behaviour by resetting the separator
character in the configuration to an empty string.  It might be
a better idea in general to just disallow this value with a special
validation callback, so that there's only one way to do it.

However given that without fancy-prompt.lua, an optional plugin,
the long line stands out considerably, it might actually be a good
idea to keep the old behaviour as the default.  I'm torn.

Right now we don't care about the situation where the string occupies
more than one terminal cell or is some Unicode BS.  User's problem.
This commit is contained in:
Přemysl Eric Janouch 2016-04-21 23:58:44 +02:00 committed by Přemysl Eric Janouch
parent f716e7601f
commit 9819b75b64
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -2425,6 +2425,11 @@ static struct config_schema g_config_behaviour[] =
.comment = "Input to strftime(3) for the date change line",
.type = CONFIG_ITEM_STRING,
.default_ = "\"%F\"" },
{ .name = "read_marker_char",
.comment = "The character to use for the read marker line",
.type = CONFIG_ITEM_STRING,
.default_ = "\"-\"",
.validate = config_validate_nonjunk_string },
{ .name = "logging",
.comment = "Log buffer contents to file",
.type = CONFIG_ITEM_BOOLEAN,
@ -4097,7 +4102,28 @@ static void
buffer_print_read_marker (struct app_context *ctx, FILE *stream, int flush_opts)
{
struct formatter f = formatter_make (ctx, NULL);
formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER);
const int timestamp_width = 8; // hardcoded to %T right now, simple
const char *marker_char = get_config_string (ctx->config.root,
"behaviour.read_marker_char");
// We could turn this off on FLUSH_OPT_NOWRAP, however our default pager
// wraps lines for us even if we don't do it ourselves, and thus there's
// no need to worry about inconsistency.
if (*marker_char)
{
struct str s = str_make ();
for (int i = 0; i < timestamp_width; i++)
str_append (&s, marker_char);
formatter_add (&f, "#a#s#r", ATTR_TIMESTAMP, s.str);
str_reset (&s);
for (int i = timestamp_width; i < g_terminal.columns; i++)
str_append (&s, marker_char);
formatter_add (&f, "#a#s#r\n", ATTR_READ_MARKER, s.str);
str_free (&s);
}
else
formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER);
formatter_flush (&f, stream, flush_opts);
// Flush the trailing formatting reset item
fflush (stream);