Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
aspeddro committed Jan 23, 2022
0 parents commit 6595bef
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Pedro Castro

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.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# gitui.nvim

[Gitui](https://github.com/extrawurst/gitui) in your Neovim

## Prerequisites

- Neovim >= 0.5.0
- [Gitui](https://github.com/extrawurst/gitui)

## Installation

[packer.nvim](https://github.com/wbthomason/packer.nvim)

```lua
use 'aspeddro/gitui.nvim'
```

## Setup

```lua
require("gitui").setup()
```

## Configuration (optional)

Following are the default config for the `setup()`. If you want to override, just modify the option that you want then it will be merged with the default config.

```lua
{
-- Command Options
command = {
-- Enable :Gitui command
-- @type: bool
enable = true,
},
-- Path to binary
-- @type: string
binary = "gitui",
-- Argumens to gitui
-- @type: table of string
args = {},
-- WIndow Options
window = {
options = {
-- Width window in %
-- @type: number
width = 90,
-- Height window in %
-- @type: number
height = 80,
-- Border Style
-- Enum: "none", "single", "rounded", "solid" or "shadow"
-- @type: string
border = "rounded",
},
},
}
```

## Lua API

```lua
require("gitui").open()
```

## TODO

- Add documentation
89 changes: 89 additions & 0 deletions lua/gitui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local M = {}

M.state = {
is_open = false,
}

-- Default options
M.config = {
-- Command Options
command = {
-- Enable :Gitui command
-- @type: bool
enable = true,
},
-- Path to binary
-- @type: string
binary = "gitui",
-- Argumens to gitui
-- @type: table of string
args = {},
-- WIndow Options
window = {
options = {
-- Width window in %
-- @type: number
width = 90,
-- Height window in %
-- @type: number
height = 80,
-- Border Style
-- Enum: "none", "single", "rounded", "solid" or "shadow"
-- @type: string
border = "rounded",
},
},
}

M.setup = function(overrides)
M.config = vim.tbl_deep_extend("force", M.config, overrides or {})

if M.config.command.enable then
vim.cmd([[
command! Gitui :lua require"gitui".open()
]])
end
end

M.open = function()
if M.state.is_open then
return
end

assert(vim.fn.executable(M.config.binary) == 1, M.config.binary .. " not a executable")

local bufnr = vim.api.nvim_create_buf(false, true)

local width = vim.api.nvim_get_option("columns")
local height = vim.api.nvim_get_option("lines")
local win_height = math.ceil(height * (M.config.window.options.height / 100))
local win_width = math.ceil(width * (M.config.window.options.width / 100))
local row = math.ceil((height - win_height) / 2)
local col = math.ceil((width - win_width) / 2)

local window_options = {
style = "minimal",
relative = "editor",
width = win_width,
height = win_height,
row = row,
col = col,
border = M.config.window.options.border,
noautocmd = true,
}

vim.api.nvim_open_win(bufnr, true, window_options)

vim.fn.termopen(table.concat(vim.tbl_flatten({ M.config.binary, M.config.args }), " "), {
on_exit = function()
-- vim.api.nvim_win_close(winr, true)
-- vim.cmd([[silent! :q]])
vim.api.nvim_buf_delete(bufnr, { force = true })
M.state.is_open = false
end,
})
vim.cmd([[startinsert!]])
M.state.is_open = true
end

return M
3 changes: 3 additions & 0 deletions stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
indent_type = "Spaces"
indent_width = 2
column_width = 120

0 comments on commit 6595bef

Please sign in to comment.