C-Menu
0.2.9
A User Interface Toolkit
Toggle main menu visibility
Loading...
Searching...
No Matches
/usr/local/src/C-Menu/src/enterchr.c
key=$(enterchr
"Are you sure?: "
)
if
[
"$key"
=
"Y"
]; then
echo
"You entered Y"
else
echo
"You entered N"
fi
#include <
cm.h
>
#include <fcntl.h>
#include <stdbool.h>
#include <string.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
int
main
(
int
argc,
char
**argv) {
char
c =
'Y'
;
char
*msg;
struct
termios raw_tioctl;
char
errmsg
[128];
if
(argc < 2)
strcpy(
errmsg
,
"Press any key"
);
else
strcpy(
errmsg
, argv[1]);
capture_shell_tioctl
();
raw_tioctl =
shell_tioctl
;
mk_raw_tioctl
(&raw_tioctl);
tcflush(0, TCOFLUSH);
while
(1) {
msg =
errmsg
;
while
(*msg) {
write(2, msg++, 1);
}
if
(read(0, &c, 1) > 0) {
write(1, &c, 1);
break
;
}
}
restore_shell_tioctl
();
if
(c == (
char
)0x1b)
return
(1);
return
(0);
}
cm.h
Headder for C-Menu API library, libcm.so.
errmsg
char errmsg[]
Definition
futil.c:84
main
int main(int argc, char **argv)
Capture the current terminal settings for later restoration.
Definition
enterchr.c:38
shell_tioctl
struct termios shell_tioctl
Definition
scriou.c:22
capture_shell_tioctl
bool capture_shell_tioctl()
capture_shell_tioctl() - capture shell terminal settings
Definition
scriou.c:43
mk_raw_tioctl
bool mk_raw_tioctl(struct termios *)
mk_raw_tioctl() - set terminal to raw mode
Definition
scriou.c:126
restore_shell_tioctl
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition
scriou.c:56
Generated by
1.17.0