Skip to content

line-pre-redraw hook conflicts with z4h cursor position query (5s Ctrl+L delay) and breaks p10k right prompt alignment #64

Description

@amryadam

Summary

ghost-complete's shell integration causes two issues when used with zsh4humans + powerlevel10k:

  1. Ctrl+L hangs for ~5 seconds_gc_report_buffer on line-pre-redraw interferes with z4h's cursor position query
  2. Right prompt (RPROMPT) misaligned_gc_precmd OSC 133 output breaks powerlevel10k's prompt width calculation

Environment

  • Terminal: Ghostty
  • Shell: zsh with zsh4humans (v5) + powerlevel10k
  • OS: macOS

Issue 1: Ctrl+L delay

Steps to reproduce

  1. Install zsh4humans
  2. Install ghost-complete (ghost-complete install)
  3. Open a new terminal
  4. Press Ctrl+L

Expected: Screen clears instantly
Actual: Terminal hangs for ~5 seconds before clearing

Root cause

z4h's z4h-clear-screen-soft-* widgets call -z4h-get-cursor-pos, which:

  1. Sends \e[6n (Device Status Report) to the terminal
  2. Reads the terminal's response (e.g. \e[24;1R) from the TTY fd with read -srt 5 -d R

ghost-complete registers _gc_report_buffer on line-pre-redraw:

_gc_report_buffer() {
    printf '\e]7770;%d;%s\a' "$CURSOR" "$BUFFER"
}
add-zle-hook-widget line-pre-redraw _gc_report_buffer

This hook fires during the redraw triggered by the clear-screen widget, writing \e]7770;... to the terminal at the same time z4h is trying to read the \e[6n response. The interleaved escape sequences corrupt the expected response pattern, causing z4h's read to retry and eventually time out after 5 seconds.

Workaround

Override z4h's clear-screen binding after z4h init:

bindkey '^L' clear-screen

Issue 2: Right prompt misalignment

Steps to reproduce

  1. Install zsh4humans (which uses powerlevel10k)
  2. Configure p10k with a 1-line prompt that has right prompt elements (e.g. time)
  3. Install ghost-complete
  4. Open a new terminal

Expected: Right prompt elements (e.g. time) aligned to the right edge of the terminal
Actual: Right prompt floats in the middle, not pushed to the right edge

Root cause

_gc_precmd emits \e]133;A\a (OSC 133) before the prompt is drawn. This escape sequence has zero visible width, but it interferes with powerlevel10k's prompt width calculation for the gap between left and right prompt segments, causing RPROMPT to be mispositioned.

Note: z4h already provides its own OSC 133 shell integration via zstyle ':z4h:' term-shell-integration 'yes', so ghost-complete's markers are redundant when z4h is in use.

Suggested fixes

  1. _gc_report_buffer could avoid writing to stdout during ZLE redraws triggered by other widgets, or debounce/defer the output to prevent interleaving with terminal queries.
  2. _gc_precmd could detect when powerlevel10k or z4h shell integration is active and skip emitting duplicate OSC 133 markers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions