Skip to content

Commit

Permalink
feat: added installation methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero authored May 14, 2024
2 parents 451655c + 9217300 commit 025ae5f
Show file tree
Hide file tree
Showing 14 changed files with 627 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Push changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "auto-generate vimdoc"
commit_message: "docs: auto-generate vimdoc"
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
commit_author:
Expand Down
67 changes: 23 additions & 44 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,42 @@ on:
- main

jobs:
vusted:
name: Run Test
runs-on: ubuntu-latest
run_tests:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
nvim-versions: ["stable", "nightly"]
os: [ubuntu-latest, macos-latest, windows-latest]
rev: [nightly, v0.9.0, stable]

steps:
- uses: actions/checkout@v4
- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.rev }}

- name: LuaJIT
- name: Run tests with NeoVim
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
make test-nvim
- uses: actions/checkout@v4

- name: Install LuaJIT
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"

- name: Luarocks
- name: Install Luarocks
uses: leafo/gh-actions-luarocks@v4

- name: Run test with vusted
shell: bash
run: |
luarocks install vusted
make test
run_tests:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
rev: nightly/nvim-linux64.tar.gz
- os: ubuntu-22.04
rev: stable/nvim-linux64.tar.gz
- os: ubuntu-22.04
rev: v0.8.3/nvim-linux64.tar.gz
- os: ubuntu-22.04
rev: v0.9.1/nvim-linux64.tar.gz
steps:
- uses: actions/checkout@v3
- run: date +%F > todays-date
- name: Restore cache for today's nightly.
uses: actions/cache@v3
with:
path: _neovim
key: |
${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}
- name: Prepare
run: |
test -d _neovim || {
mkdir -p _neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
- name: Run tests with NeoVim
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
make test-nvim
make test
27 changes: 20 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
GREEN="\033[00;32m"
RESTORE="\033[0m"

# mock directory accessible by `vim.env.MOCK_DIR`
MOCK_DIR="./tests/mocks"

# make the output of the message appear green
define style_calls
$(eval $@_msg = $(1))
echo ${GREEN}${$@_msg}
echo ${RESTORE}
endef

.PHONY: test test-nvim lint style-lint format

test:
@printf "%s\nRunning tests using vusted\n"
@vusted ./tests
@$(call style_calls,"Running vusted tests")
@MOCK_DIR=${MOCK_DIR} vusted ./tests

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

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

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

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

all: test test-nvim lint
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Take a "screenshot" of your code by turning it into an image, thanks to
Using your plugin manager at your disposal, in the example
[lazy](https://github.com/folke/lazy.nvim) is going to be used.

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

```lua
Expand All @@ -28,6 +38,14 @@ return {
}
```

> [!note]
>
> You can also install it using [Rocks.nvim](https://github.com/nvim-neorocks/rocks.nvim)
>
> `:Rocks install freeze-code.nvim`
>
> Also as `luarocks install freeze-code.nvim`
- Customizable installation:

```lua
Expand All @@ -45,27 +63,13 @@ return {
> See default configuration below.
```lua
---@class FreezeConfig
---@field output string|"freeze.png": Freeze output filename `--output "freeze.png"`
---@field theme string|"default": Freeze theme `--theme "default"`
---@field config string|"base": Freeze configuration `--config "base"`

---@class CodeSnapshotConfig
---@field freeze_path string: Path to `freeze` executable
---@field copy_cmd string: Path to copy `image/png` to clipboard command
---@field copy boolean: Open image after creation option
---@field open boolean: Open image after creation option
---@field dir string: Directory to create image
---@field freeze_config FreezeConfig

---@type CodeSnapshotConfig
local opts = {
freeze_path = vim.fn.exepath("freeze"), -- where is freeze installed
copy_cmd = "pngcopy", -- the default copy commands are in the bin directory
copy = false,
open = false,
dir = vim.env.PWD,
freeze_config = {
copy = false, -- copy after screenshot option
open = false, -- open after screenshot option
dir = vim.env.PWD, -- where is the image going to be saved "." as default
freeze_config = { -- configuration options for `freeze` command
output = "freeze.png",
config = "base",
theme = "default",
Expand Down
3 changes: 3 additions & 0 deletions autoload/health/freeze_code.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function! health#freeze_code#check()
lua require("freeze-code.health").check()
endfunction
Empty file removed doc/.gitkeep
Empty file.
38 changes: 19 additions & 19 deletions doc/freeze-code.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*freeze-code.nvim.txt* For Neovim >= 0.8.0 Last change: 2024 May 12
*freeze-code.nvim.txt* For Neovim >= 0.8.0 Last change: 2024 May 14

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


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

>lua
Expand All @@ -25,6 +33,12 @@ Using your plugin manager at your disposal, in the example lazy
}
<


[!note]
You can also install it using Rocks.nvim
<https://github.com/nvim-neorocks/rocks.nvim>
`:Rocks install freeze-code.nvim`
Also as `luarocks install freeze-code.nvim`
- Customizable installation:

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

[!note] See default configuration below.
>lua
---@class FreezeConfig
---@field output string|"freeze.png": Freeze output filename `--output "freeze.png"`
---@field theme string|"default": Freeze theme `--theme "default"`
---@field config string|"base": Freeze configuration `--config "base"`

---@class CodeSnapshotConfig
---@field freeze_path string: Path to `freeze` executable
---@field copy_cmd string: Path to copy `image/png` to clipboard command
---@field copy boolean: Open image after creation option
---@field open boolean: Open image after creation option
---@field dir string: Directory to create image
---@field freeze_config FreezeConfig

---@type CodeSnapshotConfig
local opts = {
freeze_path = vim.fn.exepath("freeze"), -- where is freeze installed
copy_cmd = "pngcopy", -- the default copy commands are in the bin directory
copy = false,
open = false,
dir = vim.env.PWD,
freeze_config = {
copy = false, -- copy after screenshot option
open = false, -- open after screenshot option
dir = vim.env.PWD, -- where is the image going to be saved "." as default
freeze_config = { -- configuration options for `freeze` command
output = "freeze.png",
config = "base",
theme = "default",
Expand Down
25 changes: 17 additions & 8 deletions lua/freeze-code/commands.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local M = {}

local os_utils = require("freeze-code.utils").os
local utils = require("freeze-code.utils")
local logger = utils.logger
local os_utils = utils.os
local is_win = os_utils.is_win
local is_macos = os_utils.is_macos
-- local is_unix = os_utils.is_unix
Expand Down Expand Up @@ -53,7 +55,7 @@ end
---The function called on exit of from the event loop
---@param msg string: Message to display if success
---@return function cb: Schedule wrap callback function
function M.on_exit(msg)
function M.on_exit(msg, opts)
local freeze_code = require("freeze-code")
return vim.schedule_wrap(function(code, _)
if code == 0 then
Expand All @@ -64,6 +66,12 @@ function M.on_exit(msg)
if freeze_code.config.copy == true then
freeze_code.copy(freeze_code.config)
end
if opts and opts.freeze then
vim.wait(5000, function()
local image_path = vim.loop.fs_fstat(opts.freeze.output)
return image_path ~= nil
end)
end
stop_job()
end)
end
Expand All @@ -84,11 +92,9 @@ end
---@return boolean success: true if executes, false otherwise
function M.check_executable(cmd, path_to_check)
if vim.fn.executable(cmd) == 0 then
vim.api.nvim_err_write(
string.format(
"[freeze-code] could not execute `" .. cmd .. "` binary in path=%s . make sure you have the right config",
path_to_check
)
logger.err_fmt(
"[freeze-code] could not execute `" .. cmd .. "` binary in path=`%s` . make sure you have the right config",
path_to_check
)
return false
end
Expand All @@ -113,7 +119,10 @@ local copy_by_os = function(opts)
return os.execute(cmd)
end
cmd = "sh " .. binaries.linux .. " " .. opts.output
os.execute(cmd)
local ok = os.execute(cmd)
if ok then
logger.info_fmt("[freeze-code] image `%s` copied to the clipboard", opts.output)
end
end

M.copy = function(opts)
Expand Down
Loading

0 comments on commit 025ae5f

Please sign in to comment.