Skip to content

Commit 25f44e9

Browse files
committed
Initial commit
0 parents  commit 25f44e9

File tree

7 files changed

+179
-0
lines changed

7 files changed

+179
-0
lines changed

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
3+
[*]
4+
insert_final_newline = true
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8

.github/workflows/format.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Format
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
format:
7+
name: Stylua
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- run: date +%W > weekly
12+
13+
- name: Restore cache
14+
id: cache
15+
uses: actions/cache@v4
16+
with:
17+
path: |
18+
~/.cargo/bin
19+
key: ${{ runner.os }}-cargo-${{ hashFiles('weekly') }}
20+
21+
- name: Install
22+
if: steps.cache.outputs.cache-hit != 'true'
23+
run: cargo install stylua
24+
25+
- name: Format
26+
run: stylua --check lua/ --config-path=.stylua.toml

.github/workflows/lint.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
name: Luacheck
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Setup
12+
run: |
13+
sudo apt-get update
14+
sudo apt-get install luarocks -y
15+
sudo luarocks install luacheck
16+
17+
- name: Lint
18+
run: luacheck lua/ --globals vim

.stylua.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
indent_type = "Spaces"
2+
indent_width = 2
3+
column_width = 120
4+
[sort_requires]
5+
enabled = true

README.md

Whitespace-only changes.

lua/cmder/init.lua

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
local Window = require("cmder.window")
2+
3+
local M = {}
4+
5+
function M.setup()
6+
end
7+
8+
function M.openMainMenu()
9+
local options = {
10+
"Build with only errors",
11+
"Build and Test",
12+
}
13+
14+
---@param row integer
15+
local function select_current_line(row)
16+
local choice = options[row]
17+
if choice then
18+
M.executeCommand(choice)
19+
end
20+
end
21+
22+
Window.createTelescopeWindow(options, select_current_line, nil, "Available Commands")
23+
end
24+
25+
function M.executeCommand(command)
26+
if command == "Build and Test" then
27+
vim.fn.system("tmux send-keys -t scratch \"dotnet build --interactive && dotnet test\" ^M")
28+
elseif command == "Build with only errors" then
29+
vim.fn.system("tmux send-keys -t scratch \"dotnet build /property:WarningLevel=0\" ^M")
30+
end
31+
vim.fn.system("tmux select-window -t scratch")
32+
end
33+
34+
vim.api.nvim_create_user_command("Cmder", function()
35+
M.openMainMenu()
36+
end, { nargs = "*", desc = "Cmder plugin" })
37+
38+
return M

lua/cmder/window.lua

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
local M = {}
2+
3+
---@param results string[]
4+
---@param callback fun(integer)
5+
function M.createTelescopeWindow(results, callback, prompt_title, results_title)
6+
local pickers = require("telescope.pickers")
7+
local finders = require("telescope.finders")
8+
local conf = require("telescope.config").values
9+
10+
local max_height = 40
11+
local height = math.min(#results + 4, max_height)
12+
pickers
13+
.new({}, {
14+
prompt_title = prompt_title,
15+
results_title = results_title,
16+
finder = finders.new_table({
17+
results = results,
18+
}),
19+
sorter = conf.generic_sorter({}),
20+
layout_strategy = "center",
21+
layout_config = {
22+
width = 80,
23+
height = height,
24+
prompt_position = "bottom",
25+
},
26+
attach_mappings = function(_, map)
27+
map("i", "<CR>", function(prompt_bufnr)
28+
local selection = require("telescope.actions.state").get_selected_entry()
29+
require("telescope.actions").close(prompt_bufnr)
30+
callback(selection.index)
31+
end)
32+
return true
33+
end,
34+
})
35+
:find()
36+
end
37+
38+
---@param options string[]
39+
---@param callback fun(integer)
40+
function M.createWindow(options, callback)
41+
local buf = vim.api.nvim_create_buf(false, true)
42+
local width = 80
43+
local max_height = 20
44+
local height = math.min(#options + 2, max_height)
45+
46+
local ui = vim.api.nvim_list_uis()[1]
47+
48+
local opts = {
49+
relative = "editor",
50+
width = width,
51+
height = height,
52+
row = math.floor((ui.height - height) / 2),
53+
col = math.floor((ui.width - width) / 2),
54+
anchor = "NW",
55+
style = "minimal",
56+
border = "rounded",
57+
}
58+
59+
local win = vim.api.nvim_open_win(buf, false, opts)
60+
vim.api.nvim_set_current_win(win)
61+
vim.api.nvim_buf_set_lines(buf, 0, -1, true, options)
62+
vim.bo[buf].modifiable = false
63+
vim.bo[buf].buftype = "nofile"
64+
vim.api.nvim_set_option_value("winhl", "Normal:MyHighlight", { win = win })
65+
vim.api.nvim_win_set_cursor(win, { 1, 0 })
66+
67+
local function select_current_line()
68+
local row, _ = unpack(vim.api.nvim_win_get_cursor(win))
69+
vim.api.nvim_win_close(win, true)
70+
callback(row)
71+
end
72+
73+
vim.keymap.set("n", "q", function()
74+
vim.api.nvim_win_close(win, true)
75+
end, { buffer = buf, silent = true })
76+
vim.keymap.set("n", "<CR>", select_current_line, { buffer = buf, silent = true })
77+
78+
for i in ipairs(options) do
79+
vim.keymap.set("n", tostring(i), function()
80+
vim.api.nvim_win_close(win, true)
81+
end, { buffer = buf, silent = true })
82+
end
83+
end
84+
85+
return M

0 commit comments

Comments
 (0)