msh

simple shell implementation
Index Commits Files Refs README LICENSE
tui.c (749B)
   1 #include "tui.h"
   2 
   3 #include <termios.h>
   4 #include <stdlib.h>
   5 #include <unistd.h>
   6 
   7 static struct termios default_attributes;
   8 
   9 void tui_reset_input_mode (void) {
  10     tcsetattr(STDIN_FILENO, TCSANOW, &default_attributes);
  11 }
  12 
  13 void tui_set_input_mode (void) {
  14     struct termios tattr;
  15 
  16     /* Save the terminal attributes so we can restore them later. */
  17     tcgetattr(STDIN_FILENO, &default_attributes);
  18     atexit(tui_reset_input_mode);
  19 
  20     /* Set the terminal modes. */
  21     tcgetattr(STDIN_FILENO, &tattr);
  22 
  23     tattr.c_iflag &= ~(PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
  24     tattr.c_oflag &= ~OPOST;
  25     tattr.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  26     tattr.c_cflag &= ~(CSIZE | PARENB);
  27     tattr.c_cflag |= CS8;
  28 
  29     tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr);
  30 }