Skip to content

Commit

Permalink
LyricsPage: use def_prog_mode()/reset_prog_mode() for spawning the ed…
Browse files Browse the repository at this point in the history
…itor

Calling ncu_deinit() (and delscreen()) causes ncmpc to crash after
returning from the editor.  This way, we don't actually deinitialize
ncurses and instead just change its state.

Closes #133
  • Loading branch information
MaxKellermann committed Sep 11, 2024
1 parent 210f5cd commit 8873b5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ncmpc 0.50 - not yet released
* draw progress bar as Unicode double line
* add color style "text" for input text controls
* remove option "text-editor-ask"
* fix lyrics editor crash
* lyrics/musixmatch: add new lyrics extension
* lyrics/google: fix partial loading of lyrics
* support MPD 0.22 tag "label" (requires libmpdclient 2.17)
Expand Down
8 changes: 4 additions & 4 deletions src/LyricsPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Options.hxx"
#include "screen.hxx"
#include "plugin.hxx"
#include "ncu.hxx"
#include "page/TextPage.hxx"
#include "lib/fmt/ToSpan.hxx"
#include "client/mpdclient.hxx"
Expand Down Expand Up @@ -346,15 +345,16 @@ LyricsPage::Edit() noexcept
if (!Save())
return;

ncu_deinit();
def_prog_mode();
endwin();

/* TODO: fork/exec/wait won't work on Windows, but building a command
string for system() is too tricky */
int status;
pid_t pid = fork();
if (pid == -1) {
reset_prog_mode();
FmtAlert("{} ({})"sv, _("Can't start editor"), strerror(errno));
ncu_init();
return;
} else if (pid == 0) {
execlp(editor, editor, path.c_str(), nullptr);
Expand All @@ -367,7 +367,7 @@ LyricsPage::Edit() noexcept
} while (ret == -1 && errno == EINTR);
}

ncu_init();
reset_prog_mode();

/* TODO: hardly portable */
if (WIFEXITED(status)) {
Expand Down

0 comments on commit 8873b5f

Please sign in to comment.