AnalogTerm now sets ERASE to ^H and disables DEL/BS swapping by default.
authorMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 11 Apr 2022 07:58:16 +0000 (07:58 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 11 Apr 2022 07:58:16 +0000 (07:58 +0000)
TODO updated and cleaned up.

MATT/TODO.txt
hacks/analogterm-main.c
utils/textclient.c

index 89f68f7..ab4d446 100644 (file)
@@ -1,8 +1,14 @@
+
 BUILD
+=====
+
 - ./configure
 - make
 
+
 TODO
+====
+
 - Maybe cleanup code checking boundaries, using max or other similar
   macros or inline functions.
 - When blinking and double-underline, the line doesn't blink.
@@ -65,30 +71,6 @@ TODO
   yet but that it gracefully degrades to ASCII when French UTF-8 text
   is displayed, at least for accents.  More complete support would
   be nice.  Could use UCS-16 or UCS-32 internally.
-- BACKSPACE is sent as ^H and unlike for various keys like DELETE
-  there is no ANSI control code.  In top, the pid entry line editor,
-  backspace doesn't work in analogterm but does in xterm.  Determine
-  why.  Under xterm, stty reports two extra lines, one related to
-  EOL2 and another one related to ^H so both could be related,
-  termios(4) mentions ERASE.  Also, wordgrinder expected a BACKSPACE
-  event but received ^H, so the corresponding action needed to be
-  rebound, otherwise it would report no binding for ^H.
-  Also interesting, when in cat, under analogterm I get ^H for
-  backspace, when it just works under xterm.
-  stty -a shows even more info, including erase that is not bound
-  to the same, ^? vs ^H.
-  Update:
-  Interestingly, if starting analogterm with -bs and then using
-  stty erase ^H (default is otherwise ^?), backspace suddenly works
-  under cat and top (but not under gnu top remotely).
-  And the urxvt man page is interesting:
-  Apparently sending the Delete terminal key sequence for the
-  backspace key is common, along with sending the "execute" terminal
-  code for the actual Delete key.
-  And according to xterm man page, if backarrowKeyIsErase resource
-  is on (on by default), it queries stty in order to determine what
-  to send.
-  Confirmed that the behavior is the same on Linux, needing -bs
 - [>0c   Secondary DA request     (distinguishes VT240 from VT220)
   Seems to not be supported by the current state system for >
   https://www.real-world-systems.com/docs/ANSIcode.html
@@ -173,6 +155,8 @@ TODO
 
 
 CONTROLS
+========
+
 From the xanalogtv man page:
        Notable X resources supported include the following which correspond to
        standard TV controls: analogTVTint, analogTVColor, analogTVBrightness,
@@ -182,7 +166,10 @@ Although this doesn't seem to be completely true, I can increase
 brightness way beyond 100 were it also increases thickness in
 analogterminal.
 
-NTSC related
+
+NTSC
+====
+
 https://web.archive.org/web/20050105095004/http://www.ee.washington.edu/conselec/CE/kuhn/ntsc/95x4.htm
 https://web.archive.org/web/20050204191229fw_/http://www.ntsc-tv.com/ntsc-main-02.htm
 https://en.wikipedia.org/wiki/NTSC#cite_note-11
@@ -199,7 +186,10 @@ the TG-1, thereby disabling the TG-1's own 31500 Hz reference
 oscillator."
 https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Ntsc_channel.svg/800px-Ntsc_channel.svg.png
 
+
 FONT
+====
+
 https://retrocomputing.stackexchange.com/questions/17312/did-any-european-computers-use-10-line-fonts
 "The Videx Videoterm 80 column card for the Apple II (very different
 from the 80 column display on the Apple //e) used an 6845 that had
@@ -215,8 +205,9 @@ was not shared by everyone ... though you could have burned your
 own EEPROM to get such a font."
 
 
-
 VIM
+===
+
 Vim can be told to not use color with :set t_Co=0 in which case it falls back
 to attributes like bold/underline/inverse.  However, some functionality is
 lost.  Unless t_Co=8 or over,  :hi MatchParen cterm=underline  for instance
@@ -224,17 +215,54 @@ still doesn't work.  This means that for ideal vim support, a colorscheme
 designed for monochrome helps.
 
 
+STTY AND BS/DEL (BACKSPACE AND DELETE KEYS)
+===========================================
+
+stty -a  can show the current settings.
+stty erase ^H  may be used to explicitly set ERASE to BackSpace/bs.
+Among other things, xterm(1), like tset(1), define the ERASE and EOL2 keys
+using the current termcap/terminfo map (TERM=xterm in our case).
+
+Analogterm also sets those but explicitly to ^@ and ^H, respectively.
+It is possible that for some users ERASE should be ^? (del).
+By default, analogterm does not swap the BackSpace and Delete keys.
+It can be instructed to do so using the command line switch -del.
+
+A common symptom of wrong settings is a non-working BackSpace key.  Sometimes
+it may generally work but not in all situations, like when in top(1)'s line
+editor, or under cat(1).  Some applications may then also complain of an
+unbound ^H key, expecting another code like ^?.
+
+Additional related notes removed from TODO:
+  And the urxvt man page is interesting:
+  Apparently sending the Delete terminal key sequence for the
+  backspace key is common, along with sending the "execute" terminal
+  code for the actual Delete key.
+  And according to xterm man page, if backarrowKeyIsErase resource
+  is on (on by default), it queries stty in order to determine what
+  to send.
+
+
+THREADS AND SMP
+===============
+
+On some systems you may want to try -no-threads.  The analogtv emulation uses
+SMP, but modern computers are so fast that disabling this may actually reduce
+CPU usage, avoiding unnecessary high-frequency synchronization.
+
+
 USAGE EXAMPLES
+==============
+
+The default window size is 800x600.  I commonly use 1364x1024.
+912x720 is approximately 12" 5/4 old display on a modern 24" monitor.
+
+Various examples:
 
 hacks/analogterm -fast -geometry 1024x768 -program /bin/sh -tv-brightness 3 -tv-contrast 100
 hacks/analogterm -fast -geometry 1024x768 -program /bin/sh -tv-brightness 0 -tv-contrast 70
 hacks/analogterm -fast -geometry 1364x1024 -program /bin/sh -tv-color 10
+hacks/analogterm -fast -geometry 1364x1024 -program /bin/sh -tv-color 0 -tv-brightness 2 -tv-contrast 140 -del
 
-912x720 is approx 12" 5/4 old display on a modern 24" monitor.
-
-hacks/analogterm -fast -geometry 1364x1024 -program /bin/sh -tv-color 0
-hacks/analogterm -fast -geometry 1364x1024 -program /bin/sh -tv-color 0 -tv-brightness 2 -tv-contrast 140
-hacks/analogterm -fast -geometry 1364x1024 -program /bin/sh -tv-color 0 -tv-brightness 2 -tv-contrast 140 -del -bs
-
-hacks/analogterm -geometry 1364x1024 -bs
-stty erase ^H   then often useful to set ERASE properly (to fix).
+Most used command by the author:
+hacks/analogterm -geometry 1364x1024 -no-threads
index 50bafe2..71372b4 100644 (file)
@@ -57,7 +57,7 @@ static const char *analogterm_defaults [] = {
   "*duration:             60",
   "*program:              xscreensaver-text --cols 80",
   "*metaSendsESC:         True",
-  "*swapBSDEL:            True",
+  "*swapBSDEL:            False",
   "*fast:                 True",
 # ifdef HAVE_FORKPTY
   "*usePty:                True",
index cce25c8..b581b62 100644 (file)
@@ -181,8 +181,27 @@ launch_text_generator (text_data *d)
           /* This is the child fork. */
           char *av[10];
           int i = 0;
+         struct termios tios;
          if (putenv ("TERM=xterm"))
             abort();
+
+         /*
+          * XXX Set client-side tty settings
+          * - tset(1) and xterm(1) can set the ERASE character to the
+          *   termcap/terminfo entry in use.  Since we simulate a subset of
+          *   xterm, and that the terminfo definition uses ^H for it, we
+          *   simply set it to that for now.  Like xterm(1) does, we also set
+          *   VEOL2.
+          */
+         if (tcgetattr(STDIN_FILENO, &tios) != -1) {
+                 tios.c_lflag |= ICANON;
+                 tios.c_cc[VERASE] = CTRL('h');
+                 tios.c_cc[VEOL2] = CTRL('@');
+                 if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios) == -1)
+                         abort();
+         }
+
+         /* Start shell */
           av[i++] = "/bin/sh";
           av[i++] = "-c";
           av[i++] = cmd;
@@ -206,8 +225,6 @@ launch_text_generator (text_data *d)
           *   causes a freeze where ctrl-q cannot resume.  With IXON this
           *   gets ignored.  Ideally we'd want user-controlled xon/xoff to
           *   work properly.
-          *   It may also be possible to set ERASE here to match BS/DEL
-          *   settings.
           */
          if (tcgetattr(fd, &tios) != -1) {
                  tios.c_iflag &= ~(BRKINT | INPCK | ISTRIP | IXON);
@@ -600,6 +617,7 @@ textclient_putc (text_data *d, XKeyEvent *k)
   KeySym keysym;
   unsigned char c = 0;
   const char *send = NULL;
+  bool swapped = false;
 
   XLookupString (k, (char *) &c, 1, &keysym, &d->compose);
 
@@ -629,11 +647,26 @@ textclient_putc (text_data *d, XKeyEvent *k)
    * software like more/less.  Thus it may not be worth it to use terminfo for
    * now, or to use vt100 traditional codes.
    */
+       /* Swap BS/DEL if necessary */
+        if (d->swap_bs_del_p) {
+               if (keysym == XK_Delete) {
+                       keysym = XK_BackSpace;
+                       swapped = true;
+               }
+               else if (keysym == XK_BackSpace) {
+                       keysym = XK_Delete;
+                       swapped = true;
+               }
+       }
+
         switch (keysym) {
        case XK_Insert:
                send = kv(k->state,
                    "\033[@", "\033[2;2~", "\033[2;5~", "\033[2;6~");
                break;
+       case XK_BackSpace:
+               send = "\010"; /* "\b" */
+               break;
        case XK_Delete:
                send = kv(k->state,
                    "\033[3~", "\033[3;2~", "\033[3;5~", "\033[3;6~");
@@ -835,8 +868,8 @@ send:
 
   if (c != 0 && d->pipe)
     {
-      /* XXX May need to swap above in X11 key handling */
-      if (!d->swap_bs_del_p) ;
+      /* Swap DEL/BS if necessary, avoid if already swapped above. */
+      if (!d->swap_bs_del_p || swapped) ;
       else if (c == 127) c = 8;
       else if (c == 8)   c = 127;