less: interpret backspace.
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 31 Dec 2006 19:23:31 +0000 (19:23 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 31 Dec 2006 19:23:31 +0000 (19:23 -0000)
less is officially declared PAGER-capable! ;)
(this includes viewing of manpages)

miscutils/less.c

index 916213082c905bb2ec9a608ed5ff916e2f4245ae..ae936c2fbd738448d213f5c5318176c93c9828d3 100644 (file)
@@ -212,11 +212,21 @@ static void read_lines(void)
                                }
                        }
                        c = readbuf[readpos];
+                       /* backspace? [need this for manpage display] */
+                       if (c == '\x8' && linepos) {
+                               readpos++; /* eat it */
+                               /* We do not consider the case of <tab><bs> */
+                               /* Anyone who has that is pure evil :) */
+                               linepos--;
+                               *p-- = '\0';
+                               continue;
+                       }
                        if (c == '\t')
                                linepos += (linepos^7) & 7;
                        linepos++;
                        if (linepos >= w)
                                break;
+                       /* ok, we will eat this char */
                        readpos++;
                        if (c == '\n') { terminated = 1; break; }
                        /* NUL is substituted by '\n'! */
@@ -1175,6 +1185,9 @@ int less_main(int argc, char **argv)
 {
        int keypress;
 
+       /* TODO: -x: do not interpret backspace, -xx: tab also */
+       /* -xxx: newline also */
+       /* -w N: assume width N (-xxx -w 32: hex viewer of sorts) */
        getopt32(argc, argv, "EMmN~");
        argc -= optind;
        argv += optind;