Skip to content

Conversation

@benlubas
Copy link
Collaborator

@benlubas benlubas commented Jan 10, 2024

closes #20

Features

  • Allows users to pass a hint to a hydra when config.hint.type = "statusline". The hint is parsed and highlighted using the same rules as window hints
  • Adds "statuslinemanual" hint type to enable passing a hint string while not automatically showing a hint in the status line (the same way setting config.hint = false does for a normal auto generated status line. Issue is when you pass a hint, the type is assumed to be window, so we need this new type if we don't want to change behavior).

Done in two steps if you would like to review the PR that way:

  • chore: window hint parsing
  • feat: custom status line hints

This PR also fixes a few README problems that I found, and adds an .editorconfig file b/c the majority of the codebase uses 3-space tabs so I'm setting that as the default.

This PR does not currently append unused heads to the end of a manual status line hint. I can add that I guess if we care to be consistent.

Example of what you can now do:
Hydra({
  name = "QuartoNavigator",
  hint = "_j_/_k_: ↑/↓ | _o_/_O_: new cell ↓/↑ | _l_: run | _s_how | _h_ide | run _a_bove | _q_uit",
  config = {
    color = "pink",
    invoke_on_body = true,
    hint = {
      type = "statuslinemanual",
    },
  },
  mode = { "n" },
  body = "<localleader>j",
  heads = {
    { "j", keys("]b"), { desc = "" } },
    { "k", keys("[b"), { desc = "" } },
    { "o", keys("/```<CR>:nohl<CR>o<CR>`<c-j>"), { desc = "new cell ↓", exit = true } },
    { "O", keys("?```.<CR>:nohl<CR><leader>kO<CR>`<c-j>"), { desc = "new cell ↑", exit = true } },
    { "l", ":QuartoSend<CR>", { desc = "run" } },
    { "s", ":noautocmd MoltenEnterOutput<CR>", { desc = "show" } },
    { "h", ":MoltenHideOutput<CR>", { desc = "hide" } },
    { "a", ":QuartoSendAbove<CR>", { desc = "run above" } },
    { "<esc>", nil, { exit = true, desc = false } },
    { "q", nil, { exit = true, desc = false } },
  },
})

-- in addition to some status line code which calls `require("hydra.statusline").get_hint()`

image

TODO:

  • Function Values in the status line

@benlubas benlubas changed the title chore: window hint parsing feat: custom status line hints Jan 10, 2024
@benlubas benlubas marked this pull request as ready for review January 10, 2024 14:58
@benlubas benlubas requested a review from miversen33 January 10, 2024 14:59
@miversen33
Copy link
Collaborator

I will try to get to this this evening. My initial gut reaction to this is "do we really need a way to set things in the statusline?" though lol.

A quick read through the code and it looks fine. If I am understanding what it is doing properly, this is generating a statusline compatible string for you but not inserting it into the statusline. Is that correct?

As an additional question, is there currently a way to retrieve this statusline hint without the statusline specific string wrapping? I am thinking about lualine users which would just want the literal string to embed in their lualine since lualine performs the proper statusline "wrapping" for them. If my understanding is correct, this would not be usable with something like lualine.

I will find out tonight, but you may have an answer before then :)

@benlubas
Copy link
Collaborator Author

do we really need a way to set things in the statusline

There's already a way, but there was only a way to put auto generated hints in the status line. this just adds support for custom hint strings.

If I am understanding what it is doing properly, this is generating a statusline compatible string for you but not inserting it into the statusline. Is that correct?

It can do both. If you pass a hint with config.hint.type = "statusline" then the Hydra plugin will replace the status line automatically (and restore it when the hydra exits). If you pass a hint with config.hint.type = "statuslinemanual" then the status line is not automatically replaced and you can use require("hydra.statusline").get_hint() to get the status line string to put into your own status line "manually".

a way to retrieve this statusline hint without the statusline specific string wrapping ... lualine users which would just want the literal string

there's the get_hint() method but that does return the string wrapped with highlights and stuff. Lualine should be able to display the wrapped string properly, I can test it quickly. I use MunifTanjim/nougat.nvim and that doesn't have trouble with it.

There is no way to get it without the wrapping.

@benlubas
Copy link
Collaborator Author

benlubas commented Jan 10, 2024

Yup, lualine will display the wrapped string properly:

image

local hydra_hint = function()
  local hint = require("hydra.statusline").get_hint()
  if hint == nil then
    return ""
  end
  return hint
end

-- inside lualine config:
lualine_c = { hydra_hint },

@miversen33
Copy link
Collaborator

Perfect! I'll give this the ole once over after work but my quick glance through, it all looked good :)

@miversen33
Copy link
Collaborator

I don't use the statusline mode as is so I cannot speak to how well this works in comparison to that. I do wonder if it makes sense to replace the "non-manual" version with something that just talks to this instead (to avoid duplicate/similar logic).

Thoughts on that? I could be completely off base as well.

Outside that, this looks good. Once I hear your thoughts on my question I have no issue merging this :)

@benlubas
Copy link
Collaborator Author

I do wonder if it makes sense to replace the "non-manual" version with something that just talks to this instead

like some code that generates a default hint string (something like: _h_: description, _j_: description) and passes it to the same class that would parse a "user entered" hint string?

That could be nice, but this would kinda flip some of the current inheritance on its head I think. I can look into it maybe later today or tomorrow, but I'd be okay with merging it in its current state as well.

@miversen33
Copy link
Collaborator

Ya I am just thinking, we currently have 2 ways to generate statusline text. Acknowledging my little knowledge there I figure it makes sense that we have 1 way to generate statusline text and the wrap that with something to auto inject it into the statusbar or whatever the "auto" statusline config option does.

For now this is fine, but it probably makes sense to clean that cruft up a bit. In either case, I am fine merging this :)

@miversen33 miversen33 merged commit 56cf39c into nvimtools:main Jan 11, 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.

[feature request] Custom hint strings in the status line

2 participants