zsh-users
 help / color / mirror / code / Atom feed
* Duplicating TRANSIENT_RPROMPT for left PROPMT?
@ 2013-10-22 21:22 Jesse Hathaway
  2013-10-23 13:47 ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Jesse Hathaway @ 2013-10-22 21:22 UTC (permalink / raw)
  To: ZSH Users Mailing List, Jesse Hathaway

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

When I enter a command the bottom part of my zsh PROMPT is not cleared

~
→ echo a
a- INSERT --
~
→
-- INSERT --

The unusual part of my prompt is the vi mode at the bottom of my screen.
Does anyone have thoughts on the best way to clear the prompt before the
command is entered?

Here is my zshrc:

bindkey -v
setopt prompt_subst

vim_ins_mode="-- INSERT --"
vim_cmd_mode=""
vim_mode=$vim_ins_mode

terminfo_down_sc=$terminfo[cud1]$terminfo[cud1]$terminfo[cuu1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1]$terminfo[cud1]
function zle-keymap-select {
  vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
  zle reset-prompt
}
zle -N zle-keymap-select

function zle-line-finish {
  vim_mode=$vim_ins_mode
}
zle -N zle-line-finish

PS1='%{$terminfo_down_sc$vim_mode$terminfo[rc]%}%~
→ '

Thanks, Jesse

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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-22 21:22 Duplicating TRANSIENT_RPROMPT for left PROPMT? Jesse Hathaway
@ 2013-10-23 13:47 ` Bart Schaefer
  2013-10-25 15:50   ` Jesse Hathaway
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2013-10-23 13:47 UTC (permalink / raw)
  To: ZSH Users Mailing List

On Oct 22,  4:22pm, Jesse Hathaway wrote:
}
} The unusual part of my prompt is the vi mode at the bottom of my screen.
} Does anyone have thoughts on the best way to clear the prompt before the
} command is entered?

The best solution to this is to NOT put the vi mode in the prompt, but
instead use "zle -M" to display it.  Simplest way is like this:

PS1='%~ '
vim_ins_mode="-- INSERT --"
vim_cmd_mode=""

function zle-keymap-select {
  vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
  zle -M -- "$vim_mode"
}
zle -N zle-keymap-select
zle -N zle-line-init zle-keymap-select


Of course if you're already doing other stuff in zle-line-init you'll need
to tweak this, e.g., call zle-keymap-select from zle-line-init.


This and your original scheme both seem to suffer from the problem that
any completion listing covers up the "mode message" and it doesn't return
until you toggle through command/insert again.


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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-23 13:47 ` Bart Schaefer
@ 2013-10-25 15:50   ` Jesse Hathaway
  2013-10-25 17:23     ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Jesse Hathaway @ 2013-10-25 15:50 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZSH Users Mailing List

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

On Wed, Oct 23, 2013 at 8:47 AM, Bart Schaefer <schaefer@brasslantern.com>wrote:

> On Oct 22,  4:22pm, Jesse Hathaway wrote:
> }
> } The unusual part of my prompt is the vi mode at the bottom of my screen.
> } Does anyone have thoughts on the best way to clear the prompt before the
> } command is entered?
>
> The best solution to this is to NOT put the vi mode in the prompt, but
> instead use "zle -M" to display it.  Simplest way is like this:
>
> PS1='%~ '
> vim_ins_mode="-- INSERT --"
> vim_cmd_mode=""
>
> function zle-keymap-select {
>
> vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
>   zle -M -- "$vim_mode"
> }
> zle -N zle-keymap-select
> zle -N zle-line-init zle-keymap-select
>

Thanks for your suggestions Bart

I tried the zle -M approach, but it seemed to result in my cursor sometimes
being at the bottom of the output, and them sometimes the vim_mode prompt
appearing, i.e. my cursor was jumping up and down.

I ended up adding a preexec which solves the problem:

# Clear vim_mode prompt before executing command, as the command output
will be
# written to same line as the vim_mode prompt on the terminal
function preexec {
  echo -n "$terminfo[el]"
}


> This and your original scheme both seem to suffer from the problem that
> any completion listing covers up the "mode message" and it doesn't return
> until you toggle through command/insert again.


Yeah this is definitively not great, I spent some time trying to determine
how to solve the problem, but I haven't come up with anything yet. I would
love suggestions. I couldn't find any hooks to use when suggestions fire. I
am also considering diving into the zsh source and look into adding proper
support for a BOTTOM_PROMPT.

Thanks, Jesse

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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-25 15:50   ` Jesse Hathaway
@ 2013-10-25 17:23     ` Bart Schaefer
  2013-10-29 18:11       ` Jesse Hathaway
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2013-10-25 17:23 UTC (permalink / raw)
  To: ZSH Users Mailing List

On Oct 25, 10:50am, Jesse Hathaway wrote:
}
} I tried the zle -M approach, but it seemed to result in my cursor sometimes
} being at the bottom of the output, and them sometimes the vim_mode prompt
} appearing, i.e. my cursor was jumping up and down.
} 
} I ended up adding a preexec which solves the problem:
} 
} # Clear vim_mode prompt before executing command, as the command output
} will be
} # written to same line as the vim_mode prompt on the terminal
} function preexec {
}   echo -n "$terminfo[el]"
} }

Here's another possibility I should have thought of before:

---- 8< ----
PS1='%~ '
vim_ins_mode=$'\n'"-- INSERT --"
vim_cmd_mode=""

zle-keymap-select() {
  vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
  POSTDISPLAY=$vim_mode
  zle redisplay
}
zle -N zle-keymap-select
zle -N zle-line-init zle-keymap-select

zle-line-finish() {
  if [[ -n $POSTDISPLAY ]]
  then
    POSTDISPLAY=''
    zle redisplay
  fi
}
zle -N zle-line-finish
---- 8< ----

I think this solves all the problems so far discussed.


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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-25 17:23     ` Bart Schaefer
@ 2013-10-29 18:11       ` Jesse Hathaway
  2013-10-30  6:19         ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Jesse Hathaway @ 2013-10-29 18:11 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZSH Users Mailing List

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

Bart thanks for the suggestion,

I tried your solution but it doesn't work for me when I first start up a
new shell. When I start up a new shell there is no POSTDISPLAY information,
but when I then change into command mode the prompt appears.

Does your code work for you when you first startup a shell?

I am using zsh version 5.0.2 on a debian sid box

Thanks, Jesse

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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-29 18:11       ` Jesse Hathaway
@ 2013-10-30  6:19         ` Bart Schaefer
  2013-10-30 18:01           ` Jesse Hathaway
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2013-10-30  6:19 UTC (permalink / raw)
  To: ZSH Users Mailing List

On Oct 29,  1:11pm, Jesse Hathaway wrote:
} 
} I tried your solution but it doesn't work for me when I first start up a
} new shell. When I start up a new shell there is no POSTDISPLAY information,
} but when I then change into command mode the prompt appears.
} 
} Does your code work for you when you first startup a shell?

Yes.

Are you sure you got this part?

    zle -N zle-line-init zle-keymap-select

You need to have both the zle-line-init and zle-keymap-select widgets
run the POSTDISPLAY assignment.  The easiest way if you don't already
have zle-line-init doing something else is to just bind them both to
the same function.

Perhaps something else that you're loading is clobbering this setup?
In which case you'll have to figure out a way to merge this into the
other use of zle-line-init that's being loaded later.

Are you missing the POSTDISPLAY only on shell startup, or every time
the first prompt is printed for a new command after the previous one
finishes?


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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-30  6:19         ` Bart Schaefer
@ 2013-10-30 18:01           ` Jesse Hathaway
  2013-10-30 18:51             ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Jesse Hathaway @ 2013-10-30 18:01 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZSH Users Mailing List, Jesse Hathaway

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

On Wed, Oct 30, 2013 at 1:19 AM, Bart Schaefer <schaefer@brasslantern.com>wrote:

> Are you sure you got this part?
>
>     zle -N zle-line-init zle-keymap-select
>

Yes I put your snippet as the entirety of my zsh config.

You need to have both the zle-line-init and zle-keymap-select widgets
> run the POSTDISPLAY assignment.  The easiest way if you don't already
> have zle-line-init doing something else is to just bind them both to
> the same function.
>
> Perhaps something else that you're loading is clobbering this setup?
> In which case you'll have to figure out a way to merge this into the
> other use of zle-line-init that's being loaded later.
>

I tried removing everything in /etc/zsh, but the behavior persists.


> Are you missing the POSTDISPLAY only on shell startup, or every time
> the first prompt is printed for a new command after the previous one
> finishes?
>

The latter, both on startup and then on every new command.

Do you have any suggestions on how I could debug this problem further?

Thanks for all the help, Jesse

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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-30 18:01           ` Jesse Hathaway
@ 2013-10-30 18:51             ` Bart Schaefer
  2013-10-31 14:07               ` Jesse Hathaway
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2013-10-30 18:51 UTC (permalink / raw)
  To: ZSH Users Mailing List

On Oct 30,  1:01pm, Jesse Hathaway wrote:
}
} > Are you sure you got this part?
} >
} >     zle -N zle-line-init zle-keymap-select
} 
} Yes I put your snippet as the entirety of my zsh config.

What's the output of

    zle -l -L

??  You should get

zle -N zle-keymap-select
zle -N zle-line-finish
zle -N zle-line-init zle-keymap-select

 
} > Are you missing the POSTDISPLAY only on shell startup, or every time
} > the first prompt is printed for a new command after the previous one
} > finishes?
} 
} The latter, both on startup and then on every new command.

Well, that certainly makes it sound as if zle-line-init is not being run,
or has a different function body.

See what the zle -l output tells you, and if that doesn't help, try
starting up the shell with the -x option.


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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-30 18:51             ` Bart Schaefer
@ 2013-10-31 14:07               ` Jesse Hathaway
  2013-10-31 15:09                 ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Jesse Hathaway @ 2013-10-31 14:07 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZSH Users Mailing List

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

On Wed, Oct 30, 2013 at 1:51 PM, Bart Schaefer <schaefer@brasslantern.com>wrote:

> What's the output of
>
>     zle -l -L
>

I tried grabbing the latest tarball from the website and compiling it, but
the results are the same:

~| /usr/local/bin/zsh -x
+/home/jhathaway/.zshrc:1> PS1='%~ '
+/home/jhathaway/.zshrc:2> vim_ins_mode='
-- INSERT --'
+/home/jhathaway/.zshrc:3> vim_cmd_mode='
-- COMMAND --'
+/home/jhathaway/.zshrc:10> zle -N zle-keymap-select
+/home/jhathaway/.zshrc:11> zle -N zle-line-init zle-keymap-select
+/home/jhathaway/.zshrc:20> zle -N zle-line-finish
~     zle -l -L
+/usr/local/bin/zsh:1> zle -l -L
zle -N zle-keymap-select
zle -N zle-line-finish
zle -N zle-line-init zle-keymap-select
~
~

Any other debugging thoughts would be great, I'm at a lost.

Thanks, Jesse

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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-31 14:07               ` Jesse Hathaway
@ 2013-10-31 15:09                 ` Bart Schaefer
  2013-10-31 18:01                   ` Jesse Hathaway
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2013-10-31 15:09 UTC (permalink / raw)
  To: ZSH Users Mailing List

On Oct 31,  9:07am, Jesse Hathaway wrote:
}
} I tried grabbing the latest tarball from the website and compiling it, but

I wouldn't have expected this to be a problem that would fix anyway ...

} the results are the same:
} 
} ~| /usr/local/bin/zsh -x
} +/home/jhathaway/.zshrc:1> PS1='%~ '
} +/home/jhathaway/.zshrc:2> vim_ins_mode='
} -- INSERT --'
} +/home/jhathaway/.zshrc:3> vim_cmd_mode='
} -- COMMAND --'
} +/home/jhathaway/.zshrc:10> zle -N zle-keymap-select
} +/home/jhathaway/.zshrc:11> zle -N zle-line-init zle-keymap-select
} +/home/jhathaway/.zshrc:20> zle -N zle-line-finish


Let's try "zsh -v" instead of "zsh -x" so we can see the function
definitions.

Also, how are you choosing whether to be in vi mode or emacs mode?  The
default is emacs mode, unless you have EDITOR=vi in the environment or
something.

Try editing the zle-keymap-select function to put the actual keymap name
into POSTDISPLAY, e.g.

  POSTDISPLAY="$vim_mode $KEYMAP"

-- 
Barton E. Schaefer


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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-31 15:09                 ` Bart Schaefer
@ 2013-10-31 18:01                   ` Jesse Hathaway
  2013-11-01  1:33                     ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Jesse Hathaway @ 2013-10-31 18:01 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZSH Users Mailing List

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

On Thu, Oct 31, 2013 at 10:09 AM, Bart Schaefer
<schaefer@brasslantern.com>wrote:

> On Oct 31,  9:07am, Jesse Hathaway wrote:
> }
> } I tried grabbing the latest tarball from the website and compiling it,
> but
>
> I wouldn't have expected this to be a problem that would fix anyway ...


I thought it was a long shot, I just wanted to make sure debian had not
added some strange patch.

} the results are the same:
> }
> } ~| /usr/local/bin/zsh -x
> } +/home/jhathaway/.zshrc:1> PS1='%~ '
> } +/home/jhathaway/.zshrc:2> vim_ins_mode='
> } -- INSERT --'
> } +/home/jhathaway/.zshrc:3> vim_cmd_mode='
> } -- COMMAND --'
> } +/home/jhathaway/.zshrc:10> zle -N zle-keymap-select
> } +/home/jhathaway/.zshrc:11> zle -N zle-line-init zle-keymap-select
> } +/home/jhathaway/.zshrc:20> zle -N zle-line-finish
>
>
> Let's try "zsh -v" instead of "zsh -x" so we can see the function
> definitions.
>

~| /usr/local/bin/zsh -v
set -o vi
PS1='%~ '
vim_ins_mode=$'\n'"-- INSERT --"
vim_cmd_mode=$'\n'"-- COMMAND --"

zle-keymap-select() {
  vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
  POSTDISPLAY="$vim_mode $KEYMAP"
  zle redisplay
}
zle -N zle-keymap-select
zle -N zle-line-init zle-keymap-select

zle-line-finish() {
  if [[ -n $POSTDISPLAY ]]
  then
    POSTDISPLAY=''
    zle redisplay
  fi
}
zle -N zle-line-finish
~

Also, how are you choosing whether to be in vi mode or emacs mode?  The
> default is emacs mode, unless you have EDITOR=vi in the environment or
> something.
>

Using the EDITOR environment variable, I also tried setting it explicitly
with `set -o vi`

Try editing the zle-keymap-select function to put the actual keymap name
> into POSTDISPLAY, e.g.
>
>   POSTDISPLAY="$vim_mode $KEYMAP"


see above.

Thanks, Jesse

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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-10-31 18:01                   ` Jesse Hathaway
@ 2013-11-01  1:33                     ` Bart Schaefer
  2013-11-01 20:10                       ` Jesse Hathaway
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2013-11-01  1:33 UTC (permalink / raw)
  To: ZSH Users Mailing List

On Oct 31,  1:01pm, Jesse Hathaway wrote:
} 
} > } I tried grabbing the latest tarball from the website and compiling it,
} >
} > I wouldn't have expected this to be a problem that would fix anyway ...
} 
} I thought it was a long shot, I just wanted to make sure debian had not
} added some strange patch.

Well, I just tried an older version (zsh-5.0.2-108-ga6ba892) and it goes
into an infinite loop in zle-line-init when calling zle redisplay.  So
some of what I wrote may be pretty dangerous advice if you don't have
the latest from CVS (effectively, zsh 5.0.3).

Consequently I suggest you try this:

zle-keymap-select() {
  vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
  POSTDISPLAY="$vim_mode $KEYMAP"
  [[ $WIDGET != zle-line-init ]] && zle redisplay
}


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

* Re: Duplicating TRANSIENT_RPROMPT for left PROPMT?
  2013-11-01  1:33                     ` Bart Schaefer
@ 2013-11-01 20:10                       ` Jesse Hathaway
  0 siblings, 0 replies; 13+ messages in thread
From: Jesse Hathaway @ 2013-11-01 20:10 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZSH Users Mailing List

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

On Thu, Oct 31, 2013 at 8:33 PM, Bart Schaefer <schaefer@brasslantern.com>wrote:

>
> Well, I just tried an older version (zsh-5.0.2-108-ga6ba892) and it goes
> into an infinite loop in zle-line-init when calling zle redisplay.  So
> some of what I wrote may be pretty dangerous advice if you don't have
> the latest from CVS (effectively, zsh 5.0.3).
>

I grabbed the latest code from git, and everything seems to work great in
my limited testing. I think I will try to backport the git HEAD version to
Debian, rather than using your suggested work around.

Thanks Bart for spending so much time getting to the bottom of this
problem. I'm excited about using vi-mode with my new fancy bottom prompt!

-Jesse

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

end of thread, other threads:[~2013-11-01 20:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-22 21:22 Duplicating TRANSIENT_RPROMPT for left PROPMT? Jesse Hathaway
2013-10-23 13:47 ` Bart Schaefer
2013-10-25 15:50   ` Jesse Hathaway
2013-10-25 17:23     ` Bart Schaefer
2013-10-29 18:11       ` Jesse Hathaway
2013-10-30  6:19         ` Bart Schaefer
2013-10-30 18:01           ` Jesse Hathaway
2013-10-30 18:51             ` Bart Schaefer
2013-10-31 14:07               ` Jesse Hathaway
2013-10-31 15:09                 ` Bart Schaefer
2013-10-31 18:01                   ` Jesse Hathaway
2013-11-01  1:33                     ` Bart Schaefer
2013-11-01 20:10                       ` Jesse Hathaway

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