Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: patch to make $TERMINFO special



On Sun, 8 May 2011 13:13:12 -0700
Danek Duvall <duvall@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> I'm sure I'm going about this the wrong way, but at least it seems to
> work ...
> 
> My problem is that I'm using a value of $TERM that's not present in
> the system's terminfo database, so when zsh starts up, its terminal
> handling is pretty confused.
> 
> I'd like to be able to set TERMINFO to the proper path, but in order
> for that to do anything, the terminal needs to be reinitialized.  So
> I've made TERMINFO a special variable that calls init_term() when
> it's set, and it seems to work okay.

I don't see an obvious problem with the basic idea.  What you're
supposed to do is assign a value (including the same value) to TERM
after setting TERMINFO, as documented in the manual, but maybe it could
be more natural.

It means you can't use the variable TERMINFO for other purposes but you
wouldn't want to if you have terminfo.  That's widespread enough I can't
see a good reason for making this dependent on the configuration.

One possible problem is now the TERMINFO variable appears as if it's
always set: you can explicitly unset it but special variables are set by
default.  That's not ideal since you might want to test if it's set to a
useful value.  I think it's safe and sensible to mark it as initially
unset; we do that with "HOME".  This doesn't stop it being imported.

Slightly superstitiously, I'd quite like to keep the TERMINFO code
similar to the TERM code --- though they're not quite the same given
that TERMINFO isn't set by default.

> I'm guessing that the addenv()
> call isn't necessary, but I can't figure out how it ought to work.

What problem is the addenv() call trying to fix?

Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.62
diff -p -u -r1.62 params.yo
--- Doc/Zsh/params.yo	17 Dec 2010 17:10:48 -0000	1.62
+++ Doc/Zsh/params.yo	9 May 2011 11:15:37 -0000
@@ -1273,6 +1273,13 @@ is necessary to make such an assignment 
 definition database or terminal type in order for the new settings to
 take effect.
 )
+vindex(TERMINFO)
+item(tt(TERMINFO) <S>)(
+A reference to a compiled description of the terminal, used by the
+`terminfo' library when the system has it; see manref(terminfo)(5).
+If set, this causes the shell to reinitialise the terminal, making
+the workaround `tt(TERM=$TERM)' unnecessary.
+)
 vindex(TIMEFMT)
 item(tt(TIMEFMT))(
 The format of process time reports with the tt(time) keyword.
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.170
diff -p -u -r1.170 params.c
--- Src/params.c	9 May 2011 09:49:09 -0000	1.170
+++ Src/params.c	9 May 2011 11:15:37 -0000
@@ -86,6 +86,7 @@ mod_export
 char *ifs,		/* $IFS         */
      *postedit,		/* $POSTEDIT    */
      *term,		/* $TERM        */
+     *zsh_terminfo,     /* $TERMINFO    */
      *ttystrname,	/* $TTY         */
      *pwd;		/* $PWD         */
 
@@ -202,6 +203,8 @@ static const struct gsu_scalar home_gsu 
 { homegetfn, homesetfn, stdunsetfn };
 static const struct gsu_scalar term_gsu =
 { termgetfn, termsetfn, stdunsetfn };
+static const struct gsu_scalar terminfo_gsu =
+{ terminfogetfn, terminfosetfn, stdunsetfn };
 static const struct gsu_scalar wordchars_gsu =
 { wordcharsgetfn, wordcharssetfn, stdunsetfn };
 static const struct gsu_scalar ifs_gsu =
@@ -276,6 +279,7 @@ IPDEF2("-", dash_gsu, PM_READONLY),
 IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT),
 IPDEF2("HOME", home_gsu, PM_UNSET),
 IPDEF2("TERM", term_gsu, 0),
+IPDEF2("TERMINFO", terminfo_gsu, PM_UNSET),
 IPDEF2("WORDCHARS", wordchars_gsu, 0),
 IPDEF2("IFS", ifs_gsu, PM_DONTIMPORT),
 IPDEF2("_", underscore_gsu, PM_READONLY),
@@ -4045,6 +4049,18 @@ underscoregetfn(UNUSED(Param pm))
     return u;
 }
 
+/* Function used when we need to reinitialies the terminal */
+
+static void
+term_reinit_from_pm(void)
+{
+    /* If non-interactive, delay setting up term till we need it. */
+    if (unset(INTERACTIVE) || !*term)
+	termflags |= TERM_UNKNOWN;
+    else
+	init_term();
+}
+
 /* Function to get value for special parameter `TERM' */
 
 /**/
@@ -4062,12 +4078,27 @@ termsetfn(UNUSED(Param pm), char *x)
 {
     zsfree(term);
     term = x ? x : ztrdup("");
+    term_reinit_from_pm();
+}
 
-    /* If non-interactive, delay setting up term till we need it. */
-    if (unset(INTERACTIVE) || !*term)
-	termflags |= TERM_UNKNOWN;
-    else 
-	init_term();
+/* Function to get value of special parameter `TERMINFO' */
+
+/**/
+char *
+terminfogetfn(Param pm, char *x)
+{
+    return zsh_terminfo ? zsh_terminfo : dupstring("");
+}
+
+/* Function to set value of special parameter `TERMINFO' */
+
+/**/
+void
+terminfosetfn(Param pm, char *x)
+{
+    zsfree(zsh_terminfo);
+    zsh_terminfo = x;
+    term_reinit_from_pm();
 }
 
 /* Function to get value for special parameter `pipestatus' */
-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author