linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
378 stars 40 forks source link

Improve the usage of VenvSelect on smaller screens #139

Open rodhash opened 3 weeks ago

rodhash commented 3 weeks ago

Hi

New version looks very very nice, thanks and kudos

This isn't an issue per se, but I noticed that the type (or source) shows up only when I have my terminal in full screen .. this isn't visible when I have my temrinal in normal size or snapped to the left / right of my monitor..

Is this expected? I find this piece of info very nice to have but most of the time I'm not using the terminal in full screen.

image
linux-cultist commented 3 weeks ago

I agree, it would be nice if the UI could take into account screen size and adapt to it. I would like it to be visible even when the terminal is snapped to a side, at least on most normal resolutions.

Let me see if I can make the UI a bit smarter, it's a good idea. :)

linux-cultist commented 3 weeks ago

Update the plugin now and see if it looks better?

tranbinh1604 commented 3 weeks ago

CleanShot 2024-06-07 at 22 10 18

mine after updated, I can not see the right project folder at all, also don't know which one to activate

linux-cultist commented 3 weeks ago

Its because you have so long paths and the window is smaller so it doesnt really fit.

You can replace the entire first part of your results with something much shorter by adding a callback function that gets called by VenvSelect for each result it finds. Here is an example you can put in your config to play with.

Dont forget to set the option at the end to actually call the function too. :)

  {
    "linux-cultist/venv-selector.nvim",
    dependencies = {
      "neovim/nvim-lspconfig",
      { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim" } },
      "mfussenegger/nvim-dap",
      "mfussenegger/nvim-dap-python",
    },
    lazy = false,
    branch = "regexp",
    config = function()

      local function shorter_name(filename)
        -- Define replacements as key-value pairs
        local replacements = {
          ["/Users/binhtt/Library/Mobile Documents/com~apple~CloudDocs/Coding"] = ".../Coding",
        }

        -- Loop through the table and replace each found path with its specific replacement
        for path, replacement in pairs(replacements) do
          filename = string.gsub(filename, path, replacement)
        end

        return filename
      end

      require("venv-selector").setup {
        settings = {
          options = {
            on_telescope_result_callback = shorter_name,
          },
        },
      }
    end,
    keys = {
      { ",v", "<cmd>VenvSelect<cr>" },
    },
  },
linux-cultist commented 3 weeks ago

I should probably add some built-in way to limit the result length as well. Normally its much more useful to see the end of the path rather than the beginning of the path, if there is not enough space to show it all.

rodhash commented 3 weeks ago

Thanks for the prompt feedback .. 2 things:

  1. I've updated my plugin to the latest version but I see no change regarding the placement of the type:
image

For me it still showing up only when full screen.

  1. I liked the callback idea but it seems to not be working for me however I managed to shorten my path using a little bit of sed:
          search = {
            venvs = {
              command = "fd python$ ~/venv -I -L -E /proc | sed 's/.*venv/foobar/g'",
              type = "pyenv"
            },
    ...
    image

With paths shortened I still can't see the type .. it shows up only with terminal in full screen

linux-cultist commented 3 weeks ago

I even tested the code above, it worked fine for me (but different path or course). It's possible that the tilde characters in the paths are not liked by lua though. If I had to guess, it's something like that. Using sed works but it will be slower.

The actual column where the type shows up is set to a specific width so I guess it's outside of the terminal width if it doesnt show up. Maybe a good idea to make this configurable in a setting since it doesn't seem like the telescope viewer can adapt the column width dynamically.

If you had a setting where you could set a number where the column would start, you could find a setting that works for you in the end.

I will experiment a bit with this later. 👍