Article 58WV9 ZSH use "zle reset-prompt" outside of trap

ZSH use "zle reset-prompt" outside of trap

by
themohawkninja
from LinuxQuestions.org on (#58WV9)
Hello,

I am trying to setup my .zshrc so that it will do something that will change the prompt when I type into the prompt. When I try putting a "zle reset-prompt" line inside of a "while read -rn1" loop, I receive a "widgets can only be called when ZLE is active" error.

It appears that I have to place the "zle reset-prompt" line in a trap. If this is the case, can I make my own trap that is called on a keypress?

For reference, below is my current .zshrc file. Instead of the one second loop, it should redraw the prompt on a key press:
Code:# Setup basic config stuff for history size, Vim keybindings, and the like
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt autocd beep extendedglob notify
unsetopt nomatch
bindkey -v

# Auto-completion (double-tab tab)
zstyle :compinstall filename '/home/terminus/.zshrc'
autoload -Uz compinit
compinit
zstyle ':completion:*' menu select

# Make Home, End and Delete do what they should do...
bindkey "^[[3~" delete-char
bindkey "^[[8~" end-of-line
bindkey "^[[7~" beginning-of-line

# Colorize ls output
alias ls='ls --color=auto'

# Special prompt theme stuffs.
autoload -Uz promptinit
promptinit
prompt elite2

# Variables
TMOUT=1
term=$(tty | grep -Eo '[0-9]{0,9}')
color="green"
text=$LBUFFER
PROMPT=$'%F{$color}%f%F{$(shorthash "pts/$term")}%B%b%y%B%b%f%F{$color}%f%F{$(shorthash $PWD)}%b%B%b%d%B%b%f\n%F{$color}> %f'
PROMPT2='%F{$color}> %f'
PS2='%F{$color}> %f'

TRAPALRM()
{
if [[ $text != $LBUFFER ]]
then
color="red"
zle reset-prompt
text=$LBUFFER
else
color="green"
zle reset-prompt
fi
}

export EDITOR='vim'Yes, I know the "prompt elite2" seems redundant, but for some reason the colors aren't right if I get rid of that. I need to figure out what gets set in that theme that I need to extract out.

Also the "shorthash" is just a program I made to convert a string into an 8 bit integer, mainly for use as a color code.latest?d=yIl2AUoC8zA latest?i=p7aYsWl_pO4:X_K37zS-8EQ:F7zBnMy latest?i=p7aYsWl_pO4:X_K37zS-8EQ:V_sGLiP latest?d=qj6IDK7rITs latest?i=p7aYsWl_pO4:X_K37zS-8EQ:gIN9vFwp7aYsWl_pO4
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments