aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-09-24 16:12:07 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-09-24 16:16:31 +0200
commitbc54bf520db3b452ac222b0f15415ad1a4700183 (patch)
tree63321b772fdb5a4635229164f8ea2f1c9855012c
parent11aaf1b325be353f7ac9e5ebbf4d9c6ed2cf722e (diff)
downloadxK-bc54bf520db3b452ac222b0f15415ad1a4700183.tar.gz
xK-bc54bf520db3b452ac222b0f15415ad1a4700183.tar.xz
xK-bc54bf520db3b452ac222b0f15415ad1a4700183.zip
degesch: add Meta-H to open the full log file
As opposed to just the visible backlog.
-rw-r--r--degesch.c99
1 files changed, 80 insertions, 19 deletions
diff --git a/degesch.c b/degesch.c
index 0500fa2..0533401 100644
--- a/degesch.c
+++ b/degesch.c
@@ -3037,12 +3037,9 @@ make_log_filename (const char *filename, struct str *output)
str_append_c (output, tolower_ascii (*p));
}
-static void
-buffer_open_log_file (struct app_context *ctx, struct buffer *buffer)
+static char *
+buffer_get_log_path (struct buffer *buffer)
{
- if (!ctx->logging || buffer->log_file)
- return;
-
struct str path;
str_init (&path);
get_xdg_home_dir (&path, "XDG_DATA_HOME", ".local/share");
@@ -3054,13 +3051,22 @@ buffer_open_log_file (struct app_context *ctx, struct buffer *buffer)
str_append_c (&path, '/');
make_log_filename (buffer->name, &path);
str_append (&path, ".log");
+ return str_steal (&path);
+}
+
+static void
+buffer_open_log_file (struct app_context *ctx, struct buffer *buffer)
+{
+ if (!ctx->logging || buffer->log_file)
+ return;
- if (!(buffer->log_file = fopen (path.str, "ab")))
+ char *path = buffer_get_log_path (buffer);
+ if (!(buffer->log_file = fopen (path, "ab")))
log_global_error (ctx, "Couldn't open log file `#s': #s",
- path.str, strerror (errno));
+ path, strerror (errno));
else
set_cloexec (fileno (buffer->log_file));
- str_free (&path);
+ free (path);
}
static void
@@ -9046,18 +9052,9 @@ exec_backlog_helper (const char *command, FILE *backlog)
}
static void
-display_backlog (struct app_context *ctx)
+launch_backlog_helper (struct app_context *ctx, FILE *backlog)
{
hard_assert (!ctx->running_backlog_helper);
-
- FILE *backlog = tmpfile ();
- set_cloexec (fileno (backlog));
-
- for (struct buffer_line *line = ctx->current_buffer->lines;
- line; line = line->next)
- buffer_line_write_to_backlog (ctx, line, backlog);
-
- rewind (backlog);
suspend_terminal (ctx);
pid_t child = fork ();
@@ -9084,6 +9081,47 @@ display_backlog (struct app_context *ctx)
}
static void
+display_backlog (struct app_context *ctx)
+{
+ FILE *backlog = tmpfile ();
+ if (!backlog)
+ {
+ log_global_error (ctx, "#s: #s",
+ "Failed to create a temporary file", strerror (errno));
+ return;
+ }
+
+ for (struct buffer_line *line = ctx->current_buffer->lines;
+ line; line = line->next)
+ buffer_line_write_to_backlog (ctx, line, backlog);
+
+ rewind (backlog);
+ set_cloexec (fileno (backlog));
+ launch_backlog_helper (ctx, backlog);
+}
+
+static void
+display_full_log (struct app_context *ctx)
+{
+ char *path = buffer_get_log_path (ctx->current_buffer);
+ FILE *full_log = fopen (path, "rb");
+ free (path);
+
+ if (!full_log)
+ {
+ log_global_error (ctx, "Failed to open log file for #s: #s",
+ ctx->current_buffer->name, strerror (errno));
+ return;
+ }
+
+ if (ctx->current_buffer->log_file)
+ fflush (ctx->current_buffer->log_file);
+
+ set_cloexec (fileno (full_log));
+ launch_backlog_helper (ctx, full_log);
+}
+
+static void
bind_common_keys (struct app_context *ctx)
{
struct input *self = &ctx->input;
@@ -9095,6 +9133,7 @@ bind_common_keys (struct app_context *ctx)
input_bind_meta (self, '0' + i, "goto-buffer");
input_bind_meta (self, 'm', "insert-attribute");
+ input_bind_meta (self, 'h', "display-full-log");
if (key_f5)
input_bind (self, key_f5, "previous-buffer");
@@ -9154,6 +9193,17 @@ on_readline_display_backlog (int count, int key)
}
static int
+on_readline_display_full_log (int count, int key)
+{
+ (void) count;
+ (void) key;
+
+ struct app_context *ctx = g_ctx;
+ display_full_log (ctx);
+ return 0;
+}
+
+static int
on_readline_redraw_screen (int count, int key)
{
(void) count;
@@ -9246,6 +9296,7 @@ app_readline_init (void)
rl_add_defun ("next-buffer", on_readline_next_buffer, -1);
rl_add_defun ("goto-buffer", on_readline_goto_buffer, -1);
rl_add_defun ("display-backlog", on_readline_display_backlog, -1);
+ rl_add_defun ("display-full-log", on_readline_display_full_log, -1);
rl_add_defun ("redraw-screen", on_readline_redraw_screen, -1);
rl_add_defun ("insert-attribute", on_readline_insert_attribute, -1);
rl_add_defun ("send-line", on_readline_return, -1);
@@ -9315,6 +9366,15 @@ on_editline_display_backlog (EditLine *editline, int key)
}
static unsigned char
+on_editline_display_full_log (EditLine *editline, int key)
+{
+ (void) editline;
+ (void) key;
+
+ display_full_log (g_ctx);
+}
+
+static unsigned char
on_editline_redraw_screen (EditLine *editline, int key)
{
(void) editline;
@@ -9430,7 +9490,8 @@ app_editline_init (struct input *self)
{ "goto-buffer", "Go to buffer", on_editline_goto_buffer },
{ "previous-buffer", "Previous buffer", on_editline_previous_buffer },
{ "next-buffer", "Next buffer", on_editline_next_buffer },
- { "display-backlog", "Display backlog", on_editline_display_backlog },
+ { "display-backlog", "Show backlog", on_editline_display_backlog },
+ { "display-full-log", "Show full log", on_editline_display_full_log },
{ "redraw-screen", "Redraw screen", on_editline_redraw_screen },
{ "insert-attribute", "mIRC formatting", on_editline_insert_attribute },
{ "send-line", "Send line", on_editline_return },