alpha-nvim icon indicating copy to clipboard operation
alpha-nvim copied to clipboard

Provide an interface to get current_state

Open guoang opened this issue 2 years ago • 5 comments

I'm trying to write my own theme and need this interface.

diff --git a/lua/alpha.lua b/lua/alpha.lua
index 9fa8e70..69e7205 100644
--- a/lua/alpha.lua
+++ b/lua/alpha.lua
@@ -671,6 +671,10 @@ function alpha.setup(config)
     })
 end
 
+function alpha.get_state()
+    return current_state
+end
+
 alpha.layout_element = layout_element
 alpha.keymaps_element = keymaps_element

guoang avatar Jan 30 '23 04:01 guoang

i believe lua tables are passed by reference so alpha.current_state = current_state would suffice, can i ask what you're trying to do? just out of curiosity

goolord avatar Jan 30 '23 06:01 goolord

i believe lua tables are passed by reference so alpha.current_state = current_state would suffice, can i ask what you're trying to do? just out of curiosity

This looks good to me too. What I need is to access current_state in my vim config, I currently can't do that since current_state is a local variable.

guoang avatar Jan 30 '23 08:01 guoang

the reason i'm asking what specifically you're trying to do is because you can already access the state by extending the layout_element and keymaps_element tables which is a bit more principled. if you're not actually defining a new element type then i'm curious y you need the state.

goolord avatar Feb 07 '23 03:02 goolord

also the api just changed a little to accommodate multiple concurrent alpha configs

https://github.com/goolord/alpha-nvim/blob/main/lua/alpha.lua#L17-L18

but this could still be done

goolord avatar Feb 07 '23 04:02 goolord

@goolord for context I'm looking into this too, the reason I want the state available would be because when I open a new session I want to be able to say "If and only if alpha is not already open, open alpha", since the start command also closes alpha and is more of a toggle. Alternatively, making start idempotent would also work

avegancafe avatar Oct 25 '23 21:10 avegancafe