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>
#ifdef __USE_GNU_GETTEXT
#include <libintl.h>
#define _(String) gettext(String)
#define gettext_noop(String) String
#define N_(String) gettext_noop(String)
#else
#define _(String) (String)
#define N_(String) String
#define textdomain(Domain)
#define bindtextdomain(Package, Directory)
#endif
int main(int argc, char **argv) {
char c = 'Y';
char *msg;
struct termios raw_tioctl;
char emsg[128];
if (argc < 2)
strcpy(emsg, _("Press any key"));
else
strcpy(emsg, argv[1]);
raw_tioctl = shell_tioctl;
mk_raw_tioctl(&raw_tioctl);
tcflush(0, TCOFLUSH);
while (1) {
msg = emsg;
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.
int main(void)
#define _(String)
Definition amort.c:23
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:132
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:57