diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..459a3da --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,74 @@ +name: CI +on: + push: + pull_request: + +jobs: + tests: + strategy: + matrix: + # os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - name: Install Neovim + shell: bash + run: | + mkdir -p /tmp/nvim + wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage + cd /tmp/nvim + chmod a+x ./nvim.appimage + ./nvim.appimage --appimage-extract + echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH + - name: Run Tests + run: | + nvim --version + [ ! -d tests ] && exit 0 + nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}" + docs: + runs-on: ubuntu-latest + needs: tests + if: ${{ github.ref == 'refs/heads/master' }} + steps: + - uses: actions/checkout@v3 + - name: panvimdoc + uses: kdheepak/panvimdoc@main + with: + vimdoc: word.nvim + version: "Neovim >= 0.8.0" + demojify: true + treesitter: true + - name: Push changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "chore(build): auto-generate vimdoc" + commit_user_name: "github-actions[bot]" + commit_user_email: "github-actions[bot]@users.noreply.github.com" + commit_author: "github-actions[bot] " + release: + name: release + if: ${{ github.ref == 'refs/heads/master' }} + needs: + - docs + - tests + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v3 + id: release + with: + release-type: simple + package-name: word.nvim + extra-files: | + lua/lazy/core/config.lua + - uses: actions/checkout@v3 + - name: tag stable versions + if: ${{ steps.release.outputs.release_created }} + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git" + git tag -d stable || true + git push origin :stable || true + git tag -a stable -m "Last Stable Release" + git push origin stable diff --git a/.luarc.jsonc b/.luarc.jsonc new file mode 100644 index 0000000..3f53162 --- /dev/null +++ b/.luarc.jsonc @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "runtime": { + "version": "LuaJIT" + }, + "workspace": { + "library": [ + "runtime/lua", + "${3rd}/luv/library" + ], + "ignoreDir": [ + "test" + ], + "checkThirdParty": "Disable" + } +} diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..22d6d3e --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 100 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferSingle" +call_parentheses = "Input" diff --git a/README.md b/README.md new file mode 100644 index 0000000..2212a7a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +## WIP diff --git a/doc/word.nvim.txt b/doc/word.nvim.txt new file mode 100644 index 0000000..e69de29 diff --git a/lua/word/commands.lua b/lua/word/commands.lua new file mode 100644 index 0000000..1c0c612 --- /dev/null +++ b/lua/word/commands.lua @@ -0,0 +1,3 @@ +return { + ui_launch = function() require('word.ui').launch() end, +} diff --git a/lua/word/config.lua b/lua/word/config.lua new file mode 100644 index 0000000..7663b18 --- /dev/null +++ b/lua/word/config.lua @@ -0,0 +1,5 @@ +local default_opts = {} + +return { + setup = function(opts) end, +} diff --git a/lua/word/init.lua b/lua/word/init.lua new file mode 100644 index 0000000..be70609 --- /dev/null +++ b/lua/word/init.lua @@ -0,0 +1,11 @@ +local M = {} + +M.setup = function(opts) + require('word.config').setup(opts) +end + +return setmetatable(M, { + __index = function(_, k) + return require('word.commands')[k] + end, +}) diff --git a/lua/word/menu.lua b/lua/word/menu.lua new file mode 100644 index 0000000..452ee35 --- /dev/null +++ b/lua/word/menu.lua @@ -0,0 +1,47 @@ +local Menu = require('nui.menu') +local event = require('nui.utils.autocmd').event +local Layout = require('nui.layout') + +local menu = Menu({ + position = '50%', + size = { width = '50%', height = '60%' }, + border = { + style = 'single', + text = { top = '[Choose-an-Element]', top_align = 'center' }, + }, + win_options = { + winhighlight = 'Normal:Normal,FloatBorder:Normal', + }, +}, { + lines = { + Menu.item('Hydrogen (H)'), + Menu.item('Carbon (C)'), + Menu.item('Nitrogen (N)'), + Menu.separator('Noble-Gases', { char = '-', text_align = 'right' }), + Menu.item('Helium (He)'), + Menu.item('Neon (Ne)'), + Menu.item('Argon (Ar)'), + }, + max_width = 20, + keymap = { + focus_next = { 'j', '', '' }, + focus_prev = { 'k', '', '' }, + close = { '', '' }, + submit = { '', '' }, + }, + on_close = function() + print('Menu Closed!') + end, + on_submit = function(item) + print('Menu Submitted: ', item.text) + end, +}) + +local layout = Layout( + { position = '50%', size = { width = 80, height = '60%' } }, + Layout.Box({ + Layout.Box(menu, { size = '60%' }), + }, { dir = 'col' }) +) + +layout:mount() diff --git a/lua/word/ui.lua b/lua/word/ui.lua new file mode 100644 index 0000000..5d2f3d0 --- /dev/null +++ b/lua/word/ui.lua @@ -0,0 +1,91 @@ +local Popup = require('nui.popup') +local event = require('nui.utils.autocmd').event +local Layout = require('nui.layout') +local NuiLine = require('nui.line') + +local Util = require('word.util') + +local cet6_json_path = '~/cet.json' +local bookmark_json_path = '~/cet-bookmark.json' + +local dict = vim.json.decode(Util.read_file(cet6_json_path)) +local words = vim.tbl_keys(dict) +table.sort(words, function(a, b) + return a:lower() < b:lower() +end) + +local popup = Popup({ + enter = true, + focusable = true, + border = { style = 'rounded' }, + position = '50%', + size = { width = '50%', height = '60%' }, +}) + +local layout = Layout( + { + position = '50%', + size = { width = '50%', height = '60%' }, + }, + Layout.Box({ + Layout.Box(popup, { size = '100%' }), + }, { dir = 'row' }) +) + +local toggle_ed = {} + +local buf_update = function(bufnr, line_nr) + for i = 1, #words do + local word = words[i] + local line = NuiLine() + + local sig = toggle_ed[i] and 'x' or ' ' + if line_nr == i then + line:append(('[%s]\t'):format(sig), 'Error') + else + line:append(('[%s]\t'):format(sig), 'Error') + end + line:append(('%-16s'):format(word), 'Function') + line:append('\t') + line:append(('%s'):format(dict[word]), 'String') + line:render(bufnr, -1, i) + end +end + +local keymap_setup = function() + popup:map('n', 'm', function() + local line_nr = vim.fn.line '.' + if toggle_ed[line_nr] then + toggle_ed[line_nr] = nil + else + toggle_ed[line_nr] = true + end + buf_update(popup.bufnr, line_nr) + end) + -- update bookmark + popup:map('n', 'w', function() + local save = {} + for i in pairs(toggle_ed) do + table.insert(save, words[i]) + end + local data = vim.json.encode(save) + Util.write_file(bookmark_json_path, data) + end) + -- show words' detail + -- popup:map('n', 'o', show_detail()) +end + +local launch = function() + layout:mount() + popup:on(event.BufLeave, function() + popup:unmount() + end) + keymap_setup() + buf_update(popup.bufnr) +end + +launch() + +return { + launch = launch, +} diff --git a/lua/word/util.lua b/lua/word/util.lua new file mode 100644 index 0000000..7e4096e --- /dev/null +++ b/lua/word/util.lua @@ -0,0 +1,26 @@ +local M = {} + +M.read_file = function(path) + path = vim.fs.normalize(path) + local fd = assert(io.open(path, 'r')) + if fd == nil then + vim.notify('fail to open file', vim.log.levels.ERROR, { title = 'word.nvim' }) + return + end + ---@type string + local data = fd:read('*a') + fd:close() + return data +end + +M.write_file = function(path, data) + path = vim.fs.normalize(path) + local fd = assert(io.open(path, 'w')) + if fd == nil then + vim.notify('fail to open file', vim.log.levels.ERROR, { title = 'word.nvim' }) + return + end + fd:write(data) + fd:close() +end +return M