Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add function to get visible state #80

Closed
wants to merge 1 commit into from

Conversation

DrummyFloyd
Copy link

@DrummyFloyd DrummyFloyd commented Jul 16, 2024

pretty usefull when u want to ad some stuff upon state

allow to do something like this

-- Plugin configuration
return {
  {
    "DrummyFloyd/precognition.nvim",
    event = "VeryLazy",
    branch = "add-visble-getter",
    opts = {
      startVisible = false,
    },
    keys = function()
      local p = require("precognition")
      LazyVim.toggle.map("<leader>uP", {
        name = "Precognition",
        get = function()
          return p.visibleState()
        end,
        set = function()
          p.toggle()
        end,
      })
    end,
  },
}

@tris203
Copy link
Owner

tris203 commented Jul 16, 2024

Thanks for the PR @DrummyFloyd

I don't use LazyVim the distro. Do you have any links for the benefits of this.

The toggle function returns the status so couldn't this be encapsulated with a local within the keys function within config?

@DrummyFloyd
Copy link
Author

DrummyFloyd commented Jul 16, 2024

Thanks for the PR @DrummyFloyd

I don't use LazyVim the distro. Do you have any links for the benefits of this.

The toggle function returns the status so couldn't this be encapsulated with a local within the keys function within config?

=> yes ofc i could do this instead

it's more or less a whim (purely UI stuff, if you don't want this getter i totally understand, even if, it could be always usefull in other cases) :D

becasue Folke (Creator of Many nVim stuff ) , introduced a LazyVim.toggle function which lead to an icon for off/sate

and the get function use a bool value for the state

20240716_14h59m38s_grim
20240716_14h59m24s_grim

@tris203
Copy link
Owner

tris203 commented Jul 16, 2024

I requested changes in a previous PR about this same issue

#73 (review)

I will think about this

@tris203
Copy link
Owner

tris203 commented Jul 22, 2024

I have given this some thought and the best middle ground is to expose it via the metatable, meaning there is no additional overhead to maintain, but the function/value is available.

If you are happy to modify this PR to do it that, I would be happy to accept it. @DrummyFloyd

@DrummyFloyd
Copy link
Author

I have given this some thought and the best middle ground is to expose it via the metatable, meaning there is no additional overhead to maintain, but the function/value is available.

If you are happy to modify this PR to do it that, I would be happy to accept it. @DrummyFloyd

so you mean somethings like this ? ( not very aware of LUA good practice )

diff --git a/lua/precognition/init.lua b/lua/precognition/init.lua
index bbd18ddf0cb1..0b51ce425050 100644
--- a/lua/precognition/init.lua
+++ b/lua/precognition/init.lua
@@ -324,7 +324,7 @@ local function create_command()
         toggle = M.toggle,
         show = M.show,
         hide = M.hide,
-        visibleState = M.visibleState,
+        visibleState = visible,
     }
 
     local function execute(args)
@@ -396,11 +396,6 @@ function M.show()
     display_marks()
 end
 
---- Return the current visibility state
-function M.visibleState()
-    return visible
-end
-
 --- Disable automatic showing of hints
 function M.hide()
     if not visible then

@tris203
Copy link
Owner

tris203 commented Jul 24, 2024

no, you would just add something like

    is_visible = function()
        return visible
    end,

around line 467

all the other changes can be reverted

a-usr added a commit to a-usr/precognition.nvim that referenced this pull request Oct 30, 2024
@tris203 tris203 closed this in #92 Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants