From ed804de3fa70cad16b7a1c2d9211e567dbf6939d Mon Sep 17 00:00:00 2001 From: Kurenshe Nurdaulet <63652620+EpsilonKu@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:09:25 +0600 Subject: [PATCH 1/6] Add options for window --- README.md | 19 +++++++++++++++++-- lua/runner/config.lua | 17 +++++++++++++++++ lua/runner/handlers/utils.lua | 14 ++++++++++++-- lua/runner/init.lua | 5 +++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 lua/runner/config.lua diff --git a/README.md b/README.md index 9b2dbb9..2c21f48 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,14 @@ A customizable Neovim plugin to run code inside the editor dependencies = { 'nvim-telescope/telescope.nvim', dependencies = { 'nvim-lua/plenary.nvim' } - } + }, + config = function() + require("runner").setup({ + position = "right", -- position of task window can be: top, left, right, bottom + width = 80, -- width of window when position is left or right + height = 10, -- height of window when position is top or bottom + }) + end } }) ``` @@ -55,7 +62,15 @@ A customizable Neovim plugin to run code inside the editor ## Configuration - This plugin doesn't have a `setup()` method, but you can set your filetype handlers using the `set_handler()` method. + ### S`setup(options)` + Runner comes with the following defaults: + ```lua + { + position = "right", -- position of task window can be: top, left, right, bottom + width = 80, -- width of window when position is left or right + height = 10, -- height of window when position is top or bottom + } + ``` Default handlers can be found [here](./lua/runner/handlers/init.lua). diff --git a/lua/runner/config.lua b/lua/runner/config.lua new file mode 100644 index 0000000..4b9e178 --- /dev/null +++ b/lua/runner/config.lua @@ -0,0 +1,17 @@ +local M = {} + +local defaults = { + position = "right", -- options: top, left, right, bottom + width = 80, -- width of window when position is left or right + height = 10, -- height of window when position is top or bottom +} + +M.options = {} + +M.setup = function(options) + M.options = vim.tbl_deep_extend("force", {}, defaults, options or {}) +end + +M.setup() + +return M; diff --git a/lua/runner/handlers/utils.lua b/lua/runner/handlers/utils.lua index f4a4be8..04d07f1 100644 --- a/lua/runner/handlers/utils.lua +++ b/lua/runner/handlers/utils.lua @@ -1,5 +1,7 @@ local M = {} +local config = require('runner.config') + M._buffer = nil M._window = nil @@ -21,7 +23,16 @@ M.create_window = function() return M._window end - vim.cmd [[ vsplit ]] + if (config.options.position == "right") then + vim.cmd('botright ' .. config.options.width .. ' vsplit') + elseif (config.options.position == "left") then + vim.cmd('topleft ' .. config.options.width .. ' vsplit') + elseif (config.options.position == "bottom") then + vim.cmd('botright ' .. config.options.height .. 'split') + elseif (config.options.position == "top") then + vim.cmd('topleft ' .. config.options.height .. 'split') + end + local window = vim.api.nvim_get_current_win() local window_opts = { @@ -57,7 +68,6 @@ M.run_command = function(command, callback) callback(output) end }) - end diff --git a/lua/runner/init.lua b/lua/runner/init.lua index f2cbf3f..4487fc7 100644 --- a/lua/runner/init.lua +++ b/lua/runner/init.lua @@ -1,9 +1,14 @@ local handlers = require('runner.handlers') +local config = require('runner.config') local M = {} M._handlers = handlers +M.setup = function(options) + config.setup(options) +end + M.set_handler = function(filetype, handler) M._handlers[filetype] = handler end From f4f42e02ec3ab3d7b28b969d6b92886d9bb3a944 Mon Sep 17 00:00:00 2001 From: Kurenshe Nurdaulet <63652620+EpsilonKu@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:38:35 +0600 Subject: [PATCH 2/6] Fix single quotes --- README.md | 23 +++++++++++------------ lua/runner/config.lua | 4 ++-- lua/runner/handlers/utils.lua | 8 ++++---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2c21f48..7c6eb22 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,10 @@ A customizable Neovim plugin to run code inside the editor requires = { 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/plenary.nvim' } - } + }, + config = function() + require('runner').setup() + end } end) ``` @@ -41,11 +44,7 @@ A customizable Neovim plugin to run code inside the editor dependencies = { 'nvim-lua/plenary.nvim' } }, config = function() - require("runner").setup({ - position = "right", -- position of task window can be: top, left, right, bottom - width = 80, -- width of window when position is left or right - height = 10, -- height of window when position is top or bottom - }) + require(runner').setup() end } }) @@ -62,14 +61,14 @@ A customizable Neovim plugin to run code inside the editor ## Configuration - ### S`setup(options)` + ### `setup(options)` Runner comes with the following defaults: ```lua - { - position = "right", -- position of task window can be: top, left, right, bottom - width = 80, -- width of window when position is left or right - height = 10, -- height of window when position is top or bottom - } + require('runner').setup({ + position = 'right', -- position of task window can be: top, left, right, bottom + width = 80, -- width of window when position is left or right + height = 10, -- height of window when position is top or bottom + }) ``` Default handlers can be found [here](./lua/runner/handlers/init.lua). diff --git a/lua/runner/config.lua b/lua/runner/config.lua index 4b9e178..3757e09 100644 --- a/lua/runner/config.lua +++ b/lua/runner/config.lua @@ -1,7 +1,7 @@ local M = {} local defaults = { - position = "right", -- options: top, left, right, bottom + position = 'right', -- options: top, left, right, bottom width = 80, -- width of window when position is left or right height = 10, -- height of window when position is top or bottom } @@ -9,7 +9,7 @@ local defaults = { M.options = {} M.setup = function(options) - M.options = vim.tbl_deep_extend("force", {}, defaults, options or {}) + M.options = vim.tbl_deep_extend('force', {}, defaults, options or {}) end M.setup() diff --git a/lua/runner/handlers/utils.lua b/lua/runner/handlers/utils.lua index 04d07f1..7c9b8d5 100644 --- a/lua/runner/handlers/utils.lua +++ b/lua/runner/handlers/utils.lua @@ -23,13 +23,13 @@ M.create_window = function() return M._window end - if (config.options.position == "right") then + if (config.options.position == 'right') then vim.cmd('botright ' .. config.options.width .. ' vsplit') - elseif (config.options.position == "left") then + elseif (config.options.position == 'left') then vim.cmd('topleft ' .. config.options.width .. ' vsplit') - elseif (config.options.position == "bottom") then + elseif (config.options.position == 'bottom') then vim.cmd('botright ' .. config.options.height .. 'split') - elseif (config.options.position == "top") then + elseif (config.options.position == 'top') then vim.cmd('topleft ' .. config.options.height .. 'split') end From 18376d7ec8a5d76e68a5ecf382fdb0a90238287e Mon Sep 17 00:00:00 2001 From: Kurenshe Nurdaulet <63652620+EpsilonKu@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:40:41 +0600 Subject: [PATCH 3/6] Weird. I thought I fixed it --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c6eb22..531f0b0 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ A customizable Neovim plugin to run code inside the editor dependencies = { 'nvim-lua/plenary.nvim' } }, config = function() - require(runner').setup() + require('runner').setup() end } }) From 87e2084403f10dfbbf14e9ecd44564b131e5ace0 Mon Sep 17 00:00:00 2001 From: Kurenshe Nurdaulet <63652620+EpsilonKu@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:49:19 +0600 Subject: [PATCH 4/6] Move line --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 531f0b0..f843c2e 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,9 @@ A customizable Neovim plugin to run code inside the editor }) ``` + #### `set_handler(filetype, handler)` Default handlers can be found [here](./lua/runner/handlers/init.lua). - #### `set_handler(filetype, handler)` | Argument name | Description | Type | |---------------- | --------------- | --------------- | | `filetype` | The filetype on which to run the given handler | `string` | From 786deb59095aba68ef76419482518bc948d9f028 Mon Sep 17 00:00:00 2001 From: Kurenshe Nurdaulet <63652620+EpsilonKu@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:53:16 +0600 Subject: [PATCH 5/6] Make title smaller --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index f843c2e..f5fcded 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,7 @@ A customizable Neovim plugin to run code inside the editor ``` ## Configuration - - ### `setup(options)` + #### `setup(options)` Runner comes with the following defaults: ```lua require('runner').setup({ From 8d2a0bdffca11d96ff15551fbaa1676526329a96 Mon Sep 17 00:00:00 2001 From: Kurenshe Nurdaulet <63652620+EpsilonKu@users.noreply.github.com> Date: Mon, 3 Apr 2023 22:02:14 +0600 Subject: [PATCH 6/6] Fix indent and space --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f5fcded..aa3bbb5 100644 --- a/README.md +++ b/README.md @@ -60,17 +60,20 @@ A customizable Neovim plugin to run code inside the editor ``` ## Configuration + #### `setup(options)` + Runner comes with the following defaults: ```lua - require('runner').setup({ - position = 'right', -- position of task window can be: top, left, right, bottom - width = 80, -- width of window when position is left or right - height = 10, -- height of window when position is top or bottom - }) + require('runner').setup({ + position = 'right', -- position of task window can be: top, left, right, bottom + width = 80, -- width of window when position is left or right + height = 10, -- height of window when position is top or bottom + }) ``` #### `set_handler(filetype, handler)` + Default handlers can be found [here](./lua/runner/handlers/init.lua). | Argument name | Description | Type |