From abfaa668f222caa59b2238ab592373a7c09df503 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Fri, 10 Jan 2025 11:28:53 -0500 Subject: [PATCH] Adding spinny animation to lualine when LLM is running --- after/plugin/lualine.lua | 67 +++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/after/plugin/lualine.lua b/after/plugin/lualine.lua index 38c5190..2c0d862 100644 --- a/after/plugin/lualine.lua +++ b/after/plugin/lualine.lua @@ -1,8 +1,61 @@ -require('lualine').setup { - options = { - theme = "catppuccin" - -- theme = "citruszest" - -- theme = "onedark" - -- ... the rest of your lualine config - } + +local M = require("lualine.component"):extend() + +M.processing = false +M.spinner_index = 1 + +local spinner_symbols = { + "⠋", + "⠙", + "⠹", + "⠸", + "⠼", + "⠴", + "⠦", + "⠧", + "⠇", + "⠏", } +local spinner_symbols_len = 10 + +-- Initializer +function M:init(options) + M.super.init(self, options) + + local group = vim.api.nvim_create_augroup("CodeCompanionHooks", {}) + + vim.api.nvim_create_autocmd({ "User" }, { + pattern = "CodeCompanionRequest*", + group = group, + callback = function(request) + if request.match == "CodeCompanionRequestStarted" then + self.processing = true + elseif request.match == "CodeCompanionRequestFinished" then + self.processing = false + end + end, + }) +end + +-- Function that runs every time statusline is updated +function M:update_status() + if self.processing then + self.spinner_index = (self.spinner_index % spinner_symbols_len) + 1 + return spinner_symbols[self.spinner_index] + else + return require('lualine.components.location')() + end +end + +require('lualine').setup { + sections = { + lualine_z = {M} + }, + options = { + theme = "catppuccin" + -- theme = "citruszest" + -- theme = "onedark" + -- ... the rest of your lualine config + } + } +