From 51ebe9e52db78341d6ed77424c17da41bacedde8 Mon Sep 17 00:00:00 2001 From: Drew Marino <77032812+OneTrueC@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:54:12 -0400 Subject: [PATCH] Fixed bug related to readline.h (#592) Terminals that don't restore the terminal state when a program exits display stdin incorrectly after quitting. This is not a bug in readline.h as its examples use termios in the same way. --- src/curses/window.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/curses/window.cpp b/src/curses/window.cpp index 59c45456..b0cc9633 100644 --- a/src/curses/window.cpp +++ b/src/curses/window.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "utility/readline.h" @@ -216,6 +217,8 @@ Color Color::Cyan(COLOR_CYAN, Color::current); Color Color::White(COLOR_WHITE, Color::current); Color Color::End(0, 0, false, true); +struct termios orig_termios; + int Color::pairNumber() const { // If colors are disabled, return default pair value. @@ -400,6 +403,7 @@ int colorCount() void initScreen(bool enable_colors, bool enable_mouse) { + tcgetattr(STDIN_FILENO, &orig_termios); initscr(); if (has_colors() && enable_colors) { @@ -481,6 +485,7 @@ void destroyScreen() Mouse::disable(); curs_set(1); endwin(); + tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios); } Window::Window(size_t startx, size_t starty, size_t width, size_t height,