]> diplodocus.org Git - nmh/commitdiff
Add support for %(hascolor), and a new function for parameterized
authorKen Hornstein <kenh@pobox.com>
Fri, 3 Jan 2014 20:55:10 +0000 (15:55 -0500)
committerKen Hornstein <kenh@pobox.com>
Fri, 3 Jan 2014 20:55:10 +0000 (15:55 -0500)
terminfo capabilities.

h/prototypes.h
sbr/fmt_compile.c
sbr/terminal.c

index adedd6a..26666ea 100644 (file)
@@ -112,13 +112,47 @@ char *getfolder(int);
  *
  * Arguments:
  *
  *
  * Arguments:
  *
- * capability  - The name of a terminfo capability (see terminfo(5)).
+ * capability  - The name of the terminfo capability (see terminfo(5)).
  *
  * Returns a tputs-processed string, or NULL if terminal initialization failed
  * or the capability wasn't found.
  */
 char *get_term_stringcap(char *capability);
 
  *
  * Returns a tputs-processed string, or NULL if terminal initialization failed
  * or the capability wasn't found.
  */
 char *get_term_stringcap(char *capability);
 
+/*
+ * Get a parameterized string from the terminfo database for the current
+ * terminal.
+ *
+ * We don't yet have a standardized tparm() that will take a stdarg
+ * argument.  Right now we don't want many parameters, so we only
+ * take two.  Everything gets passed to tparm() as-is.  If we need
+ * a capability with more arguments, we'll just add more later.
+ *
+ * Arguments:
+ *
+ * capability  - The name of the terminfo capability (see terminfo(5)).
+ * arg1..argN  - Arguments 1-N.
+ *
+ * Returns a tparm and tputs-processed string, or NULL if there was a problem
+ * initializating the terminal or retrieving the capability.
+ */
+char *get_term_stringparm(char *capability, long arg1, long arg2);
+
+/*
+ * Get a number from the terminfo database for the current terminal.
+ *
+ * Retrieve the specified terminfo capability and return the numeric
+ * value of that capability from the terminfo database.
+ *
+ * Arguments:
+ *
+ * capability  - The name of the terminfo capability (see terminfo(5)).
+ *
+ * Returns the output of tigetnum() for that capability, or -1 if it was
+ * unable to initialize the terminfo database.
+ */
+int get_term_numcap(char *capability);
+
 /*
  * Lock open/close routines.
  *
 /*
  * Lock open/close routines.
  *
index 7392c8c..2e1a0ff 100644 (file)
@@ -86,6 +86,7 @@ extern struct mailname fmt_mnull;
 #define TF_UNDERLN 13       /* special - enter underline mode     */
 #define TF_STNDOUT 14       /* special - enter underline mode     */
 #define TF_RESET   15       /* special - reset terminal modes     */
 #define TF_UNDERLN 13       /* special - enter underline mode     */
 #define TF_STNDOUT 14       /* special - enter underline mode     */
 #define TF_RESET   15       /* special - reset terminal modes     */
+#define TF_HASCLR  16       /* special - terminal have color?     */
 
 /* ftable->flags */
 /* NB that TFL_PUTS is also used to decide whether the test
 
 /* ftable->flags */
 /* NB that TFL_PUTS is also used to decide whether the test
@@ -223,6 +224,7 @@ static struct ftable functable[] = {
      { "underline",  TF_UNDERLN,FT_LS_LIT,     0,              TFL_PUTS },
      { "standout",   TF_STNDOUT,FT_LS_LIT,     0,              TFL_PUTS },
      { "resetterm",  TF_RESET, FT_LS_LIT,      0,              TFL_PUTS },
      { "underline",  TF_UNDERLN,FT_LS_LIT,     0,              TFL_PUTS },
      { "standout",   TF_STNDOUT,FT_LS_LIT,     0,              TFL_PUTS },
      { "resetterm",  TF_RESET, FT_LS_LIT,      0,              TFL_PUTS },
+     { "hascolor",   TF_HASCLR, FT_LV_LIT,     0,              0 },
 
      { NULL,         0,                0,              0,              0 }
 };
 
      { NULL,         0,                0,              0,              0 }
 };
@@ -656,6 +658,10 @@ do_func(char *sp)
        LS(t->f_type, get_term_stringcap("sgr0"));
        break;
 
        LS(t->f_type, get_term_stringcap("sgr0"));
        break;
 
+    case TF_HASCLR:
+       LV(t->f_type, get_term_numcap("colors") > 1);
+       break;
+
     case TF_NOW:
        LV(t->f_type, time((time_t *) 0));
        break;
     case TF_NOW:
        LV(t->f_type, time((time_t *) 0));
        break;
index fe7619b..89d0daf 100644 (file)
@@ -180,6 +180,52 @@ get_term_stringcap(char *capability)
     return termcbuf;
 }
 
     return termcbuf;
 }
 
+/*
+ * Return a parameterized terminfo capability
+ */
+
+char *
+get_term_stringparm(char *capability, long arg1, long arg2)
+{
+    char *parm;
+
+    initialize_terminfo();
+
+    if (termstatus == -1)
+       return NULL;
+
+    termcbufp = termcbuf;
+
+    parm = tigetstr(capability);
+
+    if (parm == (char *) -1 || parm == NULL) {
+       return NULL;
+    }
+
+    parm = tparm(parm, arg1, arg2, 0, 0, 0, 0, 0, 0, 0);
+
+    tputs(parm, 1, termbytes);
+
+    termcbufp = '\0';
+
+    return termcbuf;
+}
+
+/*
+ * Return the value of the specified numeric capability
+ */
+
+int
+get_term_numcap(char *capability)
+{
+    initialize_terminfo();
+
+    if (termstatus == -1)
+       return -1;
+
+    return tigetnum(capability);
+}
+
 /*
  * Store a sequence of characters in our local buffer
  */
 /*
  * Store a sequence of characters in our local buffer
  */