Skip to content

Commit 025ae5f

Browse files
feat: added installation methods
2 parents 451655c + 9217300 commit 025ae5f

File tree

14 files changed

+627
-182
lines changed

14 files changed

+627
-182
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Push changes
2020
uses: stefanzweifel/git-auto-commit-action@v4
2121
with:
22-
commit_message: "auto-generate vimdoc"
22+
commit_message: "docs: auto-generate vimdoc"
2323
commit_user_name: "github-actions[bot]"
2424
commit_user_email: "github-actions[bot]@users.noreply.github.com"
2525
commit_author:

.github/workflows/test.yml

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,42 @@ on:
66
- main
77

88
jobs:
9-
vusted:
10-
name: Run Test
11-
runs-on: ubuntu-latest
9+
run_tests:
10+
name: unit tests
11+
runs-on: ${{ matrix.os }}
1212
strategy:
13+
fail-fast: false
1314
matrix:
14-
nvim-versions: ["stable", "nightly"]
15+
os: [ubuntu-latest, macos-latest, windows-latest]
16+
rev: [nightly, v0.9.0, stable]
17+
1518
steps:
1619
- uses: actions/checkout@v4
20+
- uses: rhysd/action-setup-vim@v1
21+
with:
22+
neovim: true
23+
version: ${{ matrix.rev }}
1724

18-
- name: LuaJIT
25+
- name: Run tests with NeoVim
26+
run: |
27+
export PATH="${PWD}/_neovim/bin:${PATH}"
28+
export VIM="${PWD}/_neovim/share/nvim/runtime"
29+
nvim --version
30+
make test-nvim
31+
32+
- uses: actions/checkout@v4
33+
34+
- name: Install LuaJIT
1935
uses: leafo/gh-actions-lua@v10
2036
with:
2137
luaVersion: "luajit-2.1.0-beta3"
2238

23-
- name: Luarocks
39+
- name: Install Luarocks
2440
uses: leafo/gh-actions-luarocks@v4
2541

2642
- name: Run test with vusted
2743
shell: bash
2844
run: |
2945
luarocks install vusted
30-
make test
31-
32-
run_tests:
33-
name: unit tests
34-
runs-on: ${{ matrix.os }}
35-
strategy:
36-
fail-fast: false
37-
matrix:
38-
include:
39-
- os: ubuntu-22.04
40-
rev: nightly/nvim-linux64.tar.gz
41-
- os: ubuntu-22.04
42-
rev: stable/nvim-linux64.tar.gz
43-
- os: ubuntu-22.04
44-
rev: v0.8.3/nvim-linux64.tar.gz
45-
- os: ubuntu-22.04
46-
rev: v0.9.1/nvim-linux64.tar.gz
47-
steps:
48-
- uses: actions/checkout@v3
49-
- run: date +%F > todays-date
50-
- name: Restore cache for today's nightly.
51-
uses: actions/cache@v3
52-
with:
53-
path: _neovim
54-
key: |
55-
${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}
56-
- name: Prepare
57-
run: |
58-
test -d _neovim || {
59-
mkdir -p _neovim
60-
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
61-
}
62-
63-
- name: Run tests with NeoVim
64-
run: |
65-
export PATH="${PWD}/_neovim/bin:${PATH}"
66-
export VIM="${PWD}/_neovim/share/nvim/runtime"
6746
nvim --version
68-
make test-nvim
47+
make test

Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1+
GREEN="\033[00;32m"
2+
RESTORE="\033[0m"
3+
4+
# mock directory accessible by `vim.env.MOCK_DIR`
5+
MOCK_DIR="./tests/mocks"
6+
7+
# make the output of the message appear green
8+
define style_calls
9+
$(eval $@_msg = $(1))
10+
echo ${GREEN}${$@_msg}
11+
echo ${RESTORE}
12+
endef
13+
114
.PHONY: test test-nvim lint style-lint format
215

316
test:
4-
@printf "%s\nRunning tests using vusted\n"
5-
@vusted ./tests
17+
@$(call style_calls,"Running vusted tests")
18+
@MOCK_DIR=${MOCK_DIR} vusted ./tests
619

720
test-nvim:
8-
@printf "\nRunning tests using nvim\n"
9-
@nvim --headless --noplugin -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/freeze-code {minimal_init = 'tests/minimal_init.lua', sequential = true}"
21+
@$(call style_calls,"Running tests using nvim")
22+
@MOCK_DIR=${MOCK_DIR} nvim --headless --noplugin -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/freeze-code {minimal_init = 'tests/minimal_init.lua'}"
1023

1124
lint: style-lint
12-
@printf "\nRunning selene\n"
25+
@$(call style_calls,"Running selene")
1326
@selene --display-style quiet --config ./selene.toml lua/freeze-code
1427

1528
style-lint:
16-
@printf "\nRunning stylua check\n"
29+
@$(call style_calls,"Running stylua check")
1730
@stylua --color always -f ./stylua.toml --check lua/freeze-code
1831

1932
format:
20-
@printf "\nRunning stylua format\n"
33+
@$(call style_calls,"Running stylua format")
2134
@stylua --color always -f ./stylua.toml lua/freeze-code
2235

2336
all: test test-nvim lint

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ Take a "screenshot" of your code by turning it into an image, thanks to
1717
Using your plugin manager at your disposal, in the example
1818
[lazy](https://github.com/folke/lazy.nvim) is going to be used.
1919

20+
> [!note]
21+
>
22+
> If you don't have [freeze](https://github.com/charmbracelet/freeze) installed,
23+
> and you are have [golang](https://go.dev) installed, it will
24+
> `go install github.com/charmbracelet/freeze@latest` for you 🫡.
25+
>
26+
> In the case that you don't have neither of those, don't you worry 😉, we got you
27+
> cover. It will install `freeze` using `cURL` to the
28+
> [freeze's releases page](https://github.com/charmbracelet/freeze/releases).
29+
2030
- Default installation:
2131

2232
```lua
@@ -28,6 +38,14 @@ return {
2838
}
2939
```
3040

41+
> [!note]
42+
>
43+
> You can also install it using [Rocks.nvim](https://github.com/nvim-neorocks/rocks.nvim)
44+
>
45+
> `:Rocks install freeze-code.nvim`
46+
>
47+
> Also as `luarocks install freeze-code.nvim`
48+
3149
- Customizable installation:
3250

3351
```lua
@@ -45,27 +63,13 @@ return {
4563
> See default configuration below.
4664
4765
```lua
48-
---@class FreezeConfig
49-
---@field output string|"freeze.png": Freeze output filename `--output "freeze.png"`
50-
---@field theme string|"default": Freeze theme `--theme "default"`
51-
---@field config string|"base": Freeze configuration `--config "base"`
52-
53-
---@class CodeSnapshotConfig
54-
---@field freeze_path string: Path to `freeze` executable
55-
---@field copy_cmd string: Path to copy `image/png` to clipboard command
56-
---@field copy boolean: Open image after creation option
57-
---@field open boolean: Open image after creation option
58-
---@field dir string: Directory to create image
59-
---@field freeze_config FreezeConfig
60-
61-
---@type CodeSnapshotConfig
6266
local opts = {
6367
freeze_path = vim.fn.exepath("freeze"), -- where is freeze installed
6468
copy_cmd = "pngcopy", -- the default copy commands are in the bin directory
65-
copy = false,
66-
open = false,
67-
dir = vim.env.PWD,
68-
freeze_config = {
69+
copy = false, -- copy after screenshot option
70+
open = false, -- open after screenshot option
71+
dir = vim.env.PWD, -- where is the image going to be saved "." as default
72+
freeze_config = { -- configuration options for `freeze` command
6973
output = "freeze.png",
7074
config = "base",
7175
theme = "default",

autoload/health/freeze_code.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function! health#freeze_code#check()
2+
lua require("freeze-code.health").check()
3+
endfunction

doc/.gitkeep

Whitespace-only changes.

doc/freeze-code.nvim.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*freeze-code.nvim.txt* For Neovim >= 0.8.0 Last change: 2024 May 12
1+
*freeze-code.nvim.txt* For Neovim >= 0.8.0 Last change: 2024 May 14
22

33
==============================================================================
44
Table of Contents *freeze-code.nvim-table-of-contents*
@@ -14,6 +14,14 @@ INSTALLATION *freeze-code.nvim-installation*
1414
Using your plugin manager at your disposal, in the example lazy
1515
<https://github.com/folke/lazy.nvim> is going to be used.
1616

17+
18+
[!note]
19+
If you don’t have freeze <https://github.com/charmbracelet/freeze> installed,
20+
and you are have golang <https://go.dev> installed, it will `go install
21+
github.com/charmbracelet/freeze@latest` for you.
22+
In the case that you don’t have neither of those, don’t you worry , we got
23+
you cover. It will install `freeze` using `cURL` to the freeze’s releases
24+
page <https://github.com/charmbracelet/freeze/releases>.
1725
- Default installation:
1826

1927
>lua
@@ -25,6 +33,12 @@ Using your plugin manager at your disposal, in the example lazy
2533
}
2634
<
2735

36+
37+
[!note]
38+
You can also install it using Rocks.nvim
39+
<https://github.com/nvim-neorocks/rocks.nvim>
40+
`:Rocks install freeze-code.nvim`
41+
Also as `luarocks install freeze-code.nvim`
2842
- Customizable installation:
2943

3044
>lua
@@ -41,27 +55,13 @@ Using your plugin manager at your disposal, in the example lazy
4155

4256
[!note] See default configuration below.
4357
>lua
44-
---@class FreezeConfig
45-
---@field output string|"freeze.png": Freeze output filename `--output "freeze.png"`
46-
---@field theme string|"default": Freeze theme `--theme "default"`
47-
---@field config string|"base": Freeze configuration `--config "base"`
48-
49-
---@class CodeSnapshotConfig
50-
---@field freeze_path string: Path to `freeze` executable
51-
---@field copy_cmd string: Path to copy `image/png` to clipboard command
52-
---@field copy boolean: Open image after creation option
53-
---@field open boolean: Open image after creation option
54-
---@field dir string: Directory to create image
55-
---@field freeze_config FreezeConfig
56-
57-
---@type CodeSnapshotConfig
5858
local opts = {
5959
freeze_path = vim.fn.exepath("freeze"), -- where is freeze installed
6060
copy_cmd = "pngcopy", -- the default copy commands are in the bin directory
61-
copy = false,
62-
open = false,
63-
dir = vim.env.PWD,
64-
freeze_config = {
61+
copy = false, -- copy after screenshot option
62+
open = false, -- open after screenshot option
63+
dir = vim.env.PWD, -- where is the image going to be saved "." as default
64+
freeze_config = { -- configuration options for `freeze` command
6565
output = "freeze.png",
6666
config = "base",
6767
theme = "default",

lua/freeze-code/commands.lua

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
local M = {}
22

3-
local os_utils = require("freeze-code.utils").os
3+
local utils = require("freeze-code.utils")
4+
local logger = utils.logger
5+
local os_utils = utils.os
46
local is_win = os_utils.is_win
57
local is_macos = os_utils.is_macos
68
-- local is_unix = os_utils.is_unix
@@ -53,7 +55,7 @@ end
5355
---The function called on exit of from the event loop
5456
---@param msg string: Message to display if success
5557
---@return function cb: Schedule wrap callback function
56-
function M.on_exit(msg)
58+
function M.on_exit(msg, opts)
5759
local freeze_code = require("freeze-code")
5860
return vim.schedule_wrap(function(code, _)
5961
if code == 0 then
@@ -64,6 +66,12 @@ function M.on_exit(msg)
6466
if freeze_code.config.copy == true then
6567
freeze_code.copy(freeze_code.config)
6668
end
69+
if opts and opts.freeze then
70+
vim.wait(5000, function()
71+
local image_path = vim.loop.fs_fstat(opts.freeze.output)
72+
return image_path ~= nil
73+
end)
74+
end
6775
stop_job()
6876
end)
6977
end
@@ -84,11 +92,9 @@ end
8492
---@return boolean success: true if executes, false otherwise
8593
function M.check_executable(cmd, path_to_check)
8694
if vim.fn.executable(cmd) == 0 then
87-
vim.api.nvim_err_write(
88-
string.format(
89-
"[freeze-code] could not execute `" .. cmd .. "` binary in path=%s . make sure you have the right config",
90-
path_to_check
91-
)
95+
logger.err_fmt(
96+
"[freeze-code] could not execute `" .. cmd .. "` binary in path=`%s` . make sure you have the right config",
97+
path_to_check
9298
)
9399
return false
94100
end
@@ -113,7 +119,10 @@ local copy_by_os = function(opts)
113119
return os.execute(cmd)
114120
end
115121
cmd = "sh " .. binaries.linux .. " " .. opts.output
116-
os.execute(cmd)
122+
local ok = os.execute(cmd)
123+
if ok then
124+
logger.info_fmt("[freeze-code] image `%s` copied to the clipboard", opts.output)
125+
end
117126
end
118127

119128
M.copy = function(opts)

0 commit comments

Comments
 (0)