C-Menu 0.2.9
A User Interface Toolkit
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]);
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;
}
}
if (c == (char)0x1b)
return (1);
return (0);
}
Headder for C-Menu API library, libcm.so.
char errmsg[]
Definition futil.c:84
int main(int argc, char **argv)
Capture the current terminal settings for later restoration.
Definition enterchr.c:38
struct termios shell_tioctl
Definition scriou.c:22
bool capture_shell_tioctl()
capture_shell_tioctl() - capture shell terminal settings
Definition scriou.c:43
bool mk_raw_tioctl(struct termios *)
mk_raw_tioctl() - set terminal to raw mode
Definition scriou.c:126
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:56