feat: changed loading to actual animation#178
Conversation
saecki
left a comment
There was a problem hiding this comment.
I also thought about implementing this myself, but there was always something else that felt more important. So thanks opening this PR :D
In the spirit of the plugin, I'd like to make things more configurable instead of hardcoding them. While we're at it, the very similar search indicator should also be animated the same way.
|
|
||
| local timer = assert(vim.loop.new_timer()) | ||
| buf_state.loading_timer = timer | ||
| timer:start(120, 120, vim.schedule_wrap(function() |
There was a problem hiding this comment.
Could you make the update rate configurable?
I think a new section called loading with the following fields would be nice.
show_indicator: booleanframes: {string}rate: integer//0should be handled specially and not start the timer at all
The text.searching and text.loading strings should be changed to include a %s format specifier where the loading spinner will be inserted.
The loading_indicator options should be deprecated like this in config/init.lua
deprecated = {
new_field = { "loading", "show_indicator" },
},| UPDATE = 3, | ||
| } | ||
|
|
||
| local LOADING_FRAMES = { |
There was a problem hiding this comment.
These can become the default frames in the config.
| ---@type integer | ||
| local CUSTOM_NS = vim.api.nvim_create_namespace("crates.nvim") | ||
| ---@type integer | ||
| local LOADING_NS = vim.api.nvim_create_namespace("crates.nvim.loading") |
There was a problem hiding this comment.
With the mentioned changes I'd rename this to SPINNER_NS
|
|
||
| ---@enum LineState | ||
| local LineState = { | ||
| SEARCHING = 1, |
There was a problem hiding this comment.
The search indicator should also be handled the same. And be configurable with a separate search section that accepts the same fields as loading.
| end | ||
|
|
||
| ---@param buf_state BufUiState | ||
| local function stop_loading_timer(buf_state) |
|
|
||
| ---@param buf integer | ||
| ---@param buf_state BufUiState | ||
| local function render_loading(buf, buf_state) |
| ---@field line_state table<integer,LineState> | ||
| ---@field loading_timer uv.uv_timer_t? | ||
| ---@field loading_frame integer | ||
| ---@field loading_lines table<integer,boolean> |
There was a problem hiding this comment.
I think we can get rid of the separate table of loading lines, and instead just use the line_state and check if it's LOADING OR SEARCHING.
| @@ -25,13 +28,28 @@ | |||
| UPDATE = 3, | |||
There was a problem hiding this comment.
I just noticed the UPDATE state is and was never used, so could you also remove it?
Uh oh!
There was an error while loading. Please reload this page.