AnalogTerm2: Support asymmetric on/off blinking parameters.
authorMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 18 Apr 2023 10:22:46 +0000 (10:22 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 18 Apr 2023 10:22:46 +0000 (10:22 +0000)
mmsoftware/analogterm2/TODO.txt
mmsoftware/analogterm2/src/config.c
mmsoftware/analogterm2/src/config.h
mmsoftware/analogterm2/src/draw.c
mmsoftware/analogterm2/src/main.c
mmsoftware/analogterm2/src/state.c

index f7acd43..675c482 100644 (file)
   This would allow applications like neovim using this VT520 feature to
   produce a faster blinking underline and bar cursor and a slower blinking
   block cursor.
-- Maybe also support cursor blinking delays where on != off.  A second
-  parameter could be added to the speed configuration sequence.  This would
-  be useful to have a mostly on cursor that occasionally briefly blinks just
-  to get noticeable.
 - On RPI when omxplayer is launched directly from analogterm2 and bash, it
   does not behave exactly like under xterm or urxvt: keys sent to omxplayer
   may either still be sent to analogterm2 or the terminal may be in another
index fbb3247..cefa40a 100644 (file)
@@ -28,7 +28,8 @@ static const struct eparam_s eparams[] = {
 
 int    cfg_color, cfg_monocolor;
 bool   cfg_mono;
-int    cfg_refreshspeed, cfg_blinkspeed, cfg_cursormode, cfg_flashtime;
+int    cfg_refreshspeed, cfg_blinkspeedon, cfg_blinkspeedoff, cfg_cursormode,
+       cfg_flashtime;
 bool   cfg_cursorblink, cfg_cursordisable, cfg_cursorbright,
        cfg_cursorprintreset;
 int    cfg_intmin, cfg_intstep, cfg_intfg, cfg_intscan, cfg_intbg;
@@ -56,7 +57,8 @@ cfg_setdefaults(void)
        cfg_monocolor = DEFAULT_MONOCOLOR;
        cfg_mono = MONOCHROME;
        cfg_refreshspeed = REFRESH_SPEED;
-       cfg_blinkspeed = BLINK_SPEED;
+       cfg_blinkspeedon = BLINK_SPEED_ON;
+       cfg_blinkspeedoff = BLINK_SPEED_OFF;
        cfg_cursormode = CURSOR_MODE;
        cfg_flashtime = FLASH_TIME;
        cfg_cursorblink = CURSOR_BLINK;
index 507ccab..5b173c8 100644 (file)
@@ -54,11 +54,13 @@ extern int cfg_refreshspeed;
 
 /*
  * The interval timer used to toggle text and cursor blinking, in number of
- * REFRESH_SPEED ticks.
+ * REFRESH_SPEED ticks.  ON and OFF are designed to be able to optionally be
+ * asymmetric.
  */
-#define BLINK_SPEED            15
+#define BLINK_SPEED_ON         40
+#define BLINK_SPEED_OFF                10
 
-extern int cfg_blinkspeed;
+extern int cfg_blinkspeedon, cfg_blinkspeedoff;
 
 /*
  *
index 9b20b50..8360f8f 100644 (file)
@@ -154,12 +154,14 @@ draw_cleanup(void)
 static void
 alarm_sighandler(int sig)
 {
+       int blinkspeed;
 
        if (sig != SIGALRM)
                return;
 
        refresh_expired = true;
-       if (++blink_ticks == cfg_blinkspeed) {
+       blinkspeed = (draw_blink_state ? cfg_blinkspeedoff : cfg_blinkspeedon);
+       if (++blink_ticks == blinkspeed) {
                blink_ticks = 0;
                draw_blink_state = !draw_blink_state;
                state->blink_update = true;
@@ -170,7 +172,9 @@ void
 draw_blink_reset(void)
 {
 
+       draw_blink_state = true;
        blink_ticks = 0;
+       state->blink_update = true;
 }
 
 void
index e7f885c..dad5e36 100644 (file)
@@ -176,10 +176,10 @@ usage(void)
        errno = EINVAL;
        fprintf(stderr,
            "\nUsage: %s [-8|-u] [-w <cols>] [-h <rows>] [-E <n>] [-s]\n"
-           "    [-C <color>] [-c] [-W] [-b] [-r <ms>] [-B <ticks>] [-j <n>]\n"
-           "    [-P] [-m <mode>] [-M] [-d] [-D] [-S] [-p <parameters>]\n"
-           "    [-l <pixels>] [-f <delay>] [-U] [-z <ms>] [-Z <skip>]\n"
-           "    [-e <command> [<arguments>]]\n\n"
+           "    [-C <col>] [-c] [-W] [-b] [-r <ms>] [-B <ticks>[,<ticks>]]\n"
+           "    [-j <n>] [-P] [-m <mode>] [-M] [-d] [-D] [-S]\n"
+           "    [-p <parameters>] [-l <pixels>] [-f <delay>] [-U] [-z <ms>]\n"
+           "    [-Z <skip>] [-e <command> [<arguments>]]\n\n"
            "Where:\n"
            " -8 / -u - 8-bit mode (Latin-1), unicode+UTF-8.  8-bit mode is\n"
            "           automatically enabled by default if the LANG\n"
@@ -203,7 +203,9 @@ usage(void)
            "      DEC Private Mode sequence 4: [?4h and [?4l.\n"
            " -b - Toggle blinking cursor.\n"
            " -B - Set the cursor and text blinking speed, in refresh ticks.\n"
-           "      This can also be changed with ESC [?658467;65538;<n>h\n"
+           "      Two comma-separated values may optionally be provided for\n"
+           "      asymmetric on/off delays.  One value sets both symmetric.\n"
+           "      Can also be changed with ESC [?658467;65538;<n>[;<n>]h\n"
            "      This depends on the refresh rate setting, -r.\n"
            " -j - Maximum number of lines to jump in fast scrolling mode.\n"
            "      Also depends on the -r setting.\n"
@@ -339,8 +341,24 @@ main(int argc, char **argv, char **envp)
                        cfg_cursorblink = !cfg_cursorblink;
                        break;
                case 'B':
-                       if ((i = atoi(optarg)) > 0 && i < 501)
-                               cfg_blinkspeed = i;
+                       {
+                               char *cols[2], *str;
+                               int son = cfg_blinkspeedon,
+                                   soff = cfg_blinkspeedoff;
+
+                               if ((str = strdup(optarg)) == NULL)
+                                       err(EXIT_FAILURE, "stddup()");
+                               if (cfg_strspl(cols, str, 2, ',') == 2) {
+                                       son = atoi(cols[0]);
+                                       soff = atoi(cols[1]);
+                               } else
+                                       son = soff = atoi(optarg);
+                               free(str);
+                               if (son > 0 && son < 501)
+                                       cfg_blinkspeedon = son;
+                               if (soff > 0 && soff < 501)
+                                       cfg_blinkspeedoff = soff;
+                       }
                        break;
                case 'j':
                        if ((i = atoi(optarg)) > 1 && i <= 16)
index 9de5071..2bbb88f 100644 (file)
@@ -1033,16 +1033,21 @@ state_emul_printc(state_t *st, uint8_t c)
                                                            st->cursor_bright
                                                            = false;
                                                }
-                                       } else if (state->curparam == 2 &&
+                                       } else if ((state->curparam == 2 ||
+                                                   state->curparam == 3) &&
                                                   state->csiparam[1] ==
                                                   65538) {
-                                               int s = state->csiparam[2];
+                                               int s1 = state->csiparam[2],
+                                                   s2 = (state->curparam == 3
+                                                         ? state->csiparam[3]
+                                                         : s1);
 
                                                /* Blinking speed */
-                                               if (s > 0 && s < 501) {
-                                                       cfg_blinkspeed = s;
-                                                       draw_blink_reset();
-                                               }
+                                               if (s1 > 0 && s1 < 501)
+                                                       cfg_blinkspeedon = s1;
+                                               if (s2 > 0 && s2 < 501)
+                                                       cfg_blinkspeedoff = s2;
+                                               draw_blink_reset();
                                        } else if (state->curparam == 3 &&
                                                   state->csiparam[1] ==
                                                   65539) {