fbpad: c-m-l locks the screen
authorAli Gholami Rudi <ali@rudi.ir>
Sun, 4 Nov 2012 15:44:16 +0000 (4 19:14 +0330)
committerAli Gholami Rudi <ali@rudi.ir>
Sun, 4 Nov 2012 15:44:16 +0000 (4 19:14 +0330)
After this command, fbpad freezes until PASS (specified in config.h)
followed by return is entered.  A NULL PASS disables locking.

README
config.h
fbpad.c

diff --git a/README b/README
index 4750d2b..6b84374 100644 (file)
--- a/README
+++ b/README
@@ -20,6 +20,7 @@ m-o           jump to last tag
 m-tab          show next terminal
 m-s            create a text screenshot (SCRSHOT)
 m-y            redraw terminal
+c-m-l          lock the screen; use PASS to unlock
 c-m-q          quit fbpad
 ==============  =======================================
 
index 81a9c01..3e5aae2 100644 (file)
--- a/config.h
+++ b/config.h
@@ -18,6 +18,9 @@ typedef unsigned int fbval_t;
 /* where to write the screen shot */
 #define SCRSHOT                "/tmp/scr"
 
+/* lock command password; NULL disables locking */
+#define PASS           NULL
+
 /* optimized version of fb_val() */
 #define FB_VAL(r, g, b)        fb_val((r), (g), (b))
 
diff --git a/fbpad.c b/fbpad.c
index 7b57dee..4032a28 100644 (file)
--- a/fbpad.c
+++ b/fbpad.c
@@ -37,6 +37,9 @@ static int ctag;              /* current tag */
 static int ltag;               /* the last tag */
 static int exitit;
 static int hidden;
+static int locked;
+static char pass[1024];
+static int passlen;
 
 static int readchar(void)
 {
@@ -138,6 +141,18 @@ static void showtags(void)
 static void directkey(void)
 {
        int c = readchar();
+       if (PASS && locked) {
+               if (c == '\r') {
+                       pass[passlen] = '\0';
+                       if (!strcmp(PASS, pass))
+                               locked = 0;
+                       passlen = 0;
+                       return;
+               }
+               if (isprint(c) && passlen + 1 < sizeof(pass))
+                       pass[passlen++] = c;
+               return;
+       }
        if (c == ESC) {
                switch ((c = readchar())) {
                case 'c':
@@ -171,6 +186,10 @@ static void directkey(void)
                case 'y':
                        term_switch(cterm(), cterm(), 1, 0, 1);
                        return;
+               case CTRLKEY('l'):
+                       locked = 1;
+                       passlen = 0;
+                       return;
                default:
                        if (strchr(tags, c)) {
                                showtag(strchr(tags, c) - tags);