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:
		
							
								
								
									
										71
									
								
								degesch.c
									
									
									
									
									
								
							
							
						
						
									
										71
									
								
								degesch.c
									
									
									
									
									
								
							@@ -3565,12 +3565,19 @@ formatter_to_chars (struct formatter *formatter)
 | 
				
			|||||||
	return self.result;
 | 
						return self.result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						FLUSH_OPT_RAW    = (1 << 0),        ///< Print raw attributes
 | 
				
			||||||
 | 
						FLUSH_OPT_NOWRAP = (1 << 1)         ///< Do not wrap
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					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);
 | 
						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)
 | 
							LIST_FOR_EACH (struct line_char, c, line)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -3580,7 +3587,7 @@ formatter_flush (struct formatter *self, FILE *stream, bool raw_attributes)
 | 
				
			|||||||
		return;
 | 
							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);
 | 
							line = line_wrap (line, g_terminal.columns);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO: rewrite the sloppily hacked mess around attribute_printer;
 | 
						// 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
 | 
					static void
 | 
				
			||||||
buffer_line_flush (struct buffer_line *line, struct formatter *f, FILE *output,
 | 
					buffer_line_flush (struct buffer_line *line, struct formatter *f, FILE *output,
 | 
				
			||||||
	bool raw_attributes)
 | 
						int flush_opts)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int flags = line->flags;
 | 
						int flags = line->flags;
 | 
				
			||||||
	if (flags & BUFFER_LINE_INDENT)  formatter_add (f, "    ");
 | 
						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_item (f, *iter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	formatter_add (f, "\n");
 | 
						formatter_add (f, "\n");
 | 
				
			||||||
	formatter_flush (f, output, raw_attributes);
 | 
						formatter_flush (f, output, flush_opts);
 | 
				
			||||||
	formatter_free (f);
 | 
						formatter_free (f);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3712,7 +3719,7 @@ buffer_line_display (struct app_context *ctx,
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	CALL (ctx->input, hide);
 | 
						CALL (ctx->input, hide);
 | 
				
			||||||
	buffer_line_flush (line, &f, stdout, false);
 | 
						buffer_line_flush (line, &f, stdout, 0);
 | 
				
			||||||
	// Flush the trailing formatting reset item
 | 
						// Flush the trailing formatting reset item
 | 
				
			||||||
	fflush (stdout);
 | 
						fflush (stdout);
 | 
				
			||||||
	CALL (ctx->input, show);
 | 
						CALL (ctx->input, show);
 | 
				
			||||||
@@ -3720,7 +3727,7 @@ buffer_line_display (struct app_context *ctx,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
buffer_line_write_to_backlog (struct app_context *ctx,
 | 
					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;
 | 
						struct formatter f;
 | 
				
			||||||
	formatter_init (&f, ctx, NULL);
 | 
						formatter_init (&f, ctx, NULL);
 | 
				
			||||||
@@ -3734,7 +3741,7 @@ buffer_line_write_to_backlog (struct app_context *ctx,
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
		formatter_add (&f, "#a#s#r ", ATTR_TIMESTAMP, buf);
 | 
							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
 | 
					static void
 | 
				
			||||||
@@ -3756,7 +3763,8 @@ buffer_line_write_to_log (struct app_context *ctx,
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
		formatter_add (&f, "#s ", buf);
 | 
							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
 | 
					static void
 | 
				
			||||||
@@ -4006,12 +4014,12 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					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;
 | 
						struct formatter f;
 | 
				
			||||||
	formatter_init (&f, ctx, NULL);
 | 
						formatter_init (&f, ctx, NULL);
 | 
				
			||||||
	formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER);
 | 
						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
 | 
						// Flush the trailing formatting reset item
 | 
				
			||||||
	fflush (stream);
 | 
						fflush (stream);
 | 
				
			||||||
	formatter_free (&f);
 | 
						formatter_free (&f);
 | 
				
			||||||
@@ -4060,8 +4068,8 @@ buffer_print_backlog (struct app_context *ctx, struct buffer *buffer)
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		if (until_marker-- == 0
 | 
							if (until_marker-- == 0
 | 
				
			||||||
		 && buffer->new_messages_count != buffer->lines_count)
 | 
							 && buffer->new_messages_count != buffer->lines_count)
 | 
				
			||||||
			buffer_print_read_marker (ctx, stdout, false);
 | 
								buffer_print_read_marker (ctx, stdout, 0);
 | 
				
			||||||
		buffer_line_display (ctx, line, false);
 | 
							buffer_line_display (ctx, line, 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// So that it is obvious if the last line in the buffer is not from today
 | 
						// 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
 | 
					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 ();
 | 
						FILE *backlog = tmpfile ();
 | 
				
			||||||
	if (!backlog)
 | 
						if (!backlog)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -12159,8 +12163,10 @@ on_display_backlog (int count, int key, void *user_data)
 | 
				
			|||||||
			"Failed to create a temporary file", strerror (errno));
 | 
								"Failed to create a temporary file", strerror (errno));
 | 
				
			||||||
		return false;
 | 
							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;
 | 
						struct buffer *buffer = ctx->current_buffer;
 | 
				
			||||||
	int until_marker =
 | 
						int until_marker =
 | 
				
			||||||
@@ -12169,8 +12175,8 @@ on_display_backlog (int count, int key, void *user_data)
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		if (until_marker-- == 0
 | 
							if (until_marker-- == 0
 | 
				
			||||||
		 && buffer->new_messages_count != buffer->lines_count)
 | 
							 && buffer->new_messages_count != buffer->lines_count)
 | 
				
			||||||
			buffer_print_read_marker (ctx, backlog, raw_attributes);
 | 
								buffer_print_read_marker (ctx, backlog, flush_opts);
 | 
				
			||||||
		buffer_line_write_to_backlog (ctx, line, backlog, raw_attributes);
 | 
							buffer_line_write_to_backlog (ctx, line, backlog, flush_opts);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rewind (backlog);
 | 
						rewind (backlog);
 | 
				
			||||||
@@ -12180,6 +12186,22 @@ on_display_backlog (int count, int key, void *user_data)
 | 
				
			|||||||
	return true;
 | 
						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
 | 
					static bool
 | 
				
			||||||
on_display_full_log (int count, int key, void *user_data)
 | 
					on_display_full_log (int count, int key, void *user_data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -12365,6 +12387,7 @@ input_add_functions (void *user_data)
 | 
				
			|||||||
	XX ("move-buffer-left",   "Move buffer left",  on_move_buffer_left)
 | 
						XX ("move-buffer-left",   "Move buffer left",  on_move_buffer_left)
 | 
				
			||||||
	XX ("move-buffer-right",  "Move buffer right", on_move_buffer_right)
 | 
						XX ("move-buffer-right",  "Move buffer right", on_move_buffer_right)
 | 
				
			||||||
	XX ("display-backlog",    "Show backlog",      on_display_backlog)
 | 
						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 ("display-full-log",   "Show full log",     on_display_full_log)
 | 
				
			||||||
	XX ("edit-input",         "Edit input",        on_edit_input)
 | 
						XX ("edit-input",         "Edit input",        on_edit_input)
 | 
				
			||||||
	XX ("redraw-screen",      "Redraw screen",     on_redraw_screen)
 | 
						XX ("redraw-screen",      "Redraw screen",     on_redraw_screen)
 | 
				
			||||||
@@ -12393,7 +12416,7 @@ bind_common_keys (struct app_context *ctx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (key_f5)     CALL_ (self, bind, key_f5, "previous-buffer");
 | 
						if (key_f5)     CALL_ (self, bind, key_f5, "previous-buffer");
 | 
				
			||||||
	if (key_f6)     CALL_ (self, bind, key_f6, "next-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)
 | 
						if (clear_screen)
 | 
				
			||||||
		CALL_ (self, bind_control, 'l', "redraw-screen");
 | 
							CALL_ (self, bind_control, 'l', "redraw-screen");
 | 
				
			||||||
@@ -13301,7 +13324,7 @@ format_input_and_die (struct app_context *ctx)
 | 
				
			|||||||
		struct formatter f;
 | 
							struct formatter f;
 | 
				
			||||||
		formatter_init (&f, ctx, NULL);
 | 
							formatter_init (&f, ctx, NULL);
 | 
				
			||||||
		formatter_add (&f, "#m", buf);
 | 
							formatter_add (&f, "#m", buf);
 | 
				
			||||||
		formatter_flush (&f, stdout, false);
 | 
							formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP);
 | 
				
			||||||
		formatter_free (&f);
 | 
							formatter_free (&f);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	exit (EXIT_SUCCESS);
 | 
						exit (EXIT_SUCCESS);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user