You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to integrate Kanata (a keyboard remapping software) with poweerlevel10k via the prompt. I'd like it to indicate which layer Kanata is in at a given moment. I was able to get a prompt section working fine with the following code:
zmodload zsh/net/tcp
typeset -gA unicode_map=(
qwerty 'QWE'
colemak 'COL'
dvorak 'DVO'
layers $'\ueea8'
numpad '123'
symbols 'SYMB'
delimiters '()'
)
default_value=$'\uf12a'# function redraw_prompt() {# local f# for f in chpwd "${chpwd_functions[@]}" precmd "${precmd_functions[@]}"; do# [[ "${+functions[$f]}" == 0 ]] || "$f" &>/dev/null || true# done# p10k display -r# }functionprompt_my_kanata() {
ztcp 127.0.0.1 ${MYKANATAPORT-5829}&> /dev/null
if [[ -n"${REPLY:-}" ]];thenread -r line <&$REPLYif [[ "$line"=~\{\"LayerChange\":\{\"new\":\"([^\"]+)\"\}\} ]];then
layer="${match[1]}"
icon=${unicode_map[$layer]:-$default_value}
p10k segment -c "$layer" -s "$layer" -i '' -f blue -t "$icon"fiexec {REPLY}<&-
fi
}
This works fine, but doesn't update (refers/redraw) the prompt when kanata changes a layer (via keybinding or TCP server or whatever). I've looked at issue #2048 but that appears to be related to zle widget behaviour a la #72. This made me think I need some sort of asynchronous update similar to #609.
However, this script (sourced before p10k) doesn't work, it only shows up in the prompt when I manually run check_kanata_layer in the shell. It then doesn't update when new prompts are spawned even if the layer changes, and then needs check_kanata_layer to be run again to update.
One more concern I had is that the use case described in #609 seems to be for a function with large overhead being updated after the prompt is initially rendered, whereas, I want to almost have a constantly running listener that refreshes the prompt every time it receives a certain message - potentially multiple times between shell entry. Hence I'm not sure this is even the right approach.
It's been a while since I did any zsh scripting and I'm by no means proficient at it so I'd really appreciate any help with this!
EDIT: For reference, I have added my_kanata to the right prompt environment variable in my p10k config.
The text was updated successfully, but these errors were encountered:
I'm trying to integrate Kanata (a keyboard remapping software) with poweerlevel10k via the prompt. I'd like it to indicate which layer Kanata is in at a given moment. I was able to get a prompt section working fine with the following code:
This works fine, but doesn't update (refers/redraw) the prompt when kanata changes a layer (via keybinding or TCP server or whatever). I've looked at issue #2048 but that appears to be related to zle widget behaviour a la #72. This made me think I need some sort of asynchronous update similar to #609.
My attempt is as follows:
However, this script (sourced before p10k) doesn't work, it only shows up in the prompt when I manually run check_kanata_layer in the shell. It then doesn't update when new prompts are spawned even if the layer changes, and then needs check_kanata_layer to be run again to update.
One more concern I had is that the use case described in #609 seems to be for a function with large overhead being updated after the prompt is initially rendered, whereas, I want to almost have a constantly running listener that refreshes the prompt every time it receives a certain message - potentially multiple times between shell entry. Hence I'm not sure this is even the right approach.
It's been a while since I did any zsh scripting and I'm by no means proficient at it so I'd really appreciate any help with this!
EDIT: For reference, I have added
my_kanata
to the right prompt environment variable in my p10k config.The text was updated successfully, but these errors were encountered: