-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vim-airline emulation [Vim info pane, more customization and refresh] #114
Comments
Thank you for the discussion! I'll later write detailed explanations, but you can also look at the following settings: |
Actually, there were similar requests twice or three times in the past. I think I should describe it somewhere in Wiki.
This is what Vim does; In Vim, the mode-line content is hardcoded. The primary reason I prepared the options For more flexible customization, I would recommend just turning off the default mode names and instead setting up a status line as vim-airline is doing internally. The following is an example for you! Please replace ^V, ^S, and ^R with the real control characters (or you may write # blerc
function huresche/set-up-status-line {
# Hide the default mode name in the info pane
bleopt keymap_vi_mode_show=
# Update prompts on the mode change
bleopt keymap_vi_mode_update_prompt=1
# Define a named prompt sequence \q{huresche/vim-mode}
function ble/prompt/backslash:huresche/vim-mode {
local mode; ble/keymap:vi/script/get-mode
case $mode in
(*n) ble/prompt/print $'\e[1;37;41m NORMAL \e[m' ;;
(*v) ble/prompt/print $'\e[1;37;41m VISUAL \e[m' ;;
(*V) ble/prompt/print $'\e[1;37;41m V-LINE \e[m' ;;
(*^V) ble/prompt/print $'\e[1;37;41m V-BLOQ \e[m' ;;
(*s) ble/prompt/print $'\e[1;37;41m SELECT \e[m' ;;
(*S) ble/prompt/print $'\e[1;37;41m S-LINE \e[m' ;;
(*^S) ble/prompt/print $'\e[1;37;41m S-BLOQ \e[m' ;;
(i) ble/prompt/print $'\e[1;37;41m INSERT \e[m' ;;
(R) ble/prompt/print $'\e[1;37;41m RPLACE \e[m' ;;
(^R) ble/prompt/print $'\e[1;37;41m VPLACE \e[m' ;;
(*) ble/prompt/print $'\e[1;37;41m ?????? \e[m' ;;
esac
}
ble-color-setface prompt_status_line none
bleopt prompt_status_line='\q{huresche/vim-mode}\e[40;31;43m\uE0B0\e[37m \w \e[33;49m\uE0B0\e[m'
}
blehook/eval-after-load keymap_vi huresche/set-up-status-line
Maybe you don't need it anymore because we have
Ah, that is because the content of the info pane is only updated on the mode change. When you just run commands, the mode remains in |
You can also put several fields separated by # Examples
bleopt prompt_status_line='left\rcenter\rright'
bleopt prompt_status_line='\q{huresche/vim-mode}\r\w' You can find the detailed explanation of each option in the following pages:
|
I decided to make a |
Oh I see, that actually makes a more modular approach than rearranging the info pane, and also would make it easier to manage the mode combinations right?, since I saw that customizing the "visual block" mode in the info pane would result in 2 separate mode strings. The function does update the $PWD correctly! However, I noticed that the "visual block" mode was not being detected, when I enter into it with Ctrl-V, I get the ?????? mode string. I tried changing the *^V part with *^v, ^V, ^v, but no luck, what could be causing this? I checked the
Note: the \uE0B0 doesn't get interpreted inside bleopt prompt_status_line, but one can simply put the character itselft there: or put the \uE0B0 in the
I saw that hook but I didn't understand it, so should I make a custom PWD function and add it with
and
and it appears to update correctly as I expect it!, and so does blehook PRECMD. So what's the difference between |
That would be nice as it would make the terminal feel even more like vim withouth actually being in vim. (Of course vim has its own terminal mode but I still find it buggy with some terminals and multiplexers). In #85 you said:
In vim-airline one can just make a global dictionary to change how the mode strings look, for example I have:
This is similar to the |
On a related note, I noticed that when characters are printed by ble, they don't get erased when something gets resized or removed from there, including the status line and the vim info pane. For example if one resizes down the terminal (make characters smaller), the status line does adjust and prints to the new bottom line, but the previous printing is still shown. I'd show a demo but Github is not letting me post it. This issue also happens when you change the vim mode and the status line gets shrinked. For example if the status line is in normal mode and shows ノーマル, but then it's changed to insert mode 挿入 which has fewer characters; one would still see the マル part. Maybe this should be a separate issue that i didn't find it was discussed. |
Control characters
Have you noticed this comment?
I think you have checked the function by $ type ble/keymap:vi/script/get-mode | LESS= /bin/less You can also play around by defining your function with control characters: $ func() { echo $'\x16'; }; type func
func is a function
func ()
{
echo ''
}
$ type func | LESS= /bin/less -XF
func is a function
func ()
{
echo '^V'
}
|
Right, my bad, I somehow missed that!
I didn't know about that, interesting
Oh, I misread that, now it makes sense, thanks for clarifying
Awesome!!
Ah, because if you set the background color, it overrides the previous printing of the status line, yes. But the issue still exists on terminal resizing. |
da1d0ff I have pushed a partial support of $ bleopt vim_airline_@
$ ble-face vim_airline_@
$ declare -p _ble_lib_vim_airline_mode_map Note: There are still several TODOs: Now I'm trying to extract themes from Edit: I believe the afore-mentioned problems are also resolved in the commit da1d0ff:
I fixed this issue. It was caused by an old code that wasn't used recently but used by new codes.
Right. I have updated to always clear the background
This was a separate problem. It turned out that Bash kills SIGWINCH when the former SIGWINCH is in processing. If terminal sends multiple SIGWINCH for smoother resizing, only the first SIGWINCH is ensured to reach |
Fantastic, it looks and works great, and the customizations are nice. So does that mean
Yes, great, simply including
I see, interesting. Indeed now it readjusts very smoothly, thanks very much for your work. The only very minor issue I still see is when quickly increasing the terminal font size and having a right prompt, it can still leave some of the printing wrongly readjusted on top of the command line; anyways it is a very minor thing since it doesn't happen when increasing the font slowly (could be a performance thing), and doing so would mess up the previous command's right prompt printing so one would have to clean up the terminal anyways. For the TODO list I'd like to suggest showing the key pressed when there's a pending operation and also the current column like how vim does it. |
Thank you for testing it!
They are an abstraction layer for Bash versions.
After I received this question, I remembered that
Unless we clear all the terminal contents on resizing, it is difficult to handle it properly. It is related to the text reflow of the terminal where the terminal itself rearranges its contents on resizing. But the reflow algorithm depends on the terminal and also on the current cursor position (which
Actually, this directly affects the performance. In the current implementation, we need to recalculate the prompt contents every time when it needs to be updated. Supporting the current column in the status line requires updating the prompt contents on every keystroke. For example, we don't want to run |
Ah I see, thanks for the detailed explanation and the refactoring
Yeah, I know tracking previous printed prompts of executed commands is very difficult and terminal related. I was more so referring that even when there was no previous command executed, quickly changing the terminal size (e.g. the window manager tiles it to half its size) causes some printing of the current right prompt (and sometimes the left prompt comes along) on top of the current command line. As you said, erasing previous lines is not viable, and I'm still guessing it has to with performance of its recalculation since putting more complex functions in right prompt, or having vim-airline imported makes it more noticeable
Yes, totally understandable and answers the previous point, optimizations is the right thing to focus on. I wish bash supported right prompts natively, but until that comes ble's implementation is the best I've seen among bash prompts. I'll just close the issue, but feel free to reopen it for any updates on |
Ah, OK. I misunderstood that the problem is in the previous lines. I'll later take a look at whether I could reproduce it on my side.
I'm sorry, but I reopen it. I'll definitely update |
I have added support for |
It seems the OP @huresche has disappeared and doesn't seem to get back. I have been using this new vim-airline status line by myself and don't find serious problems. It works fine. So I'd now close the issue. Thank you! |
It would be nice to let users customize more freely their vim info pane. In
$_ble_base/keymap/vi.sh
, the vim's mode name is surrounded by "--"Maybe that line can be omitted or maybe just be surrounded by
$'
and\e[m'
. Then users can make their own color sequences and put special characters as if it was a regular prompt. For example I thought it would be nice to show the current directory in the vim pane in insert mode rather than in the prompt (which would declutter the terminal from repetitive output); so by deleting that line and putting this in theblerc
:one can have a nice looking pane, similar to something like vim-airline (I would post a screenshot but Github is not letting me); and of course users can customize this to their liking. However, one other thing is that this function does not get refreshed and so ${PWD} always shows just the working directory when ble was sourced. A workaround that kind of works is to put that function into a PROMPT_COMMAND (or a bash-preexec precmd), but this only refreshes the $PWD if you first change to another vim mode and back again to insert mode, could this be adressed so it reads environment variables every time it's printed?
EDIT: Funny, I just noticed ble has a blehook PRECMD that also does preexecution of functions, but it also doesn't refresh the $PWD on every prompt, maybe it's easier to change that blehook function?
The text was updated successfully, but these errors were encountered: