degesch: add a NOWRAP flag to formatter_flush()

--format should work as before now.

It is now also possible to rebind PageUp to show a wrapped backlog.
This commit is contained in:
Přemysl Eric Janouch 2016-04-10 21:37:36 +02:00
parent 99595c0d81
commit c8e4833086
Signed by: p
GPG Key ID: B715679E3A361BE6

View File

@ -3565,12 +3565,19 @@ formatter_to_chars (struct formatter *formatter)
return self.result;
}
enum
{
FLUSH_OPT_RAW = (1 << 0), ///< Print raw attributes
FLUSH_OPT_NOWRAP = (1 << 1) ///< Do not wrap
};
static void
formatter_flush (struct formatter *self, FILE *stream, bool raw_attributes)
formatter_flush (struct formatter *self, FILE *stream, int flush_opts)
{
struct line_char *line = formatter_to_chars (self);
if (!get_attribute_printer (stream) && !raw_attributes)
bool is_tty = !!get_attribute_printer (stream);
if (!is_tty && !(flush_opts & FLUSH_OPT_RAW))
{
LIST_FOR_EACH (struct line_char, c, line)
{
@ -3580,7 +3587,7 @@ formatter_flush (struct formatter *self, FILE *stream, bool raw_attributes)
return;
}
if (get_attribute_printer (stream) && self->ctx->word_wrapping)
if (self->ctx->word_wrapping && !(flush_opts & FLUSH_OPT_NOWRAP))
line = line_wrap (line, g_terminal.columns);
// TODO: rewrite the sloppily hacked mess around attribute_printer;
@ -3668,7 +3675,7 @@ buffer_update_time (struct app_context *ctx, time_t now)
static void
buffer_line_flush (struct buffer_line *line, struct formatter *f, FILE *output,
bool raw_attributes)
int flush_opts)
{
int flags = line->flags;
if (flags & BUFFER_LINE_INDENT) formatter_add (f, " ");
@ -3679,7 +3686,7 @@ buffer_line_flush (struct buffer_line *line, struct formatter *f, FILE *output,
formatter_add_item (f, *iter);
formatter_add (f, "\n");
formatter_flush (f, output, raw_attributes);
formatter_flush (f, output, flush_opts);
formatter_free (f);
}
@ -3712,7 +3719,7 @@ buffer_line_display (struct app_context *ctx,
}
CALL (ctx->input, hide);
buffer_line_flush (line, &f, stdout, false);
buffer_line_flush (line, &f, stdout, 0);
// Flush the trailing formatting reset item
fflush (stdout);
CALL (ctx->input, show);
@ -3720,7 +3727,7 @@ buffer_line_display (struct app_context *ctx,
static void
buffer_line_write_to_backlog (struct app_context *ctx,
struct buffer_line *line, FILE *log_file, bool raw_attributes)
struct buffer_line *line, FILE *log_file, int flush_opts)
{
struct formatter f;
formatter_init (&f, ctx, NULL);
@ -3734,7 +3741,7 @@ buffer_line_write_to_backlog (struct app_context *ctx,
else
formatter_add (&f, "#a#s#r ", ATTR_TIMESTAMP, buf);
buffer_line_flush (line, &f, log_file, raw_attributes);
buffer_line_flush (line, &f, log_file, flush_opts);
}
static void
@ -3756,7 +3763,8 @@ buffer_line_write_to_log (struct app_context *ctx,
else
formatter_add (&f, "#s ", buf);
buffer_line_flush (line, &f, log_file, false);
// The target is not a terminal, thus it won't wrap in spite of the 0
buffer_line_flush (line, &f, log_file, 0);
}
static void
@ -4006,12 +4014,12 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
}
static void
buffer_print_read_marker (struct app_context *ctx, FILE *stream, bool raw_attrs)
buffer_print_read_marker (struct app_context *ctx, FILE *stream, int flush_opts)
{
struct formatter f;
formatter_init (&f, ctx, NULL);
formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER);
formatter_flush (&f, stream, raw_attrs);
formatter_flush (&f, stream, flush_opts);
// Flush the trailing formatting reset item
fflush (stream);
formatter_free (&f);
@ -4060,8 +4068,8 @@ buffer_print_backlog (struct app_context *ctx, struct buffer *buffer)
{
if (until_marker-- == 0
&& buffer->new_messages_count != buffer->lines_count)
buffer_print_read_marker (ctx, stdout, false);
buffer_line_display (ctx, line, false);
buffer_print_read_marker (ctx, stdout, 0);
buffer_line_display (ctx, line, 0);
}
// So that it is obvious if the last line in the buffer is not from today
@ -12146,12 +12154,8 @@ launch_backlog_helper (struct app_context *ctx, int backlog_fd)
}
static bool
on_display_backlog (int count, int key, void *user_data)
display_backlog (struct app_context *ctx, int flush_opts)
{
(void) count;
(void) key;
struct app_context *ctx = user_data;
FILE *backlog = tmpfile ();
if (!backlog)
{
@ -12159,8 +12163,10 @@ on_display_backlog (int count, int key, void *user_data)
"Failed to create a temporary file", strerror (errno));
return false;
}
bool raw_attributes = !get_config_boolean
(ctx->config.root, "behaviour.backlog_helper_strip_formatting");
if (!get_config_boolean (ctx->config.root,
"behaviour.backlog_helper_strip_formatting"))
flush_opts |= FLUSH_OPT_RAW;
struct buffer *buffer = ctx->current_buffer;
int until_marker =
@ -12169,8 +12175,8 @@ on_display_backlog (int count, int key, void *user_data)
{
if (until_marker-- == 0
&& buffer->new_messages_count != buffer->lines_count)
buffer_print_read_marker (ctx, backlog, raw_attributes);
buffer_line_write_to_backlog (ctx, line, backlog, raw_attributes);
buffer_print_read_marker (ctx, backlog, flush_opts);
buffer_line_write_to_backlog (ctx, line, backlog, flush_opts);
}
rewind (backlog);
@ -12180,6 +12186,22 @@ on_display_backlog (int count, int key, void *user_data)
return true;
}
static bool
on_display_backlog (int count, int key, void *user_data)
{
(void) count;
(void) key;
return display_backlog (user_data, 0);
}
static bool
on_display_backlog_nowrap (int count, int key, void *user_data)
{
(void) count;
(void) key;
return display_backlog (user_data, FLUSH_OPT_NOWRAP);
}
static bool
on_display_full_log (int count, int key, void *user_data)
{
@ -12356,20 +12378,21 @@ input_add_functions (void *user_data)
{
struct app_context *ctx = user_data;
#define XX(...) CALL_ (ctx->input, register_fn, __VA_ARGS__, ctx);
XX ("previous-buffer", "Previous buffer", on_previous_buffer)
XX ("next-buffer", "Next buffer", on_next_buffer)
XX ("goto-buffer", "Go to buffer", on_goto_buffer)
XX ("switch-buffer", "Switch buffer", on_switch_buffer)
XX ("goto-highlight", "Go to highlight", on_goto_highlight)
XX ("goto-activity", "Go to activity", on_goto_activity)
XX ("move-buffer-left", "Move buffer left", on_move_buffer_left)
XX ("move-buffer-right", "Move buffer right", on_move_buffer_right)
XX ("display-backlog", "Show backlog", on_display_backlog)
XX ("display-full-log", "Show full log", on_display_full_log)
XX ("edit-input", "Edit input", on_edit_input)
XX ("redraw-screen", "Redraw screen", on_redraw_screen)
XX ("insert-attribute", "mIRC formatting", on_insert_attribute)
XX ("start-paste-mode", "Bracketed paste", on_start_paste_mode)
XX ("previous-buffer", "Previous buffer", on_previous_buffer)
XX ("next-buffer", "Next buffer", on_next_buffer)
XX ("goto-buffer", "Go to buffer", on_goto_buffer)
XX ("switch-buffer", "Switch buffer", on_switch_buffer)
XX ("goto-highlight", "Go to highlight", on_goto_highlight)
XX ("goto-activity", "Go to activity", on_goto_activity)
XX ("move-buffer-left", "Move buffer left", on_move_buffer_left)
XX ("move-buffer-right", "Move buffer right", on_move_buffer_right)
XX ("display-backlog", "Show backlog", on_display_backlog)
XX ("display-backlog-nw", "Non-wrapped log", on_display_backlog_nowrap)
XX ("display-full-log", "Show full log", on_display_full_log)
XX ("edit-input", "Edit input", on_edit_input)
XX ("redraw-screen", "Redraw screen", on_redraw_screen)
XX ("insert-attribute", "mIRC formatting", on_insert_attribute)
XX ("start-paste-mode", "Bracketed paste", on_start_paste_mode)
#undef XX
}
@ -12393,7 +12416,7 @@ bind_common_keys (struct app_context *ctx)
if (key_f5) CALL_ (self, bind, key_f5, "previous-buffer");
if (key_f6) CALL_ (self, bind, key_f6, "next-buffer");
if (key_ppage) CALL_ (self, bind, key_ppage, "display-backlog");
if (key_ppage) CALL_ (self, bind, key_ppage, "display-backlog-nw");
if (clear_screen)
CALL_ (self, bind_control, 'l', "redraw-screen");
@ -13301,7 +13324,7 @@ format_input_and_die (struct app_context *ctx)
struct formatter f;
formatter_init (&f, ctx, NULL);
formatter_add (&f, "#m", buf);
formatter_flush (&f, stdout, false);
formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP);
formatter_free (&f);
}
exit (EXIT_SUCCESS);