]> code.citadel.org Git - citadel.git/blobdiff - textclient/commands.c
Fix ansi auto-detect
[citadel.git] / textclient / commands.c
index cf3576d878eb6c3f7b21e051c656dfd20490aee6..dfc3f0601892736373c41d53bf1f57e7d3177c30 100644 (file)
@@ -1,19 +1,11 @@
-// This file contains functions which implement parts of the
-// text-mode user interface.
+// This file contains functions which implement parts of the text-mode user interface.
 //
 //
-// Copyright (c) 1987-2022 by the citadel.org team
+// Copyright (c) 1987-2024 by the citadel.org team
 //
 //
-// This program is open source software.  Use, duplication, and/or
-// disclosure is subject to the GNU General Purpose License version 3.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License version 3.
 
 #include "textclient.h"
 
 
 #include "textclient.h"
 
-
 // The help "files" are now just an embedded set of Very Long Strings.  helpnames[] is
 // an array of "file names" and helptexts[] is the "content".
 
 // The help "files" are now just an embedded set of Very Long Strings.  helpnames[] is
 // an array of "file names" and helptexts[] is the "content".
 
@@ -42,11 +34,14 @@ char *helptexts[] = {
            " G         Goto next room which has UNREAD messages.\n"
            " H         Help. Same as '?'\n"
            " I         Reads the Information file for this room.\n"
            " G         Goto next room which has UNREAD messages.\n"
            " H         Help. Same as '?'\n"
            " I         Reads the Information file for this room.\n"
+           " J         Jump to any named room (same as <.G>oto)\n"
            " K         List of Known rooms.\n"
            " L         Reads the last five messages in the room.\n"
            " K         List of Known rooms.\n"
            " L         Reads the last five messages in the room.\n"
+           " M         Go to your private Mail room\n"
            " N         Reads all new messages in the room.\n"
            " O         Reads all old messages, backwards.\n"
            " P         Page another user (send an instant message)\n"
            " N         Reads all new messages in the room.\n"
            " O         Reads all old messages, backwards.\n"
            " P         Page another user (send an instant message)\n"
+           " Q         Quiet mode on/off (disables receiving instant messages)\n"
            " R         Reads all messages in the room, in reverse order.\n"
            " S         Skips current room without making its messages old.\n"
            " T         Terminate (logout)\n"
            " R         Reads all messages in the room, in reverse order.\n"
            " S         Skips current room without making its messages old.\n"
            " T         Terminate (logout)\n"
@@ -342,9 +337,6 @@ char *helptexts[] = {
            "                                          you can specify a partial match\n"
            "\n"
            " <.> <R>ead <T>extfile formatted          File 'download' commands.\n"
            "                                          you can specify a partial match\n"
            "\n"
            " <.> <R>ead <T>extfile formatted          File 'download' commands.\n"
-           " <.> <R>ead file using <X>modem   \n"
-           " <.> <R>ead file using <Y>modem   \n"
-           " <.> <R>ead file using <Z>modem   \n"
            " <.> <R>ead <F>ile unformatted   \n"
            " <.> <R>ead <D>irectory   \n"
            "\n"
            " <.> <R>ead <F>ile unformatted   \n"
            " <.> <R>ead <D>irectory   \n"
            "\n"
@@ -431,6 +423,7 @@ int rc_display_message_numbers;
 int rc_force_mail_prompts;
 int rc_remember_passwords;
 int rc_ansi_color;
 int rc_force_mail_prompts;
 int rc_remember_passwords;
 int rc_ansi_color;
+int rc_sixel;
 int rc_color_use_bg;
 int rc_prompt_control = 0;
 time_t rc_idle_threshold = (time_t) 900;
 int rc_color_use_bg;
 int rc_prompt_control = 0;
 time_t rc_idle_threshold = (time_t) 900;
@@ -447,10 +440,10 @@ struct citcmd *cmdlist = NULL;
 
 
 // these variables are local to this module
 
 
 // these variables are local to this module
-char keepalives_enabled = KA_YES;      // send NOOPs to server when idle
-int ok_to_interrupt = 0;       // print instant msgs asynchronously
-time_t AnsiDetect;             // when did we send the detect code?
-int enable_color = 0;          // nonzero for ANSI color
+char keepalives_enabled = KA_YES;              // send NOOPs to server when idle
+int ok_to_interrupt = 0;                       // print instant msgs asynchronously
+time_t AnsiDetect;                             // when did we send the detect code?
+int enable_color = 0;                          // nonzero for ANSI color
 
 
 // If an interesting key has been pressed, return its value, otherwise 0
 
 
 // If an interesting key has been pressed, return its value, otherwise 0
@@ -491,7 +484,7 @@ void display_instant_messages(void) {
        char sender[64];
        char node[64];
        char *listing = NULL;
        char sender[64];
        char node[64];
        char *listing = NULL;
-       int r;                  // IPC result code
+       int r;                                  // IPC result code
 
        if (instant_msgs == 0) {
                return;
 
        if (instant_msgs == 0) {
                return;
@@ -753,7 +746,7 @@ int ctdl_getline(char *string, int lim, int noshow, int bs) {
        while (1) {
                ch = inkey();
 
        while (1) {
                ch = inkey();
 
-               if ((ch == 8) && (pos > 0)) {   // backspace
+               if ((ch == 8) && (pos > 0)) {                   // backspace
                        --pos;
                        scr_putc(8);
                        scr_putc(32);
                        --pos;
                        scr_putc(8);
                        scr_putc(32);
@@ -764,7 +757,7 @@ int ctdl_getline(char *string, int lim, int noshow, int bs) {
                        return (-1);
                }
 
                        return (-1);
                }
 
-               else if ((ch == 23) && (pos > 0)) {     // Ctrl-W deletes a word
+               else if ((ch == 23) && (pos > 0)) {             // Ctrl-W deletes a word
                        while ((pos > 0) && !isspace(string[pos])) {
                                --pos;
                                scr_putc(8);
                        while ((pos > 0) && !isspace(string[pos])) {
                                --pos;
                                scr_putc(8);
@@ -785,7 +778,7 @@ int ctdl_getline(char *string, int lim, int noshow, int bs) {
                        return (pos);
                }
 
                        return (pos);
                }
 
-               else if (isprint(ch)) { // payload characters
+               else if (isprint(ch)) {                         // payload characters
                        scr_putc((noshow ? '*' : ch));
                        string[pos] = ch;
                        ++pos;
                        scr_putc((noshow ? '*' : ch));
                        string[pos] = ch;
                        ++pos;
@@ -868,8 +861,9 @@ void newprompt(char *prompt, char *str, int len) {
 int lkey(void) {
        int a;
        a = inkey();
 int lkey(void) {
        int a;
        a = inkey();
-       if (isupper(a))
+       if (isupper(a)) {
                a = tolower(a);
                a = tolower(a);
+       }
        return (a);
 }
 
        return (a);
 }
 
@@ -897,6 +891,7 @@ void load_command_set(void) {
        rc_display_message_numbers = 0;
        rc_force_mail_prompts = 0;
        rc_ansi_color = 0;
        rc_display_message_numbers = 0;
        rc_force_mail_prompts = 0;
        rc_ansi_color = 0;
+       rc_sixel = 0;
        rc_color_use_bg = 0;
        strcpy(rc_url_cmd, "");
        strcpy(rc_open_cmd, "");
        rc_color_use_bg = 0;
        strcpy(rc_url_cmd, "");
        strcpy(rc_open_cmd, "");
@@ -1005,6 +1000,10 @@ void load_command_set(void) {
                        if (!strncasecmp(&buf[12], "on", 2))
                                enable_status_line = 1;
                }
                        if (!strncasecmp(&buf[12], "on", 2))
                                enable_status_line = 1;
                }
+               if (!strncasecmp(buf, "use_sixel=", 10)) {
+                       if (!strncasecmp(&buf[10], "on", 2))
+                               rc_sixel = 1;
+               }
                if (!strncasecmp(buf, "use_background=", 15)) {
                        if (!strncasecmp(&buf[15], "on", 2))
                                rc_color_use_bg = 9;
                if (!strncasecmp(buf, "use_background=", 15)) {
                        if (!strncasecmp(&buf[15], "on", 2))
                                rc_color_use_bg = 9;
@@ -1185,10 +1184,12 @@ int getcmd(CtdlIPC * ipc, char *argbuf) {
 
        // Switch color support on or off if we're in user mode
        if (rc_ansi_color == 3) {
 
        // Switch color support on or off if we're in user mode
        if (rc_ansi_color == 3) {
-               if (userflags & US_COLOR)
+               if (userflags & US_COLOR) {
                        enable_color = 1;
                        enable_color = 1;
-               else
+               }
+               else {
                        enable_color = 0;
                        enable_color = 0;
+               }
        }
 
        // if we're running in idiot mode, display a cute little menu
        }
 
        // if we're running in idiot mode, display a cute little menu
@@ -1278,13 +1279,13 @@ int getcmd(CtdlIPC * ipc, char *argbuf) {
 
                                // If this command is one that changes rooms, then the next lazy-command
                                // (space bar) should be "read new" instead of "goto"
 
                                // If this command is one that changes rooms, then the next lazy-command
                                // (space bar) should be "read new" instead of "goto"
-                               if ((cptr->c_cmdnum == 5)
-                                   || (cptr->c_cmdnum == 6)
-                                   || (cptr->c_cmdnum == 47)
-                                   || (cptr->c_cmdnum == 52)
-                                   || (cptr->c_cmdnum == 16)
-                                   || (cptr->c_cmdnum == 20)
-                                   ) {
+                               if (    (cptr->c_cmdnum == 5)
+                                       || (cptr->c_cmdnum == 6)
+                                       || (cptr->c_cmdnum == 47)
+                                       || (cptr->c_cmdnum == 52)
+                                       || (cptr->c_cmdnum == 16)
+                                       || (cptr->c_cmdnum == 20)
+                               ) {
                                        next_lazy_cmd = 13;
                                }
 
                                        next_lazy_cmd = 13;
                                }
 
@@ -1294,7 +1295,6 @@ int getcmd(CtdlIPC * ipc, char *argbuf) {
                                }
 
                                return (cptr->c_cmdnum);
                                }
 
                                return (cptr->c_cmdnum);
-
                        }
                }
 
                        }
                }
 
@@ -1330,7 +1330,7 @@ int getcmd(CtdlIPC * ipc, char *argbuf) {
 // set tty modes.  commands are:
 // 
 // 01- set to Citadel mode
 // set tty modes.  commands are:
 // 
 // 01- set to Citadel mode
-// 2 - save current settings for later restoral
+// 2 - save current settings for later restore
 // 3 - restore saved settings
 void stty_ctdl(int cmd) {
        struct termios live;
 // 3 - restore saved settings
 void stty_ctdl(int cmd) {
        struct termios live;
@@ -1396,10 +1396,11 @@ void display_help(CtdlIPC * ipc, char *name) {
 
 // fmout() - Citadel text formatter and paginator
 int fmout(int width,           // screen width to use
 
 // fmout() - Citadel text formatter and paginator
 int fmout(int width,           // screen width to use
-         FILE * fpin,          // file to read from, or NULL to format given text
-         char *text,           // text to be formatted (when fpin is NULL
-         FILE * fpout,         // file to write to, or NULL to write to screen
-         int subst) {          // nonzero if we should use hypertext mode
+       FILE * fpin,            // file to read from, or NULL to format given text
+       char *text,             // text to be formatted (when fpin is NULL
+       FILE * fpout,           // file to write to, or NULL to write to screen
+       int subst               // nonzero if we should use hypertext mode
+) {
        char *buffer = NULL;    // The current message
        char *word = NULL;      // What we are about to actually print
        char *e;                // Pointer to position in text
        char *buffer = NULL;    // The current message
        char *word = NULL;      // What we are about to actually print
        char *e;                // Pointer to position in text
@@ -1582,11 +1583,12 @@ void color(int colornum) {
                // terminals. - Changed to ORIGINAL_PAIR as this actually
                // wound up looking horrible on black-on-white terminals, not
                // to mention transparent terminals.
                // terminals. - Changed to ORIGINAL_PAIR as this actually
                // wound up looking horrible on black-on-white terminals, not
                // to mention transparent terminals.
-               if (colornum == ORIGINAL_PAIR)
+               if (colornum == ORIGINAL_PAIR) {
                        printf("\033[0;39;49m");
                        printf("\033[0;39;49m");
-               else
+               }
+               else {
                        printf("\033[%d;3%d;4%dm", (colornum & 8) ? 1 : 0, (colornum & 7), rc_color_use_bg);
                        printf("\033[%d;3%d;4%dm", (colornum & 8) ? 1 : 0, (colornum & 7), rc_color_use_bg);
-
+               }
        }
 }
 
        }
 }
 
@@ -1609,6 +1611,7 @@ void send_ansi_detect(void) {
 }
 
 
 }
 
 
+// Turn ANSI color (etc.) support on, or off, or auto-detect support, depending on the configuration
 void look_for_ansi(void) {
        fd_set rfds;
        struct timeval tv;
 void look_for_ansi(void) {
        fd_set rfds;
        struct timeval tv;
@@ -1616,21 +1619,19 @@ void look_for_ansi(void) {
        time_t now;
        int a, rv;
 
        time_t now;
        int a, rv;
 
-       if (rc_ansi_color == 0) {
+       if (rc_ansi_color == 0) {                       // Configured to never use color
                enable_color = 0;
        }
                enable_color = 0;
        }
-       else if (rc_ansi_color == 1) {
+       else if (rc_ansi_color == 1) {                  // Configured to always use color
                enable_color = 1;
        }
                enable_color = 1;
        }
-       else if (rc_ansi_color == 2) {
-
-               /* otherwise, do the auto-detect */
+       else if (rc_ansi_color == 2) {                  // Configured to auto-detect ANSI color support
 
                strcpy(abuf, "");
 
                strcpy(abuf, "");
-
                time(&now);
                time(&now);
-               if ((now - AnsiDetect) < 2)
+               if ((now - AnsiDetect) < 2) {
                        sleep(1);
                        sleep(1);
+               }
 
                do {
                        FD_ZERO(&rfds);
 
                do {
                        FD_ZERO(&rfds);
@@ -1650,8 +1651,10 @@ void look_for_ansi(void) {
                } while (FD_ISSET(0, &rfds));
 
                for (a = 0; !IsEmptyStr(&abuf[a]); ++a) {
                } while (FD_ISSET(0, &rfds));
 
                for (a = 0; !IsEmptyStr(&abuf[a]); ++a) {
-                       if ((abuf[a] == 27) && (abuf[a + 1] == '[')
-                           && (abuf[a + 2] == '?')) {
+                       if (    (abuf[a] == 27)
+                               && (abuf[a + 1] == '[')
+                               && (abuf[a + 2] == '?')
+                       ) {                                     // ANSI support was detected!
                                enable_color = 1;
                        }
                }
                                enable_color = 1;
                        }
                }