goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.78k stars 104 forks source link

Provide an interface to get current_state #171

Open guoang opened 1 year ago

guoang commented 1 year ago

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
goolord commented 1 year ago

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

guoang commented 1 year ago

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.

goolord commented 1 year ago

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 commented 1 year ago

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

avegancafe commented 9 months ago

@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