mirror of
https://github.com/kristoferssolo/runner.nvim.git
synced 2025-10-21 19:50:34 +00:00
commit
27c047a67b
26
README.md
26
README.md
@ -25,7 +25,10 @@ A customizable Neovim plugin to run code inside the editor
|
|||||||
requires = {
|
requires = {
|
||||||
'nvim-telescope/telescope.nvim',
|
'nvim-telescope/telescope.nvim',
|
||||||
requires = { 'nvim-lua/plenary.nvim' }
|
requires = { 'nvim-lua/plenary.nvim' }
|
||||||
}
|
},
|
||||||
|
config = function()
|
||||||
|
require('runner').setup()
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
@ -39,7 +42,10 @@ A customizable Neovim plugin to run code inside the editor
|
|||||||
dependencies = {
|
dependencies = {
|
||||||
'nvim-telescope/telescope.nvim',
|
'nvim-telescope/telescope.nvim',
|
||||||
dependencies = { 'nvim-lua/plenary.nvim' }
|
dependencies = { 'nvim-lua/plenary.nvim' }
|
||||||
}
|
},
|
||||||
|
config = function()
|
||||||
|
require('runner').setup()
|
||||||
|
end
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@ -55,11 +61,21 @@ A customizable Neovim plugin to run code inside the editor
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
This plugin doesn't have a `setup()` method, but you can set your filetype handlers using the `set_handler()` method.
|
#### `setup(options)`
|
||||||
|
|
||||||
Default handlers can be found [here](./lua/runner/handlers/init.lua).
|
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
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
#### `set_handler(filetype, handler)`
|
#### `set_handler(filetype, handler)`
|
||||||
|
|
||||||
|
Default handlers can be found [here](./lua/runner/handlers/init.lua).
|
||||||
|
|
||||||
| Argument name | Description | Type |
|
| Argument name | Description | Type |
|
||||||
|---------------- | --------------- | --------------- |
|
|---------------- | --------------- | --------------- |
|
||||||
| `filetype` | The filetype on which to run the given handler | `string` |
|
| `filetype` | The filetype on which to run the given handler | `string` |
|
||||||
|
|||||||
17
lua/runner/config.lua
Normal file
17
lua/runner/config.lua
Normal file
@ -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;
|
||||||
@ -1,5 +1,7 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local config = require('runner.config')
|
||||||
|
|
||||||
M._buffer = nil
|
M._buffer = nil
|
||||||
M._window = nil
|
M._window = nil
|
||||||
|
|
||||||
@ -21,7 +23,16 @@ M.create_window = function()
|
|||||||
return M._window
|
return M._window
|
||||||
end
|
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 = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
local window_opts = {
|
local window_opts = {
|
||||||
@ -57,7 +68,6 @@ M.run_command = function(command, callback)
|
|||||||
callback(output)
|
callback(output)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
local handlers = require('runner.handlers')
|
local handlers = require('runner.handlers')
|
||||||
|
local config = require('runner.config')
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M._handlers = handlers
|
M._handlers = handlers
|
||||||
|
|
||||||
|
M.setup = function(options)
|
||||||
|
config.setup(options)
|
||||||
|
end
|
||||||
|
|
||||||
M.set_handler = function(filetype, handler)
|
M.set_handler = function(filetype, handler)
|
||||||
M._handlers[filetype] = handler
|
M._handlers[filetype] = handler
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user