feat(editor): add asynchronous external editor support
Some checks failed
CI / Check spelling (pull_request) Successful in 18s
CI / Check coding style (pull_request) Successful in 31s
CI / Linux (fedora) (pull_request) Failing after 1m14s
CI / Linux (debian) (pull_request) Successful in 10m19s
CI / Linux (ubuntu) (pull_request) Successful in 10m42s
CI / Linux (arch) (pull_request) Successful in 13m2s
Some checks failed
CI / Check spelling (pull_request) Successful in 18s
CI / Check coding style (pull_request) Successful in 31s
CI / Linux (fedora) (pull_request) Failing after 1m14s
CI / Linux (debian) (pull_request) Successful in 10m19s
CI / Linux (ubuntu) (pull_request) Successful in 10m42s
CI / Linux (arch) (pull_request) Successful in 13m2s
The synchronous `get_message_from_editor` blocked the main loop (`prof_run`) while launching an external editor like `vim`, halting network I/O in `session_process_events` and preventing incoming message reception. Introduced `get_message_from_editor_async` for `cmd_editor` to run the editor asynchronously. It forks and execs the editor in a thread (`editor_thread`), suspending NCurses to free the terminal. The main loop skips `inp_readline` and `ui_update` via a new `background_mode` flag while the editor runs, allowing `session_process_events` to keep the connection alive. On editor completion, `editor_process` (called per loop iteration) resumes NCurses with `ui_resize`, inserts the result into the readline buffer and clears `background_mode`. Retained synchronous `get_message_from_editor` for ~20 existing code paths (e.g., `vcard_nickname`) to avoid breaking them. Tested with `vim` and `nano`: confirms no rendering conflicts, messages received during editing, and seamless resume. Edge cases like editor crashes handled via error logging and seamless resume.
This commit is contained in:
@@ -59,6 +59,7 @@
|
||||
#include "config/tlscerts.h"
|
||||
#include "config/scripts.h"
|
||||
#include "command/cmd_defs.h"
|
||||
#include "tools/editor.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "event/client_events.h"
|
||||
#include "ui/ui.h"
|
||||
@@ -93,6 +94,9 @@ static void _connect_default(const char* const account);
|
||||
pthread_mutex_t lock;
|
||||
static gboolean force_quit = FALSE;
|
||||
|
||||
// main.c (prof_run section)
|
||||
gboolean background_mode = FALSE;
|
||||
|
||||
void
|
||||
prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_file, gchar* theme_name, gchar** commands)
|
||||
{
|
||||
@@ -118,42 +122,44 @@ prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_f
|
||||
log_stderr_handler();
|
||||
session_check_autoaway();
|
||||
|
||||
line = commands ? *commands : inp_readline();
|
||||
if (commands && line && memcmp(line, "/sleep", 6) == 0) {
|
||||
if (!g_timer_is_active(waittimer)) {
|
||||
gchar* err_msg;
|
||||
if (strtoi_range(line + 7, &waittime, 0, 300, &err_msg)) {
|
||||
g_timer_start(waittimer);
|
||||
/* Increase the minimal runtime by the waiting time
|
||||
* so we can be sure there's runtime left after executing
|
||||
* the last command.
|
||||
*/
|
||||
min_runtime += waittime;
|
||||
} else {
|
||||
log_error(err_msg);
|
||||
g_free(err_msg);
|
||||
commands = NULL;
|
||||
if (!background_mode) {
|
||||
line = commands ? *commands : inp_readline();
|
||||
if (commands && line && memcmp(line, "/sleep", 6) == 0) {
|
||||
if (!g_timer_is_active(waittimer)) {
|
||||
gchar* err_msg;
|
||||
if (strtoi_range(line + 7, &waittime, 0, 300, &err_msg)) {
|
||||
g_timer_start(waittimer);
|
||||
/* Increase the minimal runtime by the waiting time
|
||||
* so we can be sure there's runtime left after executing
|
||||
* the last command.
|
||||
*/
|
||||
min_runtime += waittime;
|
||||
} else {
|
||||
log_error(err_msg);
|
||||
g_free(err_msg);
|
||||
commands = NULL;
|
||||
}
|
||||
} else if (g_timer_elapsed(waittimer, NULL) >= waittime) {
|
||||
g_timer_stop(waittimer);
|
||||
commands++;
|
||||
if (!(*commands))
|
||||
commands = NULL;
|
||||
}
|
||||
cont = TRUE;
|
||||
} else if (line) {
|
||||
ProfWin* window = wins_get_current();
|
||||
cont = cmd_process_input(window, line);
|
||||
if (commands) {
|
||||
commands++;
|
||||
if (!(*commands))
|
||||
commands = NULL;
|
||||
} else {
|
||||
free(line);
|
||||
line = NULL;
|
||||
}
|
||||
} else if (g_timer_elapsed(waittimer, NULL) >= waittime) {
|
||||
g_timer_stop(waittimer);
|
||||
commands++;
|
||||
if (!(*commands))
|
||||
commands = NULL;
|
||||
}
|
||||
cont = TRUE;
|
||||
} else if (line) {
|
||||
ProfWin* window = wins_get_current();
|
||||
cont = cmd_process_input(window, line);
|
||||
if (commands) {
|
||||
commands++;
|
||||
if (!(*commands))
|
||||
commands = NULL;
|
||||
} else {
|
||||
free(line);
|
||||
line = NULL;
|
||||
cont = TRUE;
|
||||
}
|
||||
} else {
|
||||
cont = TRUE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
@@ -163,7 +169,12 @@ prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_f
|
||||
notify_remind();
|
||||
session_process_events();
|
||||
iq_autoping_check();
|
||||
ui_update();
|
||||
|
||||
editor_process(wins_get_current());
|
||||
|
||||
if (!background_mode) {
|
||||
ui_update();
|
||||
}
|
||||
#ifdef HAVE_GTK
|
||||
tray_update();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user