charm-freeze.nvim icon indicating copy to clipboard operation
charm-freeze.nvim copied to clipboard

[Suggestion]: porting extra functionalities

Open AlejandroSuero opened this issue 1 year ago • 10 comments

I made freeze-code.nvim not knowing there was an official plugin from charm-and-friends and I have some extra functionality that may be interested to port, if you are interested of course.

Functionalities:

  • :checkhealth command
  • Downloading freeze if not installed (via go install or native download from github releases and unzipping.
  • Ability to copy image after the screenshot is created (natively or via a third party tool like gclip).
  • Use freeze on selected text or just a line.

Developer side*:

  • Addition of selene or luacheck, can be also included in CI (I prefer selene because it is being maintained and have a more human approach for rules).
  • Adding types to improve lsp.

AlejandroSuero avatar Sep 05 '24 13:09 AlejandroSuero

I think that sounds cool! Ultimately, that's a question for @isabelroses, the maintainer. Whatcha think, Isabel?

meowgorithm avatar Sep 05 '24 17:09 meowgorithm

@meowgorithm @isabelroses one thing that I forgot to mention it's that apart from copying the image being a feature that once implemented with https://github.com/charmbracelet/freeze/pull/97, it could be added the functionality of opening the image once is written.

I leave a quick demo here showcasing it:

https://github.com/user-attachments/assets/095995eb-f8cf-40f6-acd3-a63a47daf05f

[!note] As you can see, selecting the line you want and then using, in my case, <leader>fz freeze freeze gets executed and when it's finished, it opens the image.

The :checkhealth command, displays the following:

==============================================================================
freeze-code: require("freeze-code.health").check()

Checking for external dependencies ~
- OK Freeze: found! version: `(unknown)`
- OK GoLang: found! version: `go version go1.23.0 darwin/arm64`
- OK cURL: found! version: `curl 8.7.1 (x86_64-apple-darwin23.0) libcurl/8.7.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.61.0`
- OK tar: found! version: `bsdtar 3.5.3 - libarchive 3.5.3 zlib/1.2.12 liblzma/5.4.3 bz2lib/1.0.8 `
- OK Osascript: found! version: `(unknown)`
- OK xclip: found! version: `(unknown)`
- OK gclip: found! version: `(unknown)`
- OK open: found! version: `(unknown)`

==================================================================================== ~

[!note] The requirements may vary depending on the OS, for example:

In Windows it won't use xclip or tar, so this ones won't show up, the same goes for osascript, being needed only by MacOS.

AlejandroSuero avatar Sep 05 '24 18:09 AlejandroSuero

  • :checkhealth command
  • Addition of selene or luacheck, can be also included in CI (I prefer selene because it is being maintained and have a more human approach for rules).
  • Adding types to improve lsp.

These seems like a great ideas to implement!

  • Downloading freeze if not installed (via go install or native download from github releases and unzipping.

I don't think this is worth implementing. The idea seems nice but not worth the effort.

  • Ability to copy image after the screenshot is created (natively or via a third party tool like gclip).

As you already mentioned with your other comment, it maybe better to wait on https://github.com/charmbracelet/freeze/pull/97.

  • Use freeze on selected text or just a line.

This is already a feature :)

isabelroses avatar Sep 05 '24 18:09 isabelroses

@isabelroses Do you want the open command?

Also, in mine I have an option dir to save the files in an specific location, defaulted to the current pwd. This is because for my use case I have a directory for screenshots and screen-recordings, but if you think is not a necessary addition I understand.

AlejandroSuero avatar Sep 05 '24 18:09 AlejandroSuero

@isabelroses Do you want the open command?

What does that do?

Also, in mine I have an option dir to save the files in an specific location, defaulted to the current pwd. This is because for my use case I have a directory for screenshots and screen-recordings, but if you think is not a necessary addition I understand.

You can use the output option for this with this plugin.

isabelroses avatar Sep 05 '24 19:09 isabelroses

Did my best attempt at adding some of those features.

isabelroses avatar Sep 05 '24 19:09 isabelroses

The open command it will open the image created after writing it on disk.

https://github.com/user-attachments/assets/5da8f0c1-9e5b-4a7a-a5fc-02f60b5767fb

Comes in handy to check the image instead of going to the terminal or explorer and finding it, specially in the cases where you have it in another directory. Also at least in MacOS, in the preview you can copy it so it saves the action.

This can be pass through an option or, for example, checking the arguments passed when using vim.cmd.Freeze or :Freeze, if passed open=true, it will open it. The ladder could be better so it doesn't open every time and just when using a keymap like <leader><leader>sc instead of <leader>sc for the current behaviour.

AlejandroSuero avatar Sep 05 '24 19:09 AlejandroSuero

Use freeze on selected text or just a line.

This is already a feature :)

@isabelroses but how do you implement this? vim.api.nvim_set_keymap('v', '<leader>sc', '<cmd>Freeze<cr>', {}) here the Freeze command takes the screenshot of the whole buffer.

how do you take the screenshot of some lines in the buffer?

dpi0 avatar Apr 14 '25 15:04 dpi0

Use freeze on selected text or just a line.

This is already a feature :)

@isabelroses but how do you implement this? vim.api.nvim_set_keymap('v', '<leader>sc', '<cmd>Freeze<cr>', {}) here the Freeze command takes the screenshot of the whole buffer.

how do you take the screenshot of some lines in the buffer?

Using visual mode highlight your selected lines and use the freeze command.

isabelroses avatar Apr 14 '25 15:04 isabelroses

okay so i've realized that <cmd>Freeze<cr> and :Freeze<cr> will produce different results.

<cmd>Freeze<cr> apparently discards the visual selection and uses the whole buffer. while :Freeze<cr> preserves it.

project's README.md uses <cmd>Freeze<cr> causing the confusion.

should there be a PR for this change to README.md?

here's my lua table for reference:

return {
  'charm-and-friends/freeze.nvim',
  keys = {
    {
      '<leader>sc',
      ':Freeze<cr>',
      mode = 'v',
      desc = 'Screenshot Code',
      silent = true,
    },
  },
  config = function()
    require('freeze').setup {
      command = 'freeze',
      open = true,
      output = function()
        local home = os.getenv 'HOME'
        local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ':t'):gsub('%s+', '_')
        return string.format('%s/Screenshots/%s_(%s)_(%s).png', home, filename, os.date '%H-%M-%S', os.date '%d-%b')
      end,
      font = {
        family = 'JetBrains Mono Nerd Font',
        size = 16,
      },
      padding = '20',
      theme = 'gruvbox',
      line_height = 1.4,
      show_line_numbers = true,
      window = true,
    }
  end,
}

dpi0 avatar Apr 14 '25 15:04 dpi0