Skip to content

Commit 46cda1b

Browse files
authored
Do not use CTRL+C to close the app, only use quit/exit (#137)
* WIP Signed-off-by: Denisa <denisa@eprosima.com> * WIP2 Signed-off-by: Denisa <denisa@eprosima.com> * Do not use CTRl+C to close the app Signed-off-by: Denisa <denisa@eprosima.com> * Fix white lines1 Signed-off-by: Denisa <denisa@eprosima.com> * Add comment for ISIG Signed-off-by: Denisa <denisa@eprosima.com> --------- Signed-off-by: Denisa <denisa@eprosima.com>
1 parent 2f19b0c commit 46cda1b

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

cpp_utils/src/cpp/event/StdinEventHandler.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,13 @@ void StdinEventHandler::set_terminal_mode_(
209209
DWORD new_mode = old_mode;
210210
new_mode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);
211211
SetConsoleMode(hStdin, new_mode);
212+
SetConsoleCtrlHandler(NULL, TRUE);
212213
}
213214
else
214215
{
215216
// Restore input and output modes
216217
SetConsoleMode(hStdin, old_mode);
218+
SetConsoleCtrlHandler(NULL, FALSE);
217219
}
218220

219221
#else
@@ -230,7 +232,8 @@ void StdinEventHandler::set_terminal_mode_(
230232
// Modify line mode flags
231233
// - ICANON: Desactivate canonic mode (process each character)
232234
// - ECHO: Desactivate echo (does not print what the user writes on terminal)
233-
newt.c_lflag &= ~(ICANON | ECHO);
235+
// - ISIG: Deactivate signals (Ctrl+C, Ctrl+Z)
236+
newt.c_lflag &= ~(ICANON | ECHO | ISIG);
234237

235238
// Apply new configuration
236239
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
@@ -392,6 +395,14 @@ void StdinEventHandler::stdin_listener_thread_routine_() noexcept
392395

393396
}
394397
}
398+
else if (c == '\x03') // Ctrl+C
399+
{
400+
std::cout << std::endl;
401+
event_occurred_("");
402+
read_str = "";
403+
cursor_index = 0;
404+
break;
405+
}
395406
else
396407
{
397408
char ch = static_cast<char>(c);

0 commit comments

Comments
 (0)