zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Simulating ZLE_RPROMPT_INDENT=0
Date: Wed, 18 Dec 2013 10:43:53 -0800	[thread overview]
Message-ID: <131218104353.ZM23017@torch.brasslantern.com> (raw)
In-Reply-To: <20131218173853.54435025@pwslap01u.europe.root.pri>

On Dec 18,  5:38pm, Peter Stephenson wrote:
} Subject: Re: Simulating ZLE_RPROMPT_INDENT=0
}
} On Wed, 18 Dec 2013 09:26:11 -0800
} Bart Schaefer <schaefer@brasslantern.com> wrote:
} > Is it OK to declare ZLE_RPROMPT_INDENT in params.c or should it go in a
} > Zle/*.c file?
} 
} It doesn't need to be declared at all; it doesn't need to be special.

It does need to be declared if it's going to be "handled like LINES /
COLUMNS" as I mentioned in my previous message on this thread.  There
needs to be a global integer attached to the value so that it doesn't
have to be read with getvalue() on every call to moveto().

} It just needs to be read and the value used if it happens to be set.
} There are plenty of other variables like this.

Yes, but those others aren't referenced for every keystroke typed into
the line editor.

} > In the event that the terminal has no non-destructive move-left sequence,
} > should assigning ZLE_RPROMPT_INDENT=0 print a warning?  Should it also
} > (or instead) ignore the value and revert to 1 in that case?
} 
} Would make more to have another more programmatically useful way of
} testing this if we need to, e.g. with echotc or echoti.

I'm not sure what you mean by this.  Do you mean e.g. to just document
how a shell script would perform the test?

Here's what I had so far which does not include changing moveto() yet.

--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -977,7 +977,7 @@ zrefresh(void)
     int tmpalloced;		/* flag to free tmpline when finished	     */
     int remetafy;		/* flag that zle line is metafied	     */
     int txtchange;		/* attributes set after prompts              */
-    int rprompt_off = 1;	/* Offset of rprompt from right of screen    */
+    int rprompt_off;		/* Offset of rprompt from right of screen    */
     struct rparams rpms;
 #ifdef MULTIBYTE_SUPPORT
     int width;			/* width of wide character		     */
@@ -1579,16 +1579,12 @@ zrefresh(void)
 		!strchr(rpromptbuf, '\t');
 	    if (put_rpmpt)
 	    {
-		struct value vbuf;
-		char *name = "ZLE_RPROMPT_INDENT";
-		if (getvalue(&vbuf, &name, 1)) {
-		    rprompt_off = (int)getintvalue(&vbuf);
-		    /* sanity to avoid horrible things happening */
-		    if (rprompt_off < 0)
-			rprompt_off = 0;
-		}
-		put_rpmpt =
-		    (int)ZR_strlen(nbuf[0]) + rpromptw < winw - rprompt_off;
+	      rprompt_off = rprompt_indent;
+	      /* sanity to avoid horrible things happening */
+	      if (rprompt_off < 0)
+		rprompt_off = 0;
+	      put_rpmpt =
+		(int)ZR_strlen(nbuf[0]) + rpromptw < winw - rprompt_off;
 	    }
 	}
     } else {


--- a/Src/init.c
+++ b/Src/init.c
@@ -999,6 +999,15 @@ setupvals(void)
     setiparam("COLUMNS", zterm_columns);
     setiparam("LINES", zterm_lines);
 #endif
+    {
+	/* handle inherit from environment */
+	struct value vbuf;
+	char *name = "ZLE_RPROMPT_INDENT";
+	if (getvalue(&vbuf, &name, 1) && !(vbuf.flags & PM_UNSET))
+	    rprompt_indent = getintvalue(&vbuf);
+	else
+	    rprompt_indent = 1;
+    }
 
 #ifdef HAVE_GETRLIMIT
     for (i = 0; i != RLIM_NLIMITS; i++) {


--- a/Src/params.c
+++ b/Src/params.c
@@ -97,6 +97,7 @@ zlong lastval,		/* $?           */
      lastpid,		/* $!           */
      zterm_columns,	/* $COLUMNS     */
      zterm_lines,	/* $LINES       */
+     rprompt_indent,	/* $ZLE_RPROMPT_INDENT */
      ppid,		/* $PPID        */
      zsh_subshell;	/* $ZSH_SUBSHELL */
 /**/
@@ -316,8 +317,10 @@ IPDEF4("PPID", &ppid),
 IPDEF4("ZSH_SUBSHELL", &zsh_subshell),
 
 #define IPDEF5(A,B,F) {{NULL,A,PM_INTEGER|PM_SPECIAL},BR((void *)B),GSU(F),10,0,NULL,NULL,NULL,0}
+#define IPDEF5U(A,B,F) {{NULL,A,PM_INTEGER|PM_SPECIAL|PM_UNSET},BR((void *)B),GSU(F),10,0,NULL,NULL,NULL,0}
 IPDEF5("COLUMNS", &zterm_columns, zlevar_gsu),
 IPDEF5("LINES", &zterm_lines, zlevar_gsu),
+IPDEF5U("ZLE_RPROMPT_INDENT", &rprompt_indent, zlevar_gsu),
 IPDEF5("OPTIND", &zoptind, varinteger_gsu),
 IPDEF5("SHLVL", &shlvl, varinteger_gsu),
 IPDEF5("TRY_BLOCK_ERROR", &try_errflag, varinteger_gsu),


  reply	other threads:[~2013-12-18 18:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18  6:43 Bart Schaefer
2013-12-18  9:27 ` Peter Stephenson
2013-12-18 17:26   ` Bart Schaefer
2013-12-18 17:38     ` Peter Stephenson
2013-12-18 18:43       ` Bart Schaefer [this message]
2013-12-18 19:37         ` Peter Stephenson
2013-12-19  7:33           ` Bart Schaefer
2013-12-19  8:04             ` Bart Schaefer
2013-12-19 20:36             ` Peter Stephenson
2013-12-20  7:28               ` IPDEF5U [was Re: Simulating ZLE_RPROMPT_INDENT=0] Bart Schaefer

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=131218104353.ZM23017@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).