degesch: add Meta-H to open the full log file

As opposed to just the visible backlog.
This commit is contained in:
Přemysl Eric Janouch 2015-09-24 16:12:07 +02:00
parent 11aaf1b325
commit bc54bf520d
1 changed files with 80 additions and 19 deletions

View File

@ -3037,12 +3037,9 @@ make_log_filename (const char *filename, struct str *output)
str_append_c (output, tolower_ascii (*p)); str_append_c (output, tolower_ascii (*p));
} }
static void static char *
buffer_open_log_file (struct app_context *ctx, struct buffer *buffer) buffer_get_log_path (struct buffer *buffer)
{ {
if (!ctx->logging || buffer->log_file)
return;
struct str path; struct str path;
str_init (&path); str_init (&path);
get_xdg_home_dir (&path, "XDG_DATA_HOME", ".local/share"); 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, '/'); str_append_c (&path, '/');
make_log_filename (buffer->name, &path); make_log_filename (buffer->name, &path);
str_append (&path, ".log"); str_append (&path, ".log");
return str_steal (&path);
}
if (!(buffer->log_file = fopen (path.str, "ab"))) static void
buffer_open_log_file (struct app_context *ctx, struct buffer *buffer)
{
if (!ctx->logging || buffer->log_file)
return;
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", log_global_error (ctx, "Couldn't open log file `#s': #s",
path.str, strerror (errno)); path, strerror (errno));
else else
set_cloexec (fileno (buffer->log_file)); set_cloexec (fileno (buffer->log_file));
str_free (&path); free (path);
} }
static void static void
@ -9046,18 +9052,9 @@ exec_backlog_helper (const char *command, FILE *backlog)
} }
static void static void
display_backlog (struct app_context *ctx) launch_backlog_helper (struct app_context *ctx, FILE *backlog)
{ {
hard_assert (!ctx->running_backlog_helper); 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); suspend_terminal (ctx);
pid_t child = fork (); pid_t child = fork ();
@ -9083,6 +9080,47 @@ display_backlog (struct app_context *ctx)
fclose (backlog); fclose (backlog);
} }
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 static void
bind_common_keys (struct app_context *ctx) bind_common_keys (struct app_context *ctx)
{ {
@ -9095,6 +9133,7 @@ bind_common_keys (struct app_context *ctx)
input_bind_meta (self, '0' + i, "goto-buffer"); input_bind_meta (self, '0' + i, "goto-buffer");
input_bind_meta (self, 'm', "insert-attribute"); input_bind_meta (self, 'm', "insert-attribute");
input_bind_meta (self, 'h', "display-full-log");
if (key_f5) if (key_f5)
input_bind (self, key_f5, "previous-buffer"); input_bind (self, key_f5, "previous-buffer");
@ -9153,6 +9192,17 @@ on_readline_display_backlog (int count, int key)
return 0; return 0;
} }
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 static int
on_readline_redraw_screen (int count, int key) on_readline_redraw_screen (int count, int key)
{ {
@ -9246,6 +9296,7 @@ app_readline_init (void)
rl_add_defun ("next-buffer", on_readline_next_buffer, -1); rl_add_defun ("next-buffer", on_readline_next_buffer, -1);
rl_add_defun ("goto-buffer", on_readline_goto_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-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 ("redraw-screen", on_readline_redraw_screen, -1);
rl_add_defun ("insert-attribute", on_readline_insert_attribute, -1); rl_add_defun ("insert-attribute", on_readline_insert_attribute, -1);
rl_add_defun ("send-line", on_readline_return, -1); rl_add_defun ("send-line", on_readline_return, -1);
@ -9314,6 +9365,15 @@ on_editline_display_backlog (EditLine *editline, int key)
display_backlog (g_ctx); display_backlog (g_ctx);
} }
static unsigned char
on_editline_display_full_log (EditLine *editline, int key)
{
(void) editline;
(void) key;
display_full_log (g_ctx);
}
static unsigned char static unsigned char
on_editline_redraw_screen (EditLine *editline, int key) on_editline_redraw_screen (EditLine *editline, int key)
{ {
@ -9430,7 +9490,8 @@ app_editline_init (struct input *self)
{ "goto-buffer", "Go to buffer", on_editline_goto_buffer }, { "goto-buffer", "Go to buffer", on_editline_goto_buffer },
{ "previous-buffer", "Previous buffer", on_editline_previous_buffer }, { "previous-buffer", "Previous buffer", on_editline_previous_buffer },
{ "next-buffer", "Next buffer", on_editline_next_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 }, { "redraw-screen", "Redraw screen", on_editline_redraw_screen },
{ "insert-attribute", "mIRC formatting", on_editline_insert_attribute }, { "insert-attribute", "mIRC formatting", on_editline_insert_attribute },
{ "send-line", "Send line", on_editline_return }, { "send-line", "Send line", on_editline_return },