-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d1da293
Showing
13 changed files
with
358 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Format | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
format: | ||
name: Stylua | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: date +%W > weekly | ||
|
||
- name: Restore cache | ||
id: cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.cargo/bin | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('weekly') }} | ||
|
||
- name: Install | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: cargo install stylua | ||
|
||
- name: Format | ||
run: stylua --check lua/ --config-path=.stylua.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Lint | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint: | ||
name: Luacheck | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install luarocks | ||
sudo luarocks install luacheck | ||
- name: Lint | ||
run: luacheck lua/ --globals vim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
std = luajit | ||
cache = true | ||
codes = true | ||
|
||
read_globals = { "vim" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"diagnostics.globals": [ | ||
"P" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"neodev": { | ||
"library": { | ||
"enabled": true, | ||
"plugins": ["plenary.nvim", "nui.nvim"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
column_width = 80 | ||
line_endings = "Unix" | ||
indent_type = "Spaces" | ||
indent_width = 4 | ||
quote_style = "AutoPreferDouble" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
MIT License | ||
|
||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fmt: | ||
echo "===> Formatting" | ||
stylua lua/ --config-path=.stylua.toml | ||
|
||
lint: | ||
echo "===> Linting" | ||
luacheck lua/ --globals vim | ||
|
||
pr-ready: fmt lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div align="center"> | ||
|
||
# Hermes HTTP Ui | ||
|
||
##### Minimal http client for neovim | ||
|
||
[![Lua](https://img.shields.io/badge/Lua-blue.svg?style=for-the-badge&logo=lua)](http://www.lua.org) | ||
[![Neovim](https://img.shields.io/badge/Neovim%200.5+-green.svg?style=for-the-badge&logo=neovim)](https://neovim.io) | ||
|
||
</div> | ||
|
||
## ⇁ WIP (Under construction) | ||
|
||
This is designed to help with my personal workflow. If you experience any issues, see some improvement you think would be amazing, or just have some feedback or advice, make an issue! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
local Popup = require("nui.popup") | ||
local request = require("hermes.request") | ||
local Layout = require("nui.layout") | ||
local M = {} | ||
|
||
M._state = { | ||
authorization = nil, | ||
output_bufnr = nil, | ||
layout = nil, | ||
} | ||
|
||
--- @param bearer string|nil | ||
M.set_bearer_token = function(bearer) | ||
M._state.authorization = { bearer = bearer } | ||
end | ||
|
||
M.init = function() | ||
local input = Popup({ | ||
border = "rounded", | ||
enter = true, | ||
}) | ||
|
||
input:map("n", "<CR>", function() | ||
local text = vim.api.nvim_buf_get_lines( | ||
vim.api.nvim_get_current_buf(), | ||
0, | ||
-1, | ||
true | ||
)[1] | ||
|
||
local request_data = vim.split(text, " ") | ||
M.send_request({ | ||
method = request_data[1], | ||
url = request_data[2], | ||
}) | ||
end, { noremap = true }) | ||
|
||
local output = Popup({ | ||
border = "rounded", | ||
}) | ||
|
||
M._state.output_bufnr = output.bufnr | ||
|
||
local layout = Layout( | ||
{ | ||
position = "50%", | ||
size = { | ||
width = "50%", | ||
height = "50%", | ||
}, | ||
}, | ||
Layout.Box({ | ||
Layout.Box(input, { size = "10%" }), | ||
Layout.Box(output, { size = "90%" }), | ||
}, { dir = "col" }) | ||
) | ||
|
||
layout:mount() | ||
M._state.layout = { state = "show", layout = layout } | ||
-- set line numbers for the response | ||
vim.api.nvim_win_set_option(output.winid, "number", true) | ||
end | ||
|
||
M.hide = function() | ||
if M._state.layout == nil then | ||
return | ||
end | ||
M._state.layout.layout:unmount() | ||
M._state.layout = nil | ||
end | ||
|
||
-- TODO: set auth token | ||
--- TODO: support post put and patch | ||
M.send_request = function(opts) | ||
if opts.method == nil then | ||
vim.notify("Request method is required", vim.log.levels.ERROR) | ||
return | ||
end | ||
|
||
if opts.url == nil then | ||
vim.notify("Request url is required", vim.log.levels.ERROR) | ||
return | ||
end | ||
|
||
if opts.method == "GET" then | ||
local response = request.get(opts.url, opts) | ||
vim.api.nvim_buf_set_lines( | ||
M._state.output_bufnr, | ||
0, | ||
-1, | ||
true, | ||
vim.split(response or "", "\n") | ||
) | ||
end | ||
|
||
if opts.method == "POST" then | ||
local response = request.post(opts.url, opts) | ||
vim.api.nvim_buf_set_lines( | ||
M._state.output_bufnr, | ||
0, | ||
-1, | ||
true, | ||
vim.split(response or "", "\n") | ||
) | ||
end | ||
|
||
if opts.method == "PUT" then | ||
local response = request.put(opts.url, opts) | ||
vim.api.nvim_buf_set_lines( | ||
M._state.output_bufnr, | ||
0, | ||
-1, | ||
true, | ||
vim.split(response or "", "\n") | ||
) | ||
end | ||
|
||
if opts.method == "PATCH" then | ||
local response = request.put(opts.url, opts) | ||
vim.api.nvim_buf_set_lines( | ||
M._state.output_bufnr, | ||
0, | ||
-1, | ||
true, | ||
vim.split(response or "", "\n") | ||
) | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
local app = require("hermes.app") | ||
local M = {} | ||
|
||
function M.setup() | ||
vim.api.nvim_create_user_command("HermesShowUI", function() | ||
app.init() | ||
end, { | ||
desc = "Show Hermes UI", | ||
nargs = 0, | ||
}) | ||
vim.api.nvim_create_user_command("HermesHideUi", function() | ||
app.hide() | ||
end, { | ||
|
||
desc = "Hide Hermes Ui ", | ||
nargs = 0, | ||
}) | ||
vim.api.nvim_create_user_command("HermesSetBearerToken", function(opts) | ||
if #opts.fargs ~= 1 then | ||
vim.notify( | ||
"SetBearerToken requires 1 argument", | ||
vim.log.levels.ERROR | ||
) | ||
return | ||
end | ||
|
||
app.set_bearer_token(opts.fargs[1]) | ||
end, { | ||
desc = "Set authorization token", | ||
nargs = 1, | ||
}) | ||
|
||
vim.api.nvim_create_user_command("HermesClearBearerToken", function() | ||
app.set_bearer_token(nil) | ||
end, { | ||
desc = "Clear authorization token", | ||
nargs = 0, | ||
}) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
local M = {} | ||
local curl = require("plenary.curl") | ||
|
||
--- @param url string | ||
--- @param opts table | ||
function M.get(url, opts) | ||
local response = | ||
curl.get(url, { accept = "application/json", query = opts.query or {} }) | ||
if response.status >= 400 then | ||
vim.notify( | ||
"Request failed with status " .. response.status, | ||
vim.log.levels.ERROR | ||
) | ||
return | ||
end | ||
|
||
return response.body | ||
end | ||
|
||
--- @param url string | ||
--- @param opts table | ||
function M.post(url, opts) | ||
local response = | ||
curl.post(url, { accept = "application/json", body = opts.body or {} }) | ||
if response.status >= 400 then | ||
vim.notify( | ||
"Request failed with status " .. response.status, | ||
vim.log.levels.ERROR | ||
) | ||
return | ||
end | ||
|
||
return response.body | ||
end | ||
|
||
--- @param url string | ||
--- @param opts table | ||
function M.put(url, opts) | ||
local response = | ||
curl.put(url, { accept = "application/json", body = opts.body or {} }) | ||
if response.status >= 400 then | ||
vim.notify( | ||
"Request failed with status " .. response.status, | ||
vim.log.levels.ERROR | ||
) | ||
return | ||
end | ||
|
||
return response.body | ||
end | ||
|
||
--- @param url string | ||
--- @param opts table | ||
function M.patch(url, opts) | ||
local response = | ||
curl.patch(url, { accept = "application/json", body = opts.body or {} }) | ||
if response.status >= 400 then | ||
vim.notify( | ||
"Request failed with status " .. response.status, | ||
vim.log.levels.ERROR | ||
) | ||
return | ||
end | ||
|
||
return response.body | ||
end | ||
|
||
return M |