zsh-workers
 help / color / mirror / code / Atom feed
* Very wierd output problems
@ 2005-07-11 14:47 Ulf Magnusson
  2005-07-11 15:14 ` Travis Spencer
  0 siblings, 1 reply; 9+ messages in thread
From: Ulf Magnusson @ 2005-07-11 14:47 UTC (permalink / raw)
  To: zsh-workers

For some reason, output from programs that use printf no longer shows
up when they are run from ZSH. For example, the following C program
produces no output when run from ZSH:

#include <stdio.h>

int main() {
    printf("foo");
}

The ZSH builtin printf (that presumably uses the libc printf) doesn't
produce any output anymore either. The following is totally silent:

$ builtin printf Test%dTest 1000

Output via the function puts still shows up as it should.

All programs run as they should when invoked from Bash. I've tried
restarting ZSH and even the system, but the problem won't go away.
This is with ZSH 4.2.5, running on FreeBSD 5.4.

Ulf


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Very wierd output problems
  2005-07-11 14:47 Very wierd output problems Ulf Magnusson
@ 2005-07-11 15:14 ` Travis Spencer
  2005-07-11 17:40   ` Wayne Davison
  0 siblings, 1 reply; 9+ messages in thread
From: Travis Spencer @ 2005-07-11 15:14 UTC (permalink / raw)
  To: Ulf Magnusson; +Cc: zsh-workers

On Mon, Jul 11, 2005 at 04:47:02PM +0200, Ulf Magnusson wrote:
> For some reason, output from programs that use printf no longer shows
> up when they are run from ZSH.  For example, the following C program
> produces no output when run from ZSH:
> 
> #include <stdio.h>
> 
> int main() {
>     printf("foo");
> }
> 

What about '\n'?  Try this:

setopt NO_PROMPTCR

HTH.

-- 

Regards,

Travis Spencer


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Very wierd output problems
  2005-07-11 15:14 ` Travis Spencer
@ 2005-07-11 17:40   ` Wayne Davison
  2005-07-12  3:20     ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Wayne Davison @ 2005-07-11 17:40 UTC (permalink / raw)
  To: zsh-workers

On Mon, Jul 11, 2005 at 08:14:54AM -0700, Travis Spencer wrote:
> Try this:
> 
> setopt NO_PROMPTCR

Since that suggestion causes screen-update problems when editing after a
line of partial output, I think it is better to point people at the zsh
FAQ (http://zsh.sunsite.dk/FAQ/zshfaq03.html#l40) where they will be
introduced to a much better solution:

function precmd {
    echo -n ${(l:$COLUMNS:::):-}
}

The only downside of that is that some X terminals include the trailing
white-space when line-selecting something that was output without a
newline.

I think we should take this solution and turn it into a zsh option that
is enabled by default for interactive sessions.  Perhaps name it
PRE_PROMPT_SPACES.  Can anyone see a problem with that?  The option will
not succeed at making partial output visible when the terminal does not
allow line-wrapping, so perhaps the code would notice if the current
terminal was not going to benefit from the heuristic and skip outputting
the spaces in such circumstances.

..wayne..


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Very wierd output problems
  2005-07-11 17:40   ` Wayne Davison
@ 2005-07-12  3:20     ` Bart Schaefer
  2005-07-12  5:35       ` [PATCH] adding a new option: PROMPT_NUDGE Wayne Davison
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2005-07-12  3:20 UTC (permalink / raw)
  To: zsh-workers

On Jul 11, 10:40am, Wayne Davison wrote:
}
} I think we should take this solution and turn it into a zsh option that
} is enabled by default for interactive sessions.  Perhaps name it
} PRE_PROMPT_SPACES.  Can anyone see a problem with that?

Given that promptcr is a ZLE-specific option already, and ZLE generally
has to know how wide the terminal is, I'd say this seems reasonable --
but it's going to cause strange behavior for anyone who already has made
the FAQ-suggested alteration to precmd.

As for the name:  It's not PRE_PROMPT_CR, so I don't think the PRE_ is
needed.  I'm agnostic on whether _SPACES is the best suffix.

Also, it should perhaps be mutually exclusive with SINGLE_LINE_ZLE.  I'm
not convinced of that, but ...


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] adding a new option: PROMPT_NUDGE
  2005-07-12  3:20     ` Bart Schaefer
@ 2005-07-12  5:35       ` Wayne Davison
  2005-07-12 14:19         ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Wayne Davison @ 2005-07-12  5:35 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1700 bytes --]

On Tue, Jul 12, 2005 at 03:20:50AM +0000, Bart Schaefer wrote:
> it's going to cause strange behavior for anyone who already has made
> the FAQ-suggested alteration to precmd.

Yeah, but that should be a minor problem that is offset by more people
getting what they expect out of the shell by default.  I think that the
worst-case problem will be someone who needs to use the same .zshrc file
with both an older and newer zsh, but I think an easy solution for that
is to have the user tweak their .zshrc to force the new option off
(silently, in case the option isn't around) and to continue to use the
current precmd heuristic for both the old and new shells.

> I'm agnostic on whether _SPACES is the best suffix.

I'm currently thinking that the SPACES part is overly tied to the
implementation rather than what it's trying to accomplish.  How about
PROMPT_NUDGE?  That at least hints at its purpose.

> Also, it should perhaps be mutually exclusive with SINGLE_LINE_ZLE.

Perhaps, but for now I've created a trial implementation that depends on
PROMPT_CR being set (since its output would look crazy without the CR,
and anyone who has gone to the trouble to disable PROMPT_CR doesn't want
things to suddenly look wacko).  It might be better to auto-disable the
PROMPT_NUDGE option if PROMPT_CR is unset, and auto-enable PROMPT_CR if
PROMPT_NUDGE is set, but for now my code takes the easy way out and just
ignores PROMPT_NUDGE if PROMPT_CR is not set.

Attached is a patch of my first implementation.  It pays attention to
the presence of the "xn" termcap attribute to know if it should output
a full column-width of spaces (for xn terminals) or one space less (for
non-xn terminals).

..wayne..

[-- Attachment #2: nudge.patch --]
[-- Type: text/plain, Size: 2833 bytes --]

--- Doc/Zsh/options.yo	18 Mar 2005 22:40:17 -0000	1.37
+++ Doc/Zsh/options.yo	12 Jul 2005 05:26:34 -0000
@@ -906,6 +906,15 @@ Print a carriage return just before prin
 a prompt in the line editor.  This is on by default as multi-line editing
 is only possible if the editor knows where the start of the line appears.
 )
+pindex(PROMPT_NUDGE)
+cindex(prompt, nudge after partial line)
+item(tt(PROMPT_NUDGE) (tt(PLUS()V)) <D>)(
+Attempt to preserve any partially-output line (i.e. output that did not end
+with a newline) by outputting a series of spaces prior to the carriage return
+that is output by PROMPT_CR.  This only works if your terminal has automatic
+margins.  Also, if the PROMPT_CR option is not set, enabling this option will
+have no effect.  This option is on by default.
+)
 pindex(PROMPT_PERCENT)
 cindex(prompt, % expansion)
 item(tt(PROMPT_PERCENT) <C> <Z>)(
--- Src/init.c	13 Jun 2005 14:59:37 -0000	1.53
+++ Src/init.c	12 Jul 2005 05:26:34 -0000
@@ -77,7 +77,7 @@ mod_export int tclen[TC_COUNT];
 /**/
 int tclines, tccolumns;
 /**/
-mod_export int hasam;
+mod_export int hasam, hasxn;
 
 /* Pointer to read-key function from zle */
 
@@ -573,6 +573,7 @@ init_term(void)
 
 	/* check whether terminal has automargin (wraparound) capability */
 	hasam = tgetflag("am");
+	hasxn = tgetflag("xn"); /* also check for newline wraparound glitch */
 
 	tclines = tgetnum("li");
 	tccolumns = tgetnum("co");
--- Src/options.c	18 Mar 2005 22:40:26 -0000	1.22
+++ Src/options.c	12 Jul 2005 05:26:34 -0000
@@ -180,6 +180,7 @@ static struct optname optns[] = {
 {NULL, "privileged",	      OPT_SPECIAL,		 PRIVILEGED},
 {NULL, "promptbang",	      OPT_KSH,			 PROMPTBANG},
 {NULL, "promptcr",	      OPT_ALL,			 PROMPTCR},
+{NULL, "promptnudge",	      OPT_ALL,			 PROMPTNUDGE},
 {NULL, "promptpercent",	      OPT_NONBOURNE,		 PROMPTPERCENT},
 {NULL, "promptsubst",	      OPT_KSH,			 PROMPTSUBST},
 {NULL, "pushdignoredups",     OPT_EMULATE,		 PUSHDIGNOREDUPS},
--- Src/zsh.h	1 Jun 2005 10:45:42 -0000	1.74
+++ Src/zsh.h	12 Jul 2005 05:26:34 -0000
@@ -1593,6 +1593,7 @@ enum {
     PRIVILEGED,
     PROMPTBANG,
     PROMPTCR,
+    PROMPTNUDGE,
     PROMPTPERCENT,
     PROMPTSUBST,
     PUSHDIGNOREDUPS,
--- Src/Zle/zle_main.c	8 Apr 2005 16:58:21 -0000	1.68
+++ Src/Zle/zle_main.c	12 Jul 2005 05:26:35 -0000
@@ -962,8 +962,14 @@ zleread(char **lp, char **rp, int flags,
 	}
     }
     initundo();
-    if (isset(PROMPTCR))
+    if (isset(PROMPTCR)) {
+	/* The PROMPT_NUDGE heuristic will nudge the prompt down to a new line
+	 * if there was any dangling output on the line (assuming the terminal
+	 * has automatic margins, but we try even if hasam isn't set). */
+	if (isset(PROMPTNUDGE))
+	    fprintf(shout, "%*s", (int)columns - !hasxn, "");
 	putc('\r', shout);
+    }
     if (tmout)
 	alarm(tmout);
     zleactive = 1;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] adding a new option: PROMPT_NUDGE
  2005-07-12  5:35       ` [PATCH] adding a new option: PROMPT_NUDGE Wayne Davison
@ 2005-07-12 14:19         ` Bart Schaefer
  2005-07-12 18:48           ` Wayne Davison
  2005-07-12 20:46           ` J
  0 siblings, 2 replies; 9+ messages in thread
From: Bart Schaefer @ 2005-07-12 14:19 UTC (permalink / raw)
  To: zsh-workers

On Jul 11, 10:35pm, Wayne Davison wrote:
}
} I'm currently thinking that the SPACES part is overly tied to the
} implementation rather than what it's trying to accomplish.  How about
} PROMPT_NUDGE?  That at least hints at its purpose.

I'd like some opinions from people whose first language is not English.
 
} > Also, it should perhaps be mutually exclusive with SINGLE_LINE_ZLE.
} 
} Perhaps, but for now I've created a trial implementation that depends on
} PROMPT_CR being set (since its output would look crazy without the CR

I'd assumed that would be the case ...

} Attached is a patch of my first implementation.  It pays attention to
} the presence of the "xn" termcap attribute

Is that to avoid wrapping in the event that the cursor starts out in
column zero?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] adding a new option: PROMPT_NUDGE
  2005-07-12 14:19         ` Bart Schaefer
@ 2005-07-12 18:48           ` Wayne Davison
  2005-07-12 19:16             ` Wayne Davison
  2005-07-12 20:46           ` J
  1 sibling, 1 reply; 9+ messages in thread
From: Wayne Davison @ 2005-07-12 18:48 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Tue, Jul 12, 2005 at 02:19:21PM +0000, Bart Schaefer wrote:
> I'd like some opinions from people whose first language is not English.

I'm certainly open to suggestions.  Other possibilities that occurred to
me include PROMPT_REPOSITION, PROMPT_PRESERVE, PROMPT_PRESERVE_PARTIAL,
and the simple (yet cryptic) PROMPT_SP (where SP can stand for either
"spaces" or "save partial").
 
> Is that [xn logic] to avoid wrapping in the event that the cursor
> starts out in column zero?

Yes.  Most terminals prior to the vt100 wrapped anytime $COLUMNS chars
appeared on a single line (as long as the terminal had line-wrapping
enabled), so such a terminal would generate an empty line if we were to
output $COLUMNS spaces at the start of a line.  The vt100 started a
tradition where the terminal delayed the wrap at the end of the line to
see if it was going to be followed by more literal characters or some
cursor-movement chars.  So, we need to vary the length of the spaces
depending on if the terminal has this delayed-wrap logic or not.

..wayne..


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] adding a new option: PROMPT_NUDGE
  2005-07-12 18:48           ` Wayne Davison
@ 2005-07-12 19:16             ` Wayne Davison
  0 siblings, 0 replies; 9+ messages in thread
From: Wayne Davison @ 2005-07-12 19:16 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Tue, Jul 12, 2005 at 11:48:16AM -0700, Wayne Davison wrote:
> The vt100 started a tradition where the terminal delayed the wrap at
> the end of the line to see if it was going to be followed by more
> literal characters or some cursor-movement chars.

One other complication I forgot to mention:  there were some terminals
that handled this the other way 'round -- instead of ignoring the wrap
when followed by a CR, NL, etc., they really did wrap after $COLUMNS
characters, and then ignored a NL that came right after the wrap (which
is why the termcap attribute is "xn" for ignore newline).  I think that
the vt100-compatible "firm margins" attribute may be indicated by an
"xv" in the termcap, but it's not well documented, so it seems likely
that this "xv" attribute is not going to be reliably supplied by a
variety of OSes.

So, the current "xn" logic in my posted patch seems like it is likely to
be the most compatible way to go (since I doubt anyone uses a Concept
terminal these days).

..wayne..


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] adding a new option: PROMPT_NUDGE
  2005-07-12 14:19         ` Bart Schaefer
  2005-07-12 18:48           ` Wayne Davison
@ 2005-07-12 20:46           ` J
  1 sibling, 0 replies; 9+ messages in thread
From: J @ 2005-07-12 20:46 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

> } I'm currently thinking that the SPACES part is overly tied to the
> } implementation rather than what it's trying to accomplish.  How about
> } PROMPT_NUDGE?  That at least hints at its purpose.
> 
> I'd like some opinions from people whose first language is not English.

My first language is French and I certainly prefer PROMPT_SPACES than
PROMPT_NUDGE for that matter.

-- 
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-07-12 20:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-11 14:47 Very wierd output problems Ulf Magnusson
2005-07-11 15:14 ` Travis Spencer
2005-07-11 17:40   ` Wayne Davison
2005-07-12  3:20     ` Bart Schaefer
2005-07-12  5:35       ` [PATCH] adding a new option: PROMPT_NUDGE Wayne Davison
2005-07-12 14:19         ` Bart Schaefer
2005-07-12 18:48           ` Wayne Davison
2005-07-12 19:16             ` Wayne Davison
2005-07-12 20:46           ` J

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).