akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.67k stars 85 forks source link

[wezterm, vim-airline] lualine over cursor #413

Open raffaem opened 8 months ago

raffaem commented 8 months ago

ble version: Bash version:

GNU bash, version 5.2.26(1)-release (x86_64-pc-linux-gnu) [Arch Linux]
ble.sh, version 0.4.0-devel4+98a2ae15 (noarch) [git 2.43.1, GNU Make 4.4.1, GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.2.1, GNU MP 6.3.0)]
bash-preexec (wezterm.sh), (hash:1cc83f86c72a217a0c56bf4f4e5d9a8834142817, 20228 bytes) (noarch)
starship, version 1.17.1 (rustc 1.75.0 (82e1608df 2023-12-21) (Arch Linux rust 1:1.75.0-1), 2024-01-03 07:54:53 +00:00)
zoxide, version 0.9.2 (/usr/bin/zoxide)
atuin, version 18.0.1 (/usr/bin/atuin)
locale: LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8
terminal: TERM=xterm-256color wcwidth=15.0-west/15.1-2+ri, wezterm:20220408 (1;277;0)

When the space on screen finish, and you press carriage return without issuing any command, lualine collocates itself in front of the cursor, and what you write gets hidden by lualine:

image

Here is a video:

20240219T165217.webm

akinomyoga commented 8 months ago

Confirmed with wezterm. This is the reduced ~/.bashrc:

# bashrc
HISTFILE=~/tmp
source /path/to/ble.sh --norc
set -o vi
ble-import vim-airline
bleopt vim_airline_theme=light
source wezterm.sh

The problem is suppressed when WezTerm's semantic zone of the shell integration is disabled.

[...]

WEZTERM_SHELL_SKIP_SEMANTIC_ZONES=1
source wezterm.sh

The problem is also suppressed when this line in wezterm.sh is commented out.

I think WezTerm doesn't assume a concept of the status line at the bottom as a shell prompt. I'm not sure what would be the assumptions of Wezterm and how Wezterm responds to those OSC sequences. We probably need the help of Wez.

akinomyoga commented 8 months ago

I visited the repository of WezTerm and found that many Issues and PRs pop up every day. Wez must be super extremely busy. I'll take time to look into the codebase.

ble.sh keeps track of the cursor position on the terminal based on the sequences it emits. However, WezTerm seems to try to kindly adjust the cursor position inside precmd (or equivalently, PROMPT_COMMAND). This breaks the tracking of the cursor position by ble.sh. Actually, the needed cursor position adjustment is already done by ble.sh, so there is no need to adjust it again. The adjustment needs to be skipped.

The sequence OSC(A;...) produces FreshLineAndStartPrompt, and it performs fresh_line() and set_semantic_type(SemanticType::Prompt) here. We don't want fresh_line(), so maybe one could emit OSC(P;k=?) that invokes StartPrompt instead of OSC(A;...)? A question is what to specify to the k parameter, but it doesn't seem to be used anyway.

If that is correct, the problem would be solved by this change.

diff --git a/assets/shell-integration/wezterm.sh b/assets/shell-integration/wezterm.sh
index 1cc83f86c..524604833 100644
--- a/assets/shell-integration/wezterm.sh
+++ b/assets/shell-integration/wezterm.sh
@@ -481,7 +481,13 @@ __wezterm_semantic_precmd() {
     printf "\033]133;D;%s;aid=%s\007" "$ret" "$$"
   fi
   # Fresh line and start the prompt
-  printf "\033]133;A;cl=m;aid=%s\007" "$$"
+  if [[ -n "${BLE_VERSION-}" ]]; then
+    # Fresh line breaks ble.sh's cursor position tracking.  Also, the cursor
+    # position adjustment is already performed ble.sh so unnecessary here.
+    printf "\033]133;P\007"
+  else
+    printf "\033]133;A;cl=m;aid=%s\007" "$$"
+  fi
   __wezterm_semantic_precmd_executing=0
 }

I'll later test it because I don't have an environment now.

akinomyoga commented 8 months ago

I submitted a PR to WezTerm, but you can set the following setting for the time being:

# blerc

bleopt prompt_command_changes_layout=1 
raffaem commented 8 months ago

I submitted a PR to WezTerm, but you can set the following setting for the time being:

# blerc

bleopt prompt_command_changes_layout=1 

seems to work.Thanks!