├── .gitignore ├── LICENSE ├── README.md ├── lua ├── glslView.lua └── glslView │ └── config.lua ├── plugin └── glslView.vim └── stylua.toml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Lua sources 2 | luac.out 3 | 4 | # luarocks build files 5 | *.src.rock 6 | *.zip 7 | *.tar.gz 8 | 9 | # Object files 10 | *.o 11 | *.os 12 | *.ko 13 | *.obj 14 | *.elf 15 | 16 | # Precompiled Headers 17 | *.gch 18 | *.pch 19 | 20 | # Libraries 21 | *.lib 22 | *.a 23 | *.la 24 | *.lo 25 | *.def 26 | *.exp 27 | 28 | # Shared objects (inc. Windows DLLs) 29 | *.dll 30 | *.so 31 | *.so.* 32 | *.dylib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | *.i*86 39 | *.x86_64 40 | *.hex 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Tim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `glslView-nvim` 2 | 3 | When editing GLSL shaders, 4 | this plugin provides the command `GlslView` which will open 5 | [glslViewer](https://github.com/patriciogonzalezvivo/glslViewer) 6 | to the file being edited in the current buffer. 7 | By default, it is opened with the `-l` flag so that `glslViewer` will automatically listen 8 | for file changes, 9 | updating the preview as you save. 10 | 11 | ## 📦 Installation 12 | Install the plugin with your preferred package manager. 13 | For example, 14 | in [packer](https://github.com/wbthomason/packer.nvim) simply: 15 | 16 | ```lua 17 | use { 'timtro/glslView-nvim', ft = 'glsl' } 18 | ``` 19 | Don't forget to `PackerCompile` after installation so that the plugin will only 20 | be loaded for glsl files. 21 | You'll also need a plugin to detect the glsl filetype. 22 | 23 | 24 | #### Installing `glslViewer` 25 | See [installation](https://github.com/patriciogonzalezvivo/glslViewer/wiki/Installing) 26 | in the glslViewer Wiki. 27 | 28 | 29 | ## ⚙️ Configuration 30 | Configuration is done by passing options to `setup()`. The defaults are: 31 | 32 | ```lua 33 | require('glslView').setup { 34 | viewer_path = 'glslViewer', 35 | args = { '-l' }, 36 | } 37 | ``` 38 | 39 | ## 💪 Usage 40 | Use the command `:GlslView` to open the current buffer in glslViewer. 41 | 42 | Additional arguments will be passed to the executable after any arguments set in configuration. 43 | 44 | For example, to start with a 128x256 window: 45 | 46 | ```vimscript 47 | :GlslView -w 128 -h 256 48 | ``` 49 | More primitively, one can call directly through Lua: 50 | ``` 51 | :lua require('glslView').glslView({'-w', '128', '-h', '256'}) 52 | ``` 53 | 54 | ## 🧰 Alternatives 55 | * [vim-GlslViewer](https://github.com/patriciogonzalezvivo/vim-glslViewer) - 56 | Version drift seems to have rendered it useless (at this time) since it 57 | laucnes the process with `&` to free up the UI, but this causes glslViewer 58 | to stop rendering (and then in my case, close). 59 | -------------------------------------------------------------------------------- /lua/glslView.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.config = { 4 | viewer_path = 'glslViewer', 5 | args = { '-l' }, 6 | } 7 | 8 | M.glslView = function(command_args) 9 | local bufnr = vim.api.nvim_get_current_buf() 10 | local full_frag_file_path = vim.api.nvim_buf_get_name(0) 11 | 12 | local viewer_args = { full_frag_file_path } 13 | vim.list_extend(viewer_args, M.config.args) 14 | vim.list_extend(viewer_args, command_args) 15 | 16 | local handle -- pre-declared to avoid diagnostic error. 17 | local nvim_event_loop = vim.uv or vim.loop 18 | handle = nvim_event_loop.spawn(M.config.viewer_path, { args = viewer_args }, function() 19 | handle:close() 20 | end) 21 | 22 | if not handle then 23 | error(debug.traceback 'Failed to spawn glslViewer process.') 24 | else 25 | vim.api.nvim_buf_attach(bufnr, false, { 26 | on_detach = function() 27 | if not handle:is_closing() then 28 | handle:kill(15) 29 | end 30 | end, 31 | }) 32 | end 33 | end 34 | 35 | M.setup = function(opts) 36 | if opts ~= nil then 37 | M.config = vim.tbl_deep_extend('force', M.config, opts) 38 | end 39 | end 40 | 41 | return M 42 | -------------------------------------------------------------------------------- /lua/glslView/config.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timtro/glslView-nvim/2ad41cef51e658a0de1685728a950dd8c13788fd/lua/glslView/config.lua -------------------------------------------------------------------------------- /plugin/glslView.vim: -------------------------------------------------------------------------------- 1 | 2 | command! -nargs=* -bar GlslView :lua require'glslView'.glslView({ }) 3 | " autocmd! BufNewFile,BufRead *.frag GlslView 4 | -------------------------------------------------------------------------------- /stylua.toml: -------------------------------------------------------------------------------- 1 | column_width = 80 2 | line_endings = "Unix" 3 | indent_type = "Spaces" 4 | indent_width = 2 5 | quote_style = "AutoPreferSingle" 6 | no_call_parentheses = true 7 | --------------------------------------------------------------------------------