zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-workers@zsh.org>
Subject: Re: patch to make $TERMINFO special
Date: Mon, 9 May 2011 12:16:53 +0100	[thread overview]
Message-ID: <20110509121653.793dcd62@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20110508201312.GA5170@lorien.comfychair.org>

On Sun, 8 May 2011 13:13:12 -0700
Danek Duvall <duvall@la-z-boy.comfychair.org> 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@csr.com>            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


  reply	other threads:[~2011-05-09 11:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-08 20:13 Danek Duvall
2011-05-09 11:16 ` Peter Stephenson [this message]
2011-05-09 15:51   ` Danek Duvall
2011-05-09 16:20     ` Peter Stephenson
2011-05-09 16:23       ` Danek Duvall
2011-05-09 17:02         ` Peter Stephenson
2011-05-09 17:16           ` Danek Duvall
2011-05-10 15:42             ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110509121653.793dcd62@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).