summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJefferson Delfes <jefferson.delfes@gmail.com>2013-12-02 09:34:59 -0400
committerJefferson Delfes <jefferson.delfes@gmail.com>2013-12-02 12:12:04 -0400
commit713c8baad42915e32c2d07a4ee6a8b81197cb758 (patch)
tree9dbbb0a4771782f2d39c7a9f77d006597954b874
parentd1cc874ed4a1d8476dff8b47172c22804335d0f6 (diff)
rl_helper: restore terminal settings on exit
We disable echo on terminal, so we need to restore any changes that we made.
-rw-r--r--rl_helper.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/rl_helper.c b/rl_helper.c
index 62a5cbe..64df0c8 100644
--- a/rl_helper.c
+++ b/rl_helper.c
@@ -53,6 +53,7 @@ typedef enum {
K_DELETE = 0x106,
} keys_t;
+struct termios saved_term_setts;
line_process_callback line_cb;
static tab_completer_callback tab_completer_cb = NULL;
char lnbuf[MAX_LINE_BUFFER]; /* buffer for our line editing */
@@ -142,11 +143,18 @@ void rl_reprint_prompt() {
fflush(stdout);
}
+void restore_tc_setts() {
+
+ tcsetattr(0, TCSANOW, &saved_term_setts); /* restore settings */
+}
+
void rl_init(line_process_callback cb) {
struct termios settings;
/* disable echo */
- tcgetattr(0, &settings); /* read settings from stdin (0) */
+ tcgetattr(0, &saved_term_setts); /* read settings from stdin (0) */
+ atexit(restore_tc_setts);
+ settings = saved_term_setts;
settings.c_lflag &= ~(ICANON | ECHO); /* disable canonical and echo flags */
tcsetattr(0, TCSANOW, &settings); /* store new settings */