4 * This file contains functions which implement parts of the
5 * text-mode user interface.
16 #include <sys/types.h>
25 #ifdef HAVE_SYS_SELECT_H
26 #include <sys/select.h>
29 #ifdef THREADED_CLIENT
39 #include "citadel_decls.h"
41 #include "routines2.h"
55 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
60 int rc_allow_attachments;
61 int rc_display_message_numbers;
62 int rc_force_mail_prompts;
63 int rc_remember_passwords;
66 char urls[MAXURLS][256];
70 int next_lazy_cmd = 5;
72 int lines_printed = 0; /* line count for paginator */
73 extern int screenwidth, screenheight;
75 struct citcmd *cmdlist = NULL;
78 /* these variables are local to this module */
79 char keepalives_enabled = KA_YES; /* send NOOPs to server when idle */
80 int ok_to_interrupt = 0; /* print express msgs asynchronously */
81 time_t AnsiDetect; /* when did we send the detect code? */
82 int enable_color = 0; /* nonzero for ANSI color */
88 * If an interesting key has been pressed, return its value, otherwise 0
90 char was_a_key_pressed(void) {
100 retval = select(1, &rfds, NULL, NULL, &tv);
102 /* Careful! Disable keepalives during keyboard polling; we're probably
103 * in the middle of a data transfer from the server, in which case
104 * sending a NOOP would throw the client protocol out of sync.
106 if (FD_ISSET(0, &rfds)) {
107 set_keepalives(KA_NO);
108 the_character = inkey();
109 set_keepalives(KA_YES);
114 return(the_character);
122 * Check to see if we need to pause at the end of a screen.
123 * If we do, we have to disable server keepalives during the pause because
124 * we are probably in the middle of a server operation and the NOOP command
125 * would confuse everything.
127 int checkpagin(int lp, int pagin, int height)
131 if (sigcaught) return(lp);
132 thekey = was_a_key_pressed();
133 if ( (thekey == NEXT_KEY) || (thekey == STOP_KEY)) sigcaught = thekey;
134 if (sigcaught) return(lp);
136 if (!pagin) return(0);
137 if (lp>=(height-1)) {
138 set_keepalives(KA_NO);
140 set_keepalives(KA_YES);
150 * pprintf() ... paginated version of printf()
152 void pprintf(const char *format, ...) {
154 static char buf[4096]; /* static for performance, change if needed */
157 /* If sigcaught is nonzero, a keypress has interrupted this and we
158 * should just drain output.
160 if (sigcaught) return;
162 /* Otherwise, start spewing... */
163 va_start(arg_ptr, format);
164 vsprintf(buf, format, arg_ptr);
167 for (i=0; i<strlen(buf); ++i) {
168 putc(buf[i], stdout);
171 lines_printed = checkpagin(lines_printed,
172 (userflags & US_PAGINATOR),
181 * print_express() - print express messages if there are any
183 void print_express(void)
193 if (express_msgs == 0)
202 while (express_msgs != 0) {
208 express_msgs = extract_int(&buf[4], 0);
209 timestamp = extract_long(&buf[4], 1);
210 flags = extract_int(&buf[4], 2);
211 extract(sender, &buf[4], 3);
212 extract(node, &buf[4], 4);
214 stamp = localtime(×tamp);
216 if (strlen(rc_exp_cmd) > 0) {
217 outpipe = popen(rc_exp_cmd, "w");
218 if (outpipe != NULL) {
219 /* Header derived from flags */
222 "Please log off now, as requested ");
224 fprintf(outpipe, "Broadcast message ");
226 fprintf(outpipe, "Chat request ");
228 fprintf(outpipe, "Message ");
229 /* 24hr format. Can be changed, I guess. */
230 fprintf(outpipe, "at %d:%02d from %s @%s:\n",
231 stamp->tm_hour, stamp->tm_min,
233 while (serv_gets(buf), strcmp(buf, "000")) {
234 fprintf(outpipe, "%s\n", buf);
240 /* fall back to built-in express message display */
243 /* Header derived from flags */
245 printf("Please log off now, as requested ");
247 printf("Broadcast message ");
249 printf("Chat request ");
253 /* Timestamp. Can this be improved? */
254 if (stamp->tm_hour == 0 || stamp->tm_hour == 12)/* 12am/12pm */
255 printf("at 12:%02d%cm", stamp->tm_min,
256 stamp->tm_hour ? 'p' : 'a');
257 else if (stamp->tm_hour > 12) /* pm */
258 printf("at %d:%02dpm",
259 stamp->tm_hour - 12, stamp->tm_min);
261 printf("at %d:%02dam", stamp->tm_hour, stamp->tm_min);
264 printf(" from %s", sender);
266 /* Remote node, if any */
267 if (strncmp(serv_info.serv_nodename, node, 32))
268 printf(" @%s", node);
272 while (serv_gets(buf), strcmp(buf, "000")) {
281 void set_keepalives(int s)
283 keepalives_enabled = (char) s;
287 * This loop handles the "keepalive" messages sent to the server when idling.
290 static time_t idlet = 0;
291 static void really_do_keepalive(void) {
295 if (keepalives_enabled == KA_YES) {
300 if (ok_to_interrupt == 1) {
301 printf("\r%64s\r", "");
303 printf("%s%c ", room_name,
304 room_prompt(room_flags));
311 /* threaded nonblocking keepalive stuff starts here. I'm going for a simple
312 encapsulated interface; in theory there should be no need to touch these
313 globals outside of the async_ka_* functions. */
315 #ifdef THREADED_CLIENT
316 static pthread_t ka_thr_handle;
317 static int ka_thr_active = 0;
318 static int async_ka_enabled = 0;
320 static void *ka_thread(void *arg)
322 really_do_keepalive();
323 pthread_detach(ka_thr_handle);
328 /* start up a thread to handle a keepalive in the background */
329 static void async_ka_exec(void)
331 if (!ka_thr_active) {
333 if (pthread_create(&ka_thr_handle, NULL, ka_thread, NULL)) {
334 perror("pthread_create");
339 #endif /* THREADED_CLIENT */
341 static void do_keepalive(void)
346 if ((now - idlet) < ((long) S_KEEPALIVE))
349 /* Do a space-backspace to keep telnet sessions from idling out */
353 #ifdef THREADED_CLIENT
354 if (async_ka_enabled)
358 really_do_keepalive();
362 /* Now the actual async-keepalve API that we expose to higher levels:
363 async_ka_start() and async_ka_end(). These do nothing when we don't have
364 threading enabled, so we avoid sprinkling ifdef's throughout the code. */
366 /* wait for a background keepalive to complete. this must be done before
367 attempting any further server requests! */
368 void async_ka_end(void)
370 #ifdef THREADED_CLIENT
372 pthread_join(ka_thr_handle, NULL);
378 /* tell do_keepalive() that keepalives are asynchronous. */
379 void async_ka_start(void)
381 #ifdef THREADED_CLIENT
388 { /* get a character from the keyboard, with */
389 int a; /* the watchdog timer in effect if necessary */
392 time_t start_time, now;
401 /* This loop waits for keyboard input. If the keepalive
402 * timer expires, it sends a keepalive to the server if
403 * necessary and then waits again.
410 tv.tv_sec = S_KEEPALIVE;
414 if (((now - start_time) > SLEEPING)
415 && (SLEEPING != 0) && (getppid() == 1)) {
416 printf("Sleeping? Call again.\n");
419 select(1, &rfds, NULL, NULL, &tv);
420 } while (!FD_ISSET(0, &rfds));
425 /* At this point, there's input, so fetch it.
426 * (There's a hole in the bucket...)
436 if (((a != 4) && (a != 13) && (a != 8) && (a != NEXT_KEY) && (a != STOP_KEY))
437 && ((a < 32) || (a > 126)))
445 { /* Returns 1 for yes, 0 for no */
461 /* Returns 1 for yes, 0 for no, arg is default value */
484 /* Gets a line from the terminal */
485 /* string == Pointer to string buffer */
486 /* lim == Maximum length - if negative, no-show */
487 void getline(char *string, int lim)
501 if ((a == 8) && (strlen(string) == 0))
503 if ((a != 13) && (a != 8) && (strlen(string) == lim))
505 if ((a == 8) && (string[0] != 0)) {
506 string[strlen(string) - 1] = 0;
512 if ((a == 13) || (a == 10)) {
532 * strprompt() - prompt for a string, print the existing value and
533 * allow the user to press return to keep it...
535 void strprompt(char *prompt, char *str, int len)
540 printf("%s ", prompt);
543 color(BRIGHT_MAGENTA);
557 * boolprompt() - prompt for a yes/no, print the existing value and
558 * allow the user to press return to keep it...
560 int boolprompt(char *prompt, int prev_val)
565 printf("%s ", prompt);
568 color(BRIGHT_MAGENTA);
569 printf("%s", (prev_val ? "Yes" : "No"));
573 r = (yesno_d(prev_val));
579 * intprompt() - like strprompt(), except for an integer
580 * (note that it RETURNS the new value!)
582 int intprompt(char *prompt, int ival, int imin, int imax)
590 snprintf(buf, sizeof buf, "%d", i);
591 strprompt(prompt, buf, 15);
593 for (p=0; p<strlen(buf); ++p) {
594 if ( (!isdigit(buf[p]))
595 && ( (buf[p]!='-') || (p!=0) ) )
599 printf("*** Must be no less than %d.\n", imin);
601 printf("*** Must be no more than %d.\n", imax);
602 } while ((i < imin) || (i > imax));
607 * newprompt() - prompt for a string with no existing value
608 * (clears out string buffer first)
610 void newprompt(char *prompt, char *str, int len)
612 color(BRIGHT_MAGENTA);
613 printf("%s", prompt);
621 { /* returns a lower case value */
630 * parse the citadel.rc file
632 void load_command_set(void)
637 struct citcmd *lastcmd = NULL;
642 /* first, set up some defaults for non-required variables */
644 strcpy(editor_path, "");
645 strcpy(printcmd, "");
646 strcpy(rc_username, "");
647 strcpy(rc_password, "");
650 rc_allow_attachments = 0;
651 rc_remember_passwords = 0;
652 strcpy(rc_exp_cmd, "");
653 rc_display_message_numbers = 0;
654 rc_force_mail_prompts = 0;
656 strcpy(rc_url_cmd, "");
658 /* now try to open the citadel.rc file */
661 if (getenv("HOME") != NULL) {
662 snprintf(buf, sizeof buf, "%s/.citadelrc", getenv("HOME"));
663 ccfile = fopen(buf, "r");
665 if (ccfile == NULL) {
666 ccfile = fopen("/usr/local/lib/citadel.rc", "r");
668 if (ccfile == NULL) {
669 snprintf(buf, sizeof buf, "%s/citadel.rc", BBSDIR);
670 ccfile = fopen(buf, "r");
672 if (ccfile == NULL) {
673 ccfile = fopen("./citadel.rc", "r");
675 if (ccfile == NULL) {
676 perror("commands: cannot open citadel.rc");
679 while (fgets(buf, 256, ccfile) != NULL) {
680 while ((strlen(buf) > 0) ? (isspace(buf[strlen(buf) - 1])) : 0)
681 buf[strlen(buf) - 1] = 0;
683 if (!strncasecmp(buf, "editor=", 7))
684 strcpy(editor_path, &buf[7]);
686 if (!strncasecmp(buf, "printcmd=", 9))
687 strcpy(printcmd, &buf[9]);
689 if (!strncasecmp(buf, "expcmd=", 7))
690 strcpy(rc_exp_cmd, &buf[7]);
692 if (!strncasecmp(buf, "local_screen_dimensions=", 24))
693 have_xterm = (char) atoi(&buf[24]);
695 if (!strncasecmp(buf, "use_floors=", 11)) {
696 if (!strcasecmp(&buf[11], "yes"))
697 rc_floor_mode = RC_YES;
698 if (!strcasecmp(&buf[11], "no"))
699 rc_floor_mode = RC_NO;
700 if (!strcasecmp(&buf[11], "default"))
701 rc_floor_mode = RC_DEFAULT;
703 if (!strncasecmp(buf, "beep=", 5)) {
704 rc_exp_beep = atoi(&buf[5]);
706 if (!strncasecmp(buf, "allow_attachments=", 18)) {
707 rc_allow_attachments = atoi(&buf[18]);
709 if (!strncasecmp(buf, "remember_passwords=", 19)) {
710 rc_remember_passwords = atoi(&buf[19]);
712 if (!strncasecmp(buf, "display_message_numbers=", 24)) {
713 rc_display_message_numbers = atoi(&buf[24]);
715 if (!strncasecmp(buf, "force_mail_prompts=", 19)) {
716 rc_force_mail_prompts = atoi(&buf[19]);
718 if (!strncasecmp(buf, "ansi_color=", 11)) {
719 if (!strncasecmp(&buf[11], "on", 2))
721 if (!strncasecmp(&buf[11], "auto", 4))
722 rc_ansi_color = 2; /* autodetect */
723 if (!strncasecmp(&buf[11], "user", 4))
724 rc_ansi_color = 3; /* user config */
726 if (!strncasecmp(buf, "username=", 9))
727 strcpy(rc_username, &buf[9]);
729 if (!strncasecmp(buf, "password=", 9))
730 strcpy(rc_password, &buf[9]);
732 if (!strncasecmp(buf, "urlcmd=", 7))
733 strcpy(rc_url_cmd, &buf[7]);
735 if (!strncasecmp(buf, "cmd=", 4)) {
736 strcpy(buf, &buf[4]);
738 cptr = (struct citcmd *) malloc(sizeof(struct citcmd));
740 cptr->c_cmdnum = atoi(buf);
741 for (d = strlen(buf); d >= 0; --d)
744 strcpy(buf, &buf[b + 1]);
746 cptr->c_axlevel = atoi(buf);
747 for (d = strlen(buf); d >= 0; --d)
750 strcpy(buf, &buf[b + 1]);
752 for (a = 0; a < 5; ++a)
753 cptr->c_keys[a][0] = 0;
757 buf[strlen(buf) + 1] = 0;
758 while (strlen(buf) > 0) {
760 for (d = strlen(buf); d >= 0; --d)
763 strncpy(cptr->c_keys[a], buf, b);
764 cptr->c_keys[a][b] = 0;
766 strcpy(buf, &buf[b + 1]);
776 lastcmd->next = cptr;
786 * return the key associated with a command
788 char keycmd(char *cmdstr)
792 for (a = 0; a < strlen(cmdstr); ++a)
793 if (cmdstr[a] == '&')
794 return (tolower(cmdstr[a + 1]));
800 * Output the string from a key command without the ampersand
801 * "mode" should be set to 0 for normal or 1 for <C>ommand key highlighting
803 char *cmd_expand(char *strbuf, int mode)
811 for (a = 0; a < strlen(exp); ++a) {
812 if (strbuf[a] == '&') {
815 strcpy(&exp[a], &exp[a + 1]);
819 strcpy(buf, &exp[a + 2]);
825 if (!strncmp(&exp[a], "^r", 2)) {
827 strcpy(&exp[a], room_name);
828 strcat(exp, &buf[a + 2]);
830 if (!strncmp(&exp[a], "^c", 2)) {
832 strcpy(&exp[a + 1], &exp[a + 2]);
842 * Comparison function to determine if entered commands match a
843 * command loaded from the config file.
845 int cmdmatch(char *cmdbuf, struct citcmd *cptr, int ncomp)
856 for (a = 0; a < ncomp; ++a) {
857 if ((tolower(cmdbuf[a]) != keycmd(cptr->c_keys[a]))
858 || (cptr->c_axlevel > cmdax))
866 * This function returns 1 if a given command requires a string input
868 int requires_string(struct citcmd *cptr, int ncomp)
873 strcpy(buf, cptr->c_keys[ncomp - 1]);
874 for (a = 0; a < strlen(buf); ++a) {
883 * Input a command at the main prompt.
884 * This function returns an integer command number. If the command prompts
885 * for a string then it is placed in the supplied buffer.
887 int getcmd(char *argbuf)
899 * Starting a new command now, so set sigcaught to 0. This variable
900 * is set to nonzero (usually NEXT_KEY or STOP_KEY) if a command has
901 * been interrupted by a keypress.
905 /* Switch color support on or off if we're in user mode */
906 if (rc_ansi_color == 3) {
907 if (userflags & US_COLOR)
912 /* if we're running in idiot mode, display a cute little menu */
913 IFNEXPERT formout("mainmenu");
915 print_express(); /* print express messages if there are any */
918 for (a = 0; a < 5; ++a)
920 /* now the room prompt... */
923 printf("\n%s", room_name);
925 printf("%c ", room_prompt(room_flags));
932 /* Handle the backspace key, but only if there's something
933 * to backspace over...
935 if ((ch == 8) && (cmdpos > 0)) {
936 back(cmdspaces[cmdpos - 1] + 1);
940 /* Spacebar invokes "lazy traversal" commands */
941 if ((ch == 32) && (cmdpos == 0)) {
942 this_lazy_cmd = next_lazy_cmd;
943 if (this_lazy_cmd == 13)
945 if (this_lazy_cmd == 5)
947 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
948 if (cptr->c_cmdnum == this_lazy_cmd) {
949 for (a = 0; a < 5; ++a)
950 if (cptr->c_keys[a][0] != 0)
951 printf("%s ", cmd_expand(
952 cptr->c_keys[a], 0));
954 return (this_lazy_cmd);
958 return (this_lazy_cmd);
960 /* Otherwise, process the command */
961 cmdbuf[cmdpos] = tolower(ch);
963 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
964 if (cmdmatch(cmdbuf, cptr, cmdpos + 1)) {
966 printf("%s", cmd_expand(cptr->c_keys[cmdpos], 0));
967 cmdspaces[cmdpos] = strlen(
968 cmd_expand(cptr->c_keys[cmdpos], 0));
970 if ((cptr->c_keys[cmdpos + 1]) != 0)
976 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
977 if (cmdmatch(cmdbuf, cptr, 5)) {
978 /* We've found our command. */
979 if (requires_string(cptr, cmdpos)) {
985 /* If this command is one that changes rooms,
986 * then the next lazy-command (space bar)
987 * should be "read new" instead of "goto"
989 if ((cptr->c_cmdnum == 5)
990 || (cptr->c_cmdnum == 6)
991 || (cptr->c_cmdnum == 47)
992 || (cptr->c_cmdnum == 52)
993 || (cptr->c_cmdnum == 16)
994 || (cptr->c_cmdnum == 20))
997 return (cptr->c_cmdnum);
1003 printf("\rOne of ... \n");
1004 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
1005 if (cmdmatch(cmdbuf, cptr, cmdpos)) {
1006 for (a = 0; a < 5; ++a) {
1007 printf("%s ", cmd_expand(cptr->c_keys[a], 1));
1013 printf("\n%s%c ", room_name, room_prompt(room_flags));
1015 for (cptr = cmdlist; cptr != NULL; cptr = cptr->next) {
1016 if ((got == 0) && (cmdmatch(cmdbuf, cptr, cmdpos))) {
1017 for (a = 0; a < cmdpos; ++a) {
1019 cmd_expand(cptr->c_keys[a], 0));
1034 * set tty modes. commands are:
1036 * 01- set to bbs mode
1037 * 2 - save current settings for later restoral
1038 * 3 - restore saved settings
1040 #ifdef HAVE_TERMIOS_H
1041 void sttybbs(int cmd)
1042 { /* SysV version of sttybbs() */
1043 struct termios live;
1044 static struct termios saved_settings;
1045 static int last_cmd = 0;
1052 if ((cmd == 0) || (cmd == 1)) {
1053 tcgetattr(0, &live);
1054 live.c_iflag = ISTRIP | IXON | IXANY;
1055 live.c_oflag = OPOST | ONLCR;
1056 live.c_lflag = ISIG | NOFLSH;
1058 live.c_cc[VINTR] = (-1);
1059 live.c_cc[VQUIT] = (-1);
1062 live.c_cc[VMIN] = 0;
1063 live.c_cc[VTIME] = 0;
1066 /* do we even need this stuff anymore? */
1067 /* live.c_line=0; */
1068 live.c_cc[VERASE] = 8;
1069 live.c_cc[VKILL] = 24;
1070 live.c_cc[VEOF] = 1;
1071 live.c_cc[VEOL] = 255;
1072 live.c_cc[VEOL2] = 0;
1073 live.c_cc[VSTART] = 0;
1074 tcsetattr(0, TCSADRAIN, &live);
1077 tcgetattr(0, &saved_settings);
1080 tcsetattr(0, TCSADRAIN, &saved_settings);
1084 void sttybbs(int cmd)
1085 { /* BSD version of sttybbs() */
1087 static struct sgttyb saved_settings;
1089 if ((cmd == 0) || (cmd == 1)) {
1091 live.sg_flags |= CBREAK;
1092 live.sg_flags |= CRMOD;
1093 live.sg_flags |= NL1;
1094 live.sg_flags &= ~ECHO;
1096 live.sg_flags |= NOFLSH;
1100 gtty(0, &saved_settings);
1103 stty(0, &saved_settings);
1110 * display_help() - help file viewer
1112 void display_help(char *name)
1119 * fmout() - Citadel text formatter and paginator
1122 int width, /* screen width to use */
1123 FILE *fp, /* file to read from, or NULL to read from server */
1124 char pagin, /* nonzero if we should use the paginator */
1125 int height, /* screen height to use */
1126 int starting_lp,/* starting value for lines_printed, -1 for global */
1127 char subst) /* nonzero if we should use hypertext mode */
1129 int a, b, c, d, old;
1135 num_urls = 0; /* Start with a clean slate of embedded URL's */
1137 if (starting_lp >= 0) {
1138 lines_printed = starting_lp;
1143 c = 1; /* c is the current pos */
1145 FMTA: while ((eof_flag == 0) && (strlen(buffer) < 126)) {
1146 if (fp != NULL) { /* read from file */
1149 if (eof_flag == 0) {
1151 buffer[strlen(buffer) + 1] = 0;
1152 buffer[strlen(buffer)] = a;
1154 } else { /* read from server */
1156 serv_gets(&buffer[d]);
1157 while ((!isspace(buffer[d])) && (isspace(buffer[strlen(buffer) - 1])))
1158 buffer[strlen(buffer) - 1] = 0;
1159 if (!strcmp(&buffer[d], "000")) {
1162 while (isspace(buffer[strlen(buffer) - 1]))
1163 buffer[strlen(buffer) - 1] = 0;
1171 if ( (!strncasecmp(buffer, "http://", 7))
1172 || (!strncasecmp(buffer, "ftp://", 6)) ) {
1173 safestrncpy(urls[num_urls], buffer, 255);
1174 for (a=0; a<strlen(urls[num_urls]); ++a) {
1175 b = urls[num_urls][a];
1176 if ( (b==' ') || (b==')') || (b=='>') || (b==10)
1177 || (b==13) || (b==9) || (b=='\"') )
1178 urls[num_urls][a] = 0;
1183 buffer[strlen(buffer) + 1] = 0;
1185 strcpy(buffer, &buffer[1]);
1192 if (((a == 13) || (a == 10)) && (old != 13) && (old != 10))
1194 if (((old == 13) || (old == 10)) && (isspace(real))) {
1197 lines_printed = checkpagin(lines_printed, pagin, height);
1204 if (((strlen(aaa) + c) > (width - 5)) && (strlen(aaa) > (width - 5))) {
1205 printf("\n%s", aaa);
1209 lines_printed = checkpagin(lines_printed, pagin, height);
1216 if ((strlen(aaa) + c) > (width - 5)) {
1220 lines_printed = checkpagin(lines_printed, pagin, height);
1224 c = c + strlen(aaa);
1228 if ((a == 13) || (a == 10)) {
1229 printf("%s\n", aaa);
1232 lines_printed = checkpagin(lines_printed, pagin, height);
1233 if (sigcaught) goto OOPS;
1239 /* keypress caught; drain the server */
1242 } while (strcmp(aaa, "000"));
1244 FMTEND: printf("\n");
1246 lines_printed = checkpagin(lines_printed, pagin, height);
1252 * support ANSI color if defined
1254 void color(int colornum)
1256 static int is_bold = 0;
1257 static int hold_color, current_color;
1259 if (colornum == COLOR_PUSH) {
1260 hold_color = current_color;
1264 if (colornum == COLOR_POP) {
1269 current_color = colornum;
1271 /* When switching to dim white, actually output an 'original
1272 * pair' sequence -- this looks better on black-on-white
1275 if (colornum == DIM_WHITE)
1276 printf("\033[39;49m");
1278 printf("\033[3%d;40m", (colornum & 7));
1280 if ((colornum >= 8) && (is_bold == 0)) {
1283 } else if ((colornum < 8) && (is_bold == 1)) {
1291 void cls(int colornum)
1294 printf("\033[4%dm\033[2J\033[H\033[0m", colornum);
1301 * Detect whether ANSI color is available (answerback)
1303 void send_ansi_detect(void)
1305 if (rc_ansi_color == 2) {
1312 void look_for_ansi(void)
1320 if (rc_ansi_color == 0) {
1322 } else if (rc_ansi_color == 1) {
1324 } else if (rc_ansi_color == 2) {
1326 /* otherwise, do the auto-detect */
1331 if ((now - AnsiDetect) < 2)
1340 select(1, &rfds, NULL, NULL, &tv);
1341 if (FD_ISSET(0, &rfds)) {
1342 abuf[strlen(abuf) + 1] = 0;
1343 read(0, &abuf[strlen(abuf)], 1);
1345 } while (FD_ISSET(0, &rfds));
1347 for (a = 0; a < strlen(abuf); ++a) {
1348 if ((abuf[a] == 27) && (abuf[a + 1] == '[')
1349 && (abuf[a + 2] == '?')) {
1358 * Display key options (highlight hotkeys inside angle brackets)
1360 void keyopt(char *buf) {
1364 for (i=0; i<strlen(buf); ++i) {
1366 putc(buf[i], stdout);
1367 color(BRIGHT_MAGENTA);
1372 putc(buf[i], stdout);
1381 * Present a key-menu line choice type of thing
1383 char keymenu(char *menuprompt, char *menustring) {
1389 int display_prompt = 1;
1391 choices = num_tokens(menustring, '|');
1393 if (menuprompt != NULL) do_prompt = 1;
1394 if (menuprompt != NULL) if (strlen(menuprompt)==0) do_prompt = 0;
1397 if (display_prompt) {
1399 printf("%s ", menuprompt);
1402 for (i=0; i<choices; ++i) {
1403 extract(buf, menustring, i);
1413 if ( (do_prompt) && (ch=='?') ) {
1414 printf("\rOne of... ");
1416 for (i=0; i<choices; ++i) {
1417 extract(buf, menustring, i);
1426 for (i=0; i<choices; ++i) {
1427 extract(buf, menustring, i);
1428 for (c=1; c<strlen(buf); ++c) {
1429 if ( (ch == tolower(buf[c]))
1431 && (buf[c+1]=='>') ) {
1432 for (a=0; a<strlen(buf); ++a) {
1433 if ( (a!=(c-1)) && (a!=(c+1))) {
1434 putc(buf[a], stdout);