+void
+set_terminal_mode(void)
+{
+ struct termios options;
+ tcgetattr(STDIN_FILENO, &options);
+ /* Create a cbreak-like environment through the following options. */
+ options.c_lflag &= ~ECHO; /* Disable echoing of input characters. */
+ options.c_lflag &= ~ICANON; /* Disable cooked/line-oriented mode. */
+ options.c_cc[VMIN] = 1;
+ options.c_cc[VTIME] = 0;
+ tcsetattr(STDIN_FILENO, TCSANOW, &options);
+}
+
+void
+unset_terminal_mode(void)
+{
+ struct termios options;
+ tcgetattr(STDIN_FILENO, &options);
+ /* Undo the changes made in set_terminal_mode(). */
+ options.c_lflag |= ECHO; /* Enable echoing of input characters. */
+ options.c_lflag |= ICANON; /* Enable cooked/line-oriented mode. */
+ options.c_cc[VMIN] = 1; /* Default value from /usr/src/sys/sys/ttydefaults.h */
+ options.c_cc[VTIME] = 0; /* Default value from /usr/src/sys/sys/ttydefaults.h */
+ tcsetattr(STDIN_FILENO, TCSANOW, &options);
+}
+