Skip to content

Commit 4bc402c

Browse files
committed
chore: re-enable cursor if program dies (and wrap-lines is enabled ofc)
1 parent 848e18d commit 4bc402c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
500500
return true;
501501
}
502502

503+
void enable_cursor()
504+
{
505+
fmt::print("\x1B[?25h\x1B[?7h");
506+
}
507+
503508
#if ANDROID_APP
504509
int mainAndroid(int argc, char *argv[])
505510
#else
@@ -587,13 +592,17 @@ int main(int argc, char *argv[])
587592

588593
if (config.wrap_lines)
589594
{
595+
// https://en.cppreference.com/w/c/program/exit
596+
// if something goes wrong like a segfault, then re-enable the cursor again
597+
std::atexit(enable_cursor);
598+
590599
// hide cursor and disable line wrapping
591600
fmt::print("\x1B[?25l\x1B[?7l");
592601

593602
Display::display(Display::render(config, colors, false, path));
594603

595604
// enable both of them again
596-
fmt::print("\x1B[?25h\x1B[?7h");
605+
enable_cursor();
597606
}
598607
else
599608
{

0 commit comments

Comments
 (0)