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

Re: reinventing print_exit_value



On Jul 3, 11:56pm, Christian Taylor wrote:
}
} However: is there a simpler way to achieve this? My solution seems a bit 
} inelegant to me.

How about this way of putting it into the prompt?

PS1="%{%(0?..$(echotc DO 1)$(echotc sc)
$(echotc rc)$(echotc UP 1))%}%# %{%(0?..$(echotc sc)
(%?%)$(echotc rc))%}"

Translation:

Counting no size for this output -
- if $? is 0, output nothing
- else, try to move down one line, then save the cursor position, output
  a newline, restore the cursor position and try to move up one line.
Output a percent or pound character followed by a space.
Counting no size for this output -
- if $? is 0, output nothing
- else, save the cursor position, emit a newline and the value of $? in
  parens and restore the cursor.

What this does is cause an extra line to be added BELOW the regular prompt,
rather than above it, which contains the nonzero exit status.  Each time
you hit enter at the prompt, the new prompt covers up the previous result
and displays it again, so it's always visible but never occupies more than
one vertical line of your screen.

You may need to adjust that first part for your terminal; it's intended
to handle vt100/xterm save/restore cursor behavior at any line of the
screen, including the last line where emitting a newline scrolls the text
but does not change the saved position.  It doesn't always work properly
when NO_PROMPT_CR is set because ZLE may reposition the cursor again after
the prompt has been printed.  (This may be an issue only in 4.0.x rather
than 4.2.x.)



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