diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..5dafa14 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @AlejandroSuero diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..739cfaa --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,129 @@ +name: Bug Report +description: Report a problem with freeze-code.nvim +title: "[Bug]: " +labels: + - bug + +body: + - type: markdown + attributes: + value: | + # Before reporting + + - Confirm that the problem is reproducible. + - Try using the [minimal reproduction template](https://github.com/AlejandroSuero/freeze-code.nvim/blob/main/contrib/minimal.lua). + + - type: checkboxes + id: pre-requisites + attributes: + label: Pre-requisites + description: Make sure to check to see if you are following this requisites. + options: + - label: The issue is reproducible + required: true + - label: The aren't other issues similar to this problem. + required: true + - label: The aren't PRs tackling this problem. + required: true + + - type: markdown + attributes: + value: | + ## Issue report + + - type: textarea + id: nvim-version + attributes: + label: NeoVim version + description: Paste here your NeoVim version, `nvim --version`. + placeholder: | + NVIM v0.9.5 + Build type: RelWithDebInfo + LuaJIT 2.1.1692716794 + validations: + required: true + + - type: dropdown + id: operative-system + attributes: + label: Operative system + description: OS in which the issue occurs + multiple: true + options: + - Windows + - MacOS + - Linux + - Android + - All systems + validations: + required: true + + - type: textarea + id: os-version + attributes: + label: OS version + description: OS version in which the issue occurs + placeholder: | + MacOS 14.4.1 + Windows 11 + Ubuntu 22.04 + ... + validations: + required: true + + - type: textarea + id: issue-behaviour + attributes: + label: Behaviour + description: Describe the current behaviour. May include logs, images, videos ... + validations: + required: true + + - type: textarea + id: repro-steps + attributes: + label: Steps to reproduce + description: List the steps to reproduce the behaviour mentioned above. + placeholder: | + 1. `nvim --clean -u minimal.lua` + 2. Go to ... + 3. Use ... + ... + validations: + required: true + + - type: textarea + id: minimal-config + attributes: + label: Minimal config + description: Minimal configuration to reproduce this behaviour. + render: lua + value: | + vim.cmd([[set runtimepath=$VIMRUNTIME]]) + vim.cmd([[set packpath=/tmp/nvim/]]) + + local lazypath = "/tmp/nvim/lazy/lazy.nvim" + if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) + end + vim.opt.rtp:prepend(lazypath) + + require("lazy").setup({ + { + "AlejandroSuero/freeze-code.nvim", + config = function() + require("freeze-code").setup() + end, + lazy = false, + enabled = true, + }, + }) + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..778330b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[Feat]: " +labels: enhancement +assignees: "" +--- + +## Is your feature request related to a problem? Please describe + +A clear and concise description of what the problem is. Ex. I'm always frustrated +when [...] + +## Describe the solution you'd like + +A clear and concise description of what you want to happen. + +## Describe alternatives you've considere + +A clear and concise description of any alternative solutions or features you've considered. + +## Additional context + +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..731d30d --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,36 @@ +# Description + +Please include a summary of the change and which issue is fixed. Please also +include relevant motivation and context + +Fixes # (issue) + +## Type of change + +Please delete options that are not relevant. + +- Bug fix (non-breaking change which fixes an issue) +- New feature (non-breaking change which adds functionality) +- Breaking change (fix or feature that would cause existing functionality to not + work as expected) +- This change requires a documentation update + +## How Has This Been Tested? + +Please describe the tests that you ran to verify your changes. Provide +instructions so we can reproduce. Please also list relevant details about your configuration + +- [ ] Test A +- [ ] Test B + +**Configuration**: + +- Neovim version (`nvim --version`): +- Operating system and version: + +## Checklist + +- [ ] My code follows the style guidelines of this project (stylua) +- [ ] I have performed a self-review of my own code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000..6690d72 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,15 @@ +name: commitlint + +on: [pull_request] + +jobs: + lint-commits: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: npm install --save-dev @commitlint/{cli,config-conventional} + - run: | + echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js + - run: npx commitlint --from HEAD~1 --to HEAD --verbose diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..48244eb --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,26 @@ +name: docs + +on: ["push", "pull_request"] + +jobs: + docs: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Generating docs with panvimdoc + uses: kdheepak/panvimdoc@main + with: + vimdoc: freeze-code.nvim + version: "Neovim >= 0.8.0" + demojify: true + treesitter: true + - name: Push changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "auto-generate vimdoc" + commit_user_name: "github-actions[bot]" + commit_user_email: "github-actions[bot]@users.noreply.github.com" + commit_author: + "github-actions[bot] " diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..bfcf5bb --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,29 @@ +name: lint + +on: ["push", "pull_request"] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Run selene + uses: NTBBloodbath/selene-action@v1.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --display-style quiet lua/freeze-code + + style-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Lint with stylua + uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --check . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..eaca7c0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,21 @@ +name: "release" +on: + push: + tags: + - "*" +jobs: + luarocks-upload: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: LuaRocks Upload + uses: nvim-neorocks/luarocks-tag-release@v5 + env: + LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} + with: + summary: | + A code snapshot plugin using freeze. + detailed_description: | + This plugin allows you to take a "screenshot" of your code, + thanks to freeze by charm.sh. + licence: "MIT/X11" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f5bbe5e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,68 @@ +name: test + +on: + pull_request: + branches: + - main + +jobs: + vusted: + name: Run Test + runs-on: ubuntu-latest + strategy: + matrix: + nvim-versions: ["stable", "nightly"] + steps: + - uses: actions/checkout@v4 + + - name: LuaJIT + uses: leafo/gh-actions-lua@v10 + with: + luaVersion: "luajit-2.1.0-beta3" + + - name: 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..26def9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +# Compiled Lua sources +luac.out + +# luarocks build files +*.src.rock +*.zip +*.tar.gz + +# Object files +*.o +*.os +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo +*.def +*.exp + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +build/ +doc/tags diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..5188494 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "diagnostics": { + "unusedLocalExclude": ["_*"] + } +} diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..24cdada --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,18 @@ +{ + "default": true, + "MD033": false, + "MD052": false, + "MD041": false, + "MD004": { + "style": "dash" + }, + "MD046": { + "style": "fenced" + }, + "MD030": { + "ul_single": 1, + "ol_single": 1, + "ul_multi": 1, + "ol_multi": 1 + } +} diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..c975a33 --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,10 @@ +rules: + document-end: disable + document-start: + level: warning + present: false + line-length: + level: warning + max: 80 + allow-non-breakable-words: true + allow-non-breakable-inline-mappings: true diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..39edbe4 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 AlejandroSuero [AoMe · 青目] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2c54cc7 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +.PHONY: test test-nvim lint style-lint format + +test: + @printf "\nRunning tests using vusted\n" + 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}" + +lint: style-lint + @printf "\nRunning selene\n" + selene --display-style quiet --config ./selene.toml lua/freeze-code + +style-lint: + @printf "\nRunning stylua check\n" + stylua --color always -f ./stylua.toml --check lua/freeze-code + +format: + @printf "\nRunning stylua format\n" + stylua --color always -f ./stylua.toml lua/freeze-code + +all: test test-nvim lint diff --git a/README.md b/README.md new file mode 100644 index 0000000..ca3adae --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ + + +
+ +# Freeze NeoVim Plugin + +Take a "screenshot" of your code by turning it into an image, thanks to +[freeze](https://github.com/charmbracelet/freeze) by [charm](https://charm.sh/). + +[Report an issue](https://github.com/AlejandroSuero/freeze-code.nvim/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml&title=%5BBug%5D%3A+) +· [Suggest a feature](https://github.com/AlejandroSuero/freeze-code.nvim/issues/new?assignees=&labels=enhancement&projects=&template=feature_request.md&title=%5BFeat%5D%3A+) + +
+ +## Installation + +Using your plugin manager at your disposal, in the example +[lazy](https://github.com/folke/lazy.nvim) is going to be used. + +- Default installation: + +```lua +return { + "AlejandroSuero/freeze-code.nvim", + config = function() + require("freeze-code").setup() + end, +} +``` + +- Customizable installation: + +```lua +return { + "AlejandroSuero/freeze-code.nvim", + config = function() + require("freeze-code.nvim").setup({ + -- your configuration goes here + }) + end, +} +``` + +> [!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 = { + output = "freeze.png", + config = "base", + theme = "default", + }, +} +``` + +> [!note] +> The commands to copy, as defaults per OS will be in the +> [bin-directory](https://github.com/AlejandroSuero/freeze-code.nvim/blob/main/bin) + +## Contributing + +Thank you to everyone that is contributing and to those who want to contribute. +Any contribution is welcomed! + +**Quick guide**: + +1. [Fork](https://github.com/AlejandroSuero/freeze-code.nvim/fork) this + project. +2. Clone your fork (`git clone `). +3. Add main repo as remote (`git remote add upstream `). +4. Create a branch for your changes (`git switch -c feature/your-feature` or + `git switch -c fix/your-fix`). +5. Commit your changes (`git commit -m "feat(...): ..."`). +6. Push to your fork (`git push origin `). +7. Open a [PR](https://github.com/AlejandroSuero/freeze-code.nvim/pulls). + +For more information, check +[CONTRIBUTING.md](https://github.com/AlejandroSuero/freeze-code.nvim/blob/main/contrib/CONTRIBUTING.md). diff --git a/bin/pngcopy-linux b/bin/pngcopy-linux new file mode 100755 index 0000000..afe7dea --- /dev/null +++ b/bin/pngcopy-linux @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +xclip -selection clipboard -t image/png -i "$@" diff --git a/bin/pngcopy-macos b/bin/pngcopy-macos new file mode 100755 index 0000000..16a3e24 --- /dev/null +++ b/bin/pngcopy-macos @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +osascript \ + -e "on run args" \ + -e "set the clipboard to (read (POSIX file (first item of args)) as JPEG picture)" \ + -e end \ + "$@" diff --git a/bin/pngcopy-windows.ps1 b/bin/pngcopy-windows.ps1 new file mode 100644 index 0000000..377de26 --- /dev/null +++ b/bin/pngcopy-windows.ps1 @@ -0,0 +1 @@ +Add-Type -AssemblyName System.Windows.Forms; [Windows.Forms.Clipboard]::SetImage($[Syste.Drawing.Image]::FromFile("$args[0]"))) diff --git a/contrib/CONTRIBUTING.md b/contrib/CONTRIBUTING.md new file mode 100644 index 0000000..0bb4f22 --- /dev/null +++ b/contrib/CONTRIBUTING.md @@ -0,0 +1,102 @@ +# Freeze Code plugin contributions + +Welcome everyone and thank you for wanting to contribute to this project. + +## Dependencies + +This project uses [selene](https://github.com/Kampfkarren/selene) as the +linter, [stylua](https://github.com/JohnnyMorganz/StyLua) as the formatter and +[vusted](https://github.com/notomo/vusted) as the test runner. + +```bash +cargo install selene +cargo install stylua +luarocks --lua-version=5.1 install vusted +``` + +## How to contribute + +1. **Configure the development** + + - **Fork this repo**: Make a fork of this repo. For that, click on the **Fork** + button at the top right side of the main page for this GitHub repo. + + - **Clone your fork**: After the fork, make a clone of your repo `username/freeze-code.nvim` + on your local machine, `git clone `. + + - **Add the main repo as remote**: To keep up with the changes, + `git remote add upstream `. + +2. **Work on your changes** + + - **Sync the fork**: You can do this from your fork's repo, using the GitHub UI, + or using your terminal, `gh repo sync -b main` or + `git switch main && git fetch upstream && git merge upstream/main`. + + - **Create a new branch**: Before working on your changes, create a new branch, + using `git switch -c `. + + - **Make your changes**: Implement your changes on your local machine. Make sure + to follow the project standards (linting and formatting rules). + + > You can use `make lint` and `make test` to check if your changes are correct. + +3. **Send your changes** + +- **Commit your changes**: Once you are satisfied with your changes, commit them + with a descriptive and concise message. Following the standards like in the + [Neovim repo](https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages), + [conventional commit guidelines](https://www.conventionalcommits.org/en/v1.0.0). + +```COMMITMSG +type(scope): subject + +Problem: +... + +Solution: +... +``` + +> [!note] +> Some of the types are: `build ci docs feat fix perf refactor revert test` +> +> You can leave the **body** blank, but it is nice if a complex change occurs, +> you do provide a concise **body**. + +```COMMITMSG +Problem: +... + +Solution: +... +``` + +> [!warning] +> To indicate **BREAKING CHANGES**: + +```COMMITMSG +refactor(installation)!: drop support for nvim-0.8 + +BREAKING CHANGE: refactor to use neovim's API supported only in v0.9 or higher +``` + +- **Push to your fork**: Push your changes to your fork using + `git push origin `. + +- **Create a Pull Request (PR)**: Once you pushed your changes, make a pull request + so we can see the changes and discuss over it if necessary. A clear description + of the changes is allways welcomed. + +## Good practices + +- **Check for open issues**: Duplicated issues are never good. + +- **Check for open PRs**: Make sure there isn't another PR open tackling a similar + issue or creating a similar feature. You can allways help in an open PR. + +- **Descriptive and concised commits**: [conventional commit messages](https://www.conventionalcommits.org/en/v1.0.0). + +- **Follow the code style**: Try to match the code style as much as possible. Follow + lint and format rules. For `md` files, [markdownlint](https://github.com/markdownlint/markdownlint); + for `lua` files, [selene](https://github.com/Kampfkarren/selene) and [stylua](https://github.com/JohnnyMorganz/StyLua) diff --git a/contrib/minimal.lua b/contrib/minimal.lua new file mode 100644 index 0000000..160bd7c --- /dev/null +++ b/contrib/minimal.lua @@ -0,0 +1,27 @@ +vim.cmd([[set runtimepath=$VIMRUNTIME]]) +vim.cmd([[set packpath=/tmp/nvim/lazy/]]) + +local lazypath = "/tmp/nvim/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end + +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + { + "AlejandroSuero/freeze-code.nvim", + config = function() + require("freeze-code").setup() + end, + lazy = false, + enabled = true, + }, +}) diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/freeze-code-scm-1.rockspec b/freeze-code-scm-1.rockspec new file mode 100644 index 0000000..a4e2460 --- /dev/null +++ b/freeze-code-scm-1.rockspec @@ -0,0 +1,34 @@ +---@diagnostic disable: lowercase-global +--#selene: allow(unscoped_variables, unused_variable) +local _MODREV, _SPECREV = "scm", "-1" + +rockspec_format = "3.0" +package = "freeze-code" +version = _MODREV .. _SPECREV + +description = { + summary = "A code snapshot plugin using freeze.", + detailed = [[ + This plugin allows you to take a "screenshot" of your code, + thanks to freeze by charm.sh. +]], + homepage = "https://github.com/AlejandroSuero/freeze-code.nvim", + license = "MIT/X11", + labels = { "neovim", "snapshot", "screenshot", "freeze" }, +} + +dependencies = { + "lua >= 5.1, < 5.4", + "luassert", +} + +source = { + url = "git://github.com/AlejandroSuero/freeze-code.nvim", +} + +build = { + type = "builtin", + copy_directories = { + "doc", + }, +} diff --git a/freeze.png b/freeze.png new file mode 100644 index 0000000..d03bcae Binary files /dev/null and b/freeze.png differ diff --git a/lua/freeze-code/init.lua b/lua/freeze-code/init.lua new file mode 100644 index 0000000..61b0310 --- /dev/null +++ b/lua/freeze-code/init.lua @@ -0,0 +1,46 @@ +---@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 FreezeCodeConfig +---@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 + +---@class FreezeCode +---@field setup function +---@field config FreezeCodeConfig + +---@type FreezeCode|{} +local freeze_code = {} + +---@type FreezeConfig +local freeze_config = { + output = "freeze.png", + config = "base", + theme = "default", +} + +---@type FreezeCodeConfig +local config = { + freeze_path = vim.fn.exepath("freeze"), + copy_cmd = vim.env.HOME .. "/dev/nvim_plugins/freeze-code.nvim/bin/pngcopy-macos", + copy = false, + open = false, + dir = vim.env.PWD, + freeze_config = freeze_config, +} + +freeze_code.config = config + +---freeze-code's set up function +---@param opts {}|nil +freeze_code.setup = function(opts) + freeze_code.config = vim.tbl_extend("force", {}, freeze_code.config, opts or {}) +end + +return freeze_code diff --git a/lua/freeze-code/utils/init.lua b/lua/freeze-code/utils/init.lua new file mode 100644 index 0000000..d473ca7 --- /dev/null +++ b/lua/freeze-code/utils/init.lua @@ -0,0 +1,8 @@ +---@class FreezeCodeUtils +---@field logger FreezeCodeLogger +---@type FreezeCodeUtils|{} +local M = {} + +M.logger = require("freeze-code.utils.logger") + +return M diff --git a/lua/freeze-code/utils/logger.lua b/lua/freeze-code/utils/logger.lua new file mode 100644 index 0000000..89eed8d --- /dev/null +++ b/lua/freeze-code/utils/logger.lua @@ -0,0 +1,71 @@ +---@meta + +---@brief [[ +--- Provides `loggin` functions to display messages. +---@brief ]] + +---@class FreezeCodeLogger +---@field err function +---@field err_once function +---@field warn function +---@field info function +---@field err_fmt function +---@field err_once_fmt function +---@field warn_fmt function +---@field info_fmt function +---@type FreezeCodeLogger|{} +local M = {} + +---Display error message +---@param msg string: Message to display +function M.err(msg) + vim.notify(msg, vim.log.levels.ERROR, { title = "FreezeCode" }) +end + +---Display error message once +---@param msg string: Message to display +function M.err_once(msg) + vim.notify_once(msg, vim.log.levels.ERROR, { title = "FreezeCode" }) +end + +---Display warn message +---@param msg string: Message to display +function M.warn(msg) + vim.notify(msg, vim.log.levels.WARN, { title = "FreezeCode" }) +end + +---Display log message +---@param msg string: Message to display +function M.info(msg) + vim.notify(msg, vim.log.levels.INFO, { title = "FreezeCode" }) +end + +---Display formatted error message +---@param msg string|number: Format to display +---@param ... any: Format parameters +function M.err_fmt(msg, ...) + vim.notify(string.format(msg, ...), vim.log.levels.ERROR, { title = "FreezeCode" }) +end + +---Display formatted error message once +---@param msg string|number: Format to display +---@param ... any: Format parameters +function M.err_once_fmt(msg, ...) + vim.notify_once(string.format(msg, ...), vim.log.levels.ERROR, { title = "FreezeCode" }) +end + +---Display formatted warn message +---@param msg string|number: Format to display +---@param ... any: Format parameters +function M.warn_fmt(msg, ...) + vim.notify(string.format(msg, ...), vim.log.levels.WARN, { title = "FreezeCode" }) +end + +---Display formatted log message +---@param msg string|number: Format to display +---@param ... any: Format parameters +function M.info_fmt(msg, ...) + vim.notify(string.format(msg, ...), vim.log.levels.INFO, { title = "FreezeCode" }) +end + +return M diff --git a/neovim.yml b/neovim.yml new file mode 100644 index 0000000..9de2931 --- /dev/null +++ b/neovim.yml @@ -0,0 +1,25 @@ +--- +base: lua51 + +globals: + vim: + any: true + assert: + args: + - type: bool + - type: string + required: false + after_each: + args: + - type: function + before_each: + args: + - type: function + describe: + args: + - type: string + - type: function + it: + args: + - type: string + - type: function diff --git a/rockspec.template b/rockspec.template new file mode 100644 index 0000000..5ff991d --- /dev/null +++ b/rockspec.template @@ -0,0 +1,39 @@ +local git_tag = "$git_tag" +local modrev = "$modrev" +local specrev = "-1" + +local repo_url = "$repo_url" + +rockspec_format = "3.0" +package = "$package" +version = modrev .. specrev + +description = { + summary = "$summary", + detailed = $detailed_description, + labels = $labels, + homepage = "$homepage", + $license +} + +dependencies = { + "lua >= 5.1, < 5.4", + "luassert" +} + +source = { + url = repo_url .. "/archive/" .. git_tag .. ".zip", + dir = "$repo_name-" .. modrev, +} + +build = { + type = "builtin", + copy_directories = { + "doc" + } +} + +test = { + type = "command", + command = "make test" +} diff --git a/scripts/minimal.vim b/scripts/minimal.vim new file mode 100644 index 0000000..36acc45 --- /dev/null +++ b/scripts/minimal.vim @@ -0,0 +1,3 @@ + +set rtp+=. +runtime plugin/plenary.vim diff --git a/selene.toml b/selene.toml new file mode 100644 index 0000000..cd07894 --- /dev/null +++ b/selene.toml @@ -0,0 +1,10 @@ +std="neovim" + +exclude = ["./*.rockspec"] + +[rules] +global_usage = "warn" +multiple_statements = "allow" +incorrect_standard_library_use = "allow" +mixed_table = "allow" +unused_variable = "warn" diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..543dc9b --- /dev/null +++ b/stylua.toml @@ -0,0 +1,10 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "Never" + +[sort_requires] +enabled = true diff --git a/tests/freeze-code/freeze-code_spec.lua b/tests/freeze-code/freeze-code_spec.lua new file mode 100644 index 0000000..ec9f4e9 --- /dev/null +++ b/tests/freeze-code/freeze-code_spec.lua @@ -0,0 +1,39 @@ +local assert = require("luassert.assert") +describe("[freeze-code test]", function() + describe("setup", function() + local code_snapshot = require("freeze-code") + local same = assert.are.same + it("with default config", function() + local expected = { + freeze_path = vim.fn.exepath("freeze"), + copy_cmd = vim.env.HOME .. "/dev/nvim_plugins/freeze-code.nvim/bin/pngcopy-macos", + copy = false, + open = false, + dir = vim.env.PWD, + freeze_config = { + output = "freeze.png", + config = "base", + theme = "default", + }, + } + code_snapshot.setup() + same(code_snapshot.config, expected) + end) + it("with custom config", function() + local expected = { + freeze_path = vim.fn.exepath("freeze"), + copy_cmd = vim.env.HOME .. "/dev/nvim_plugins/freeze-code.nvim/bin/pngcopy-linux", + copy = false, + open = true, + dir = vim.env.PWD, + freeze_config = { + output = "freeze.png", + config = "user", + theme = "rose-pine-moon", + }, + } + code_snapshot.setup(expected) + same(code_snapshot.config, expected) + end) + end) +end) diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua new file mode 100644 index 0000000..b4c8c23 --- /dev/null +++ b/tests/minimal_init.lua @@ -0,0 +1,11 @@ +local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim" +local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0 +if is_not_a_directory then + vim.fn.system({ "git", "clone", "https://github.com/nvim-lua/plenary.nvim", plenary_dir }) +end + +vim.opt.rtp:append(".") +vim.opt.rtp:append(plenary_dir) + +vim.cmd("runtime plugin/plenary.vim") +require("plenary.busted")