C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Screen IO Support

Provides Terminal Settings for C-MENU Applications and Restores Terminal State on Exit. More...

Functions

bool capture_curses_tioctl ()
 capture_curses_tioctl() - capture curses terminal settings
bool capture_shell_tioctl ()
 capture_shell_tioctl() - capture shell terminal settings
char di_getch ()
 get single character from terminal in raw mode
bool mk_raw_tioctl (struct termios *t_p)
 mk_raw_tioctl() - set terminal to raw mode
bool restore_curses_tioctl ()
 restore_curses_tioctl() - restore curses terminal settings
bool restore_shell_tioctl ()
 restore_shell_tioctl() - restore shell terminal settings
bool set_sane_tioctl (struct termios *t_p)
 set_sane_tioctl() - set terminal to sane settings for C-MENU

Detailed Description

Provides Terminal Settings for C-MENU Applications and Restores Terminal State on Exit.

Terminal Handling

Function Documentation

◆ capture_curses_tioctl()

bool capture_curses_tioctl ( )

capture_curses_tioctl() - capture curses terminal settings

Returns
- true on success
  • captures terminal settings for stdin, stdout, and stderr

Definition at line 70 of file scriou.c.

70 {
72 return true;
73 fflush(NULL);
74 tcgetattr(0, &curses_in_tioctl);
75 tcgetattr(1, &curses_out_tioctl);
76 tcgetattr(2, &curses_err_tioctl);
78 return true;
79}
bool f_have_curses_tioctl
Definition scriou.c:25
struct termios shell_out_tioctl curses_out_tioctl
Definition scriou.c:36
struct termios shell_in_tioctl curses_in_tioctl
Definition scriou.c:35
struct termios shell_err_tioctl curses_err_tioctl
Definition scriou.c:37

References curses_err_tioctl, curses_in_tioctl, curses_out_tioctl, and f_have_curses_tioctl.

Referenced by fork_exec(), and main().

Here is the caller graph for this function:

◆ capture_shell_tioctl()

bool capture_shell_tioctl ( )

capture_shell_tioctl() - capture shell terminal settings

Returns
- true on success
  • captures terminal settings for stdin, stdout, and stderr

Definition at line 43 of file scriou.c.

43 {
45 return true;
46 fflush(NULL);
47 tcgetattr(0, &shell_in_tioctl);
48 tcgetattr(1, &shell_out_tioctl);
49 tcgetattr(2, &shell_err_tioctl);
51 return true;
52}
bool f_have_shell_tioctl
Definition scriou.c:24

References f_have_shell_tioctl.

Referenced by main().

Here is the caller graph for this function:

◆ di_getch()

char di_getch ( )

get single character from terminal in raw mode

Returns
- the character read from terminal

intended to be used when curses is not active

Note
restores terminal settings before returning

Definition at line 158 of file scriou.c.

158 {
159 struct termios org_tioctl, new_tioctl;
160 char buf;
161
162 fflush(NULL);
163 if (tcgetattr(2, &org_tioctl) == -1) {
164 fprintf(stderr, "\ndi_getch: tcgetattr failed\n");
165 return (0);
166 }
167 new_tioctl = org_tioctl;
168 new_tioctl.c_lflag &= ~(ECHO | ICANON);
169 new_tioctl.c_cc[VMIN] = 1;
170 new_tioctl.c_cc[VTIME] = 0;
171 fflush(NULL);
172 tcsetattr(2, TCSAFLUSH, &new_tioctl);
173 read(2, &buf, 1);
174 fflush(NULL);
175 tcsetattr(2, TCSAFLUSH, &org_tioctl);
176 return (buf);
177}

◆ mk_raw_tioctl()

bool mk_raw_tioctl ( struct termios * t_p)

mk_raw_tioctl() - set terminal to raw mode

Parameters
t_p- pointer to termios structure to modify
Returns
- true on success
  • unlike cfmakeraw(), this leaves ISIG enabled. cfmakeraw() disables ISIG, which prevents C-MENU from handling signals like Ctrl-C. Instead of using cfmakeraw(), we manually set the terminal to raw mode while leaving ISIG enabled. The following code is equivalent to cfmakeraw() but with ISIG left enabled:
    t_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR |
    IGNCR | ICRNL | IXON | IXOFF);
    t_p->c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
    t_p->c_cflag &= ~(CSIZE | PARENB);
    t_p->c_cflag |= CS8 | CLOCAL;

Definition at line 132 of file scriou.c.

132 {
133 fflush(NULL);
134 tcgetattr(0, t_p);
135 t_p->c_lflag |= ISIG;
136 t_p->c_lflag &= ~(ECHO | ICANON);
137 t_p->c_cc[VMIN] = 1;
138 t_p->c_cc[VTIME] = 0;
139 fflush(NULL);
140 tcsetattr(0, TCSAFLUSH, t_p);
141 fflush(NULL);
142 tcgetattr(2, t_p);
143 t_p->c_lflag |= ISIG;
144 t_p->c_lflag &= ~(ECHO | ICANON);
145 t_p->c_cc[VMIN] = 1;
146 t_p->c_cc[VTIME] = 0;
147 fflush(NULL);
148 tcsetattr(2, TCSAFLUSH, t_p);
149 return true;
150}

Referenced by main().

Here is the caller graph for this function:

◆ restore_curses_tioctl()

bool restore_curses_tioctl ( )

restore_curses_tioctl() - restore curses terminal settings

Returns
- true on success
  • restores terminal settings for stdin, stdout, and stderr

Definition at line 84 of file scriou.c.

84 {
86 return false;
87 fflush(NULL);
88 tcsetattr(0, TCSANOW, &curses_in_tioctl);
89 tcsetattr(1, TCSANOW, &curses_out_tioctl);
90 tcsetattr(2, TCSANOW, &curses_err_tioctl);
91
92 return true;
93}

References curses_err_tioctl, curses_in_tioctl, curses_out_tioctl, and f_have_curses_tioctl.

◆ restore_shell_tioctl()

bool restore_shell_tioctl ( )

restore_shell_tioctl() - restore shell terminal settings

Returns
- true on success
  • restores terminal settings for stdin, stdout, and stderr

Definition at line 57 of file scriou.c.

57 {
59 return false;
60 fflush(NULL);
61 tcsetattr(0, TCSANOW, &shell_in_tioctl);
62 tcsetattr(1, TCSANOW, &shell_out_tioctl);
63 tcsetattr(2, TCSANOW, &shell_err_tioctl);
64 return true;
65}

References f_have_shell_tioctl.

Referenced by abend(), destroy_curses(), fork_exec(), handle_signal(), and main().

Here is the caller graph for this function:

◆ set_sane_tioctl()

bool set_sane_tioctl ( struct termios * t_p)

set_sane_tioctl() - set terminal to sane settings for C-MENU

Parameters
t_p- pointer to termios structure to modify
Returns
- true on success
  • sets terminal to sane settings for C-MENU applications

Definition at line 99 of file scriou.c.

99 {
100 fflush(NULL);
101 tcgetattr(0, t_p);
102 t_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INPCK | ISTRIP | INLCR |
103 IGNCR | ICRNL | IXON | IXOFF);
104 t_p->c_iflag |= IUTF8;
105 t_p->c_oflag |= OPOST | ONLCR;
106 t_p->c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
107 t_p->c_lflag |= (ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK);
108 t_p->c_cflag &= ~(CSIZE | PARENB);
109 t_p->c_cflag |= CS8 | CLOCAL | CREAD;
110 fflush(NULL);
111 tcsetattr(0, TCSANOW, t_p);
112 return true;
113}

Referenced by signal_handler().

Here is the caller graph for this function: