helix icon indicating copy to clipboard operation
helix copied to clipboard

Configurable spinners

Open sbromberger opened this issue 2 years ago • 18 comments

This PR adds the ability to customize the progress spinners. It changes the way they are created, as well, but this is not a huge issue because they weren't user-customizable beforehand anyway.

In summary:

The spinner can be defined in the config file using two keys under [editor] - spinner and spinner-interval. The former is a Vec<String> whose elements represent frames. The latter is the maximum update time in ms (equivalent to the interval that already exists in the code). Both default to the existing spinner.

This required allowing EditorView to take a ProgressSpinners argument, so I've changed the calling convention for EditorView::new.

If the spinner is multi-frame, then the current behavior where Instant::now() is repeatedly called still applies. However, for lower-powered systems, if the spinner is a single frame, then we can elide all the calls (and resulting syscalls) and save some performance.

The spinner can now be styled using ui.spinner in the theme. This allows the use of rapid_blink, for example, to simulate motion. (However - If the statusbar is non-black, I don't know yet how to make the background persist when the blink state goes to black.)

Anyway - please let me know what you think. I'm still not sure why we're using ProgressSpinners as a collection when it appears there's only ever one spinner. Could we simplify this?

sbromberger avatar Jun 16 '22 20:06 sbromberger

@BearOve - I think I addressed/resolved all your suggestions. Mind taking another look? Thanks!

sbromberger avatar Jun 17 '22 14:06 sbromberger

Yes you have. The only thing now is what happens if the frame specified is more than one visible character wide. However, it might even be a feature to have a 3 character spinner?

I will leave this for someone more familiar with the inner workings of Helix however.

Great work

bjorn-ove avatar Jun 17 '22 16:06 bjorn-ove

The only thing now is what happens if the frame specified is more than one visible character wide. However, it might even be a feature to have a 3 character spinner?

I tried this last night and it works up to 3-4 chars before it bumps into the filename.

sbromberger avatar Jun 17 '22 17:06 sbromberger

I was curious what you would want to replace the current spinner

Selfishly, I hate things that move erratically - I find them really distracting, and the LSP loading process stops and starts the spinner a few times (there's a CPU lag as well on my lower-performance VM). I replaced it with a single frame of a yellow dot. The single-frame notification also doesn't use Instant::now() so I save the syscalls.

But yes - I've been playing around with lots of alternate possibilities.

(Won't somebody think of the poor syscalls?)

sbromberger avatar Jun 18 '22 00:06 sbromberger

Does it make sense for spinner-interval set to 0 to disable spinner display? We already have this functionality if spinner-frames is set to [].

Would it not make more sense to change this functionality to keep the previous logic (update when a key-press is made, instead of just removing the spinner)? I prefer this logic, because it prevents a render every time the spinner updates (which is 👍 if you're on a slow connection/ssh'd into a server).

Woolworths avatar Jun 19 '22 13:06 Woolworths

Would it not make more sense to change this functionality to keep the previous logic (update when a key-press is made, instead of just removing the spinner)?

I'm not sure I understand. The current code doesn't allow you to configure the spinner interval at all, and if you manage to do it by editing the code, if you set it to zero, helix will panic on assert [1]. There's currently no logic that handles "update spinner on keypress".

Because the frame is empty, there will be no significant update - I run helix (and this proposed code) on a small VM over a slow SSH connection and haven't seen any issues. In fact, it's one of the primary reasons I'm submitting this PR, since the current behavior causes the spinner to move erratically.

[1] https://github.com/helix-editor/helix/blob/ad15e7b5e8918e1521683c7f5c63d77e00c58023/helix-term/src/ui/spinner.rs#L38

sbromberger avatar Jun 19 '22 14:06 sbromberger

Ahhh yes, that makes sense. Thanks for the explanation 👍

Woolworths avatar Jun 20 '22 03:06 Woolworths

~~Changing this to WIP pending discussion of #2829~~ This was the wrong approach.

sbromberger avatar Jun 20 '22 04:06 sbromberger

@Woolworths - just out of curiosity, are you using mosh?

sbromberger avatar Jun 20 '22 06:06 sbromberger

@sbromberger I'm not, no 😄

Woolworths avatar Jun 20 '22 07:06 Woolworths

Does this PR affect how spinners work internally or just how they are displayed? While testing this PR I just ran into the situation where the spinner would not disappear, even after rust-analyzer finished loading.

Though, I've also recently updated rust-analyzer (427061da1 2022-06-19) which may have introduced this problem.

CptPotato avatar Jun 22 '22 07:06 CptPotato

While testing this PR I just ran into the situation where the spinner would not disappear, even after rust-analyzer finished loading.

I've noticed this too, but I also noticed it without the PR, so I don't think it's the code here. The spinner indicator updated to the correct state (went away) when I pressed a key.

I didn't change any of the logic relating to spinner start/stop - just how it's displayed.

sbromberger avatar Jun 22 '22 14:06 sbromberger

Also, it's not consistent. Here's a screen recording I just made with a single-char (yellow dot) spinner:

https://asciinema.org/a/Tjuz8EWfpLZiDHd6A24K1l9sW

sbromberger avatar Jun 22 '22 14:06 sbromberger

I've noticed this too, but I also noticed it without the PR, so I don't think it's the code here. The spinner indicator updated to the correct state (went away) when I pressed a key.

I didn't change any of the logic relating to spinner start/stop - just how it's displayed.

Then it's probably an unrelated issue. In my case it really never disappeared, even after half an hour while editing the file.

CptPotato avatar Jun 22 '22 14:06 CptPotato

This would be really awesome to see in helix!

Woolworths avatar Jul 18 '22 04:07 Woolworths

Refactored for new customizable statusline. Width of spinner is now handled appropriately by the statusline!

Ready for review.

sbromberger avatar Jul 21 '22 10:07 sbromberger

Been using this branch for some time with a simple one character custom spinner and have seen no obvious glitches.

aikomastboom avatar Jul 28 '22 11:07 aikomastboom

Could I get a review on this, please? Thank you :)

sbromberger avatar Aug 04 '22 18:08 sbromberger

Merged with master - I think this is ready for review. Thank you.

sbromberger avatar Sep 02 '22 19:09 sbromberger