Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
}
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
git clone --depth 1 https://github.com/MunifTanjim/nui.nvim ~/.local/share/nvim/site/pack/vendor/start/nui.nvim
git clone --depth 1 https://github.com/grapp-dev/nui-components.nvim ~/.local/share/nvim/site/pack/vendor/start/nui-components.nvim
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start

- name: Install latest stable `rustc`
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
jobs:
luarocks-upload:
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
- name: LuaRocks Upload
Expand Down
21 changes: 15 additions & 6 deletions lua/spectre/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ local config = {
lnum_UI = 8, -- total line for ui you can edit it
line_result = 10, -- line begin result

-- result_padding = '│ ',
-- color_devicons = true,
-- line_sep_start = '┌-----------------------------------------',
-- result_padding = '¦ ',
-- line_sep = '├──────────────────────────────────────',

-- TODO: make it deprecated
line_sep_start = '┌──────────────────────────────────────────────────────',
result_padding = '│ ',
line_sep = '└──────────────────────────────────────────────────────',

color_devicons = true,
open_cmd = 'vnew',
live_update = false,
Expand Down Expand Up @@ -220,6 +216,19 @@ local config = {
is_insert_mode = false,
is_block_ui_break = false,
open_template = {},

ui = {
default = 'buffer',
buffer = {
lnum_UI = 8, -- total line for ui you can edit it
line_result = 10, -- line begin result

line_sep_start = '┌──────────────────────────────────────────────────────',
result_padding = '│ ',
line_sep = '└──────────────────────────────────────────────────────',
},
float = {},
},
}

return config
37 changes: 15 additions & 22 deletions lua/spectre/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local config = require('spectre.config')
local state = require('spectre.state')
local state_utils = require('spectre.state_utils')
local utils = require('spectre.utils')
local ui = require('spectre.ui')
local ui = nil
local log = require('spectre._log')
local async = require('plenary.async')

Expand All @@ -38,6 +38,7 @@ M.setup = function(cfg)
state.options[opt] = true
end
require('spectre.highlight').set_hl()

M.check_replace_cmd_bins()
end

Expand Down Expand Up @@ -119,6 +120,14 @@ M.open = function(opts)
M.setup()
end

if state.user_config.ui.default == 'buffer' then
ui = require('spectre.ui.buffer')
elseif state.user_config.ui.default == 'float' then
ui = require('spectre.ui.float')
else
vim.notify('Invalid ui type: ' .. state.user_config.ui, vim.log.levels.ERROR)
end

opts = vim.tbl_extend('force', {
cwd = nil,
is_insert_mode = state.user_config.is_insert_mode,
Expand Down Expand Up @@ -163,29 +172,9 @@ M.open = function(opts)
end
end

vim.wo.foldenable = false
vim.bo.buftype = 'nofile'
vim.bo.buflisted = false
state.bufnr = api.nvim_get_current_buf()
vim.cmd(string.format('file %s/spectre', state.bufnr))
vim.bo.filetype = config.filetype
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_status, 0, -1)
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_result, 0, -1)
api.nvim_buf_set_lines(state.bufnr, 0, -1, false, {})

vim.api.nvim_buf_attach(state.bufnr, false, {
on_detach = M.stop,
})
ui.render_text_query(opts)

state.cwd = opts.cwd
state.search_paths = opts.search_paths
M.change_view('reset')
ui.render_search_ui()

if opts.is_insert_mode == true then
vim.api.nvim_feedkeys('A', 'n', true)
end
ui.open(opts)

M.mapping_buffer(state.bufnr)

Expand All @@ -208,6 +197,10 @@ M.toggle = function(opts)
end

function M.mapping_buffer(bufnr)
if state.user_config.ui.default ~= 'buffer' then
return
end

_G.__spectre_fold = M.get_fold
vim.cmd([[augroup spectre_panel
au!
Expand Down
26 changes: 26 additions & 0 deletions lua/spectre/ui.lua → lua/spectre/ui/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ local api = vim.api

local M = {}

M.open = function(opts)
vim.wo.foldenable = false
vim.bo.buftype = 'nofile'
vim.bo.buflisted = false
state.bufnr = api.nvim_get_current_buf()
vim.cmd(string.format('file %s/spectre', state.bufnr))
vim.bo.filetype = config.filetype
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_status, 0, -1)
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_result, 0, -1)
api.nvim_buf_set_lines(state.bufnr, 0, -1, false, {})

vim.api.nvim_buf_attach(state.bufnr, false, {
on_detach = M.stop,
})

M.render_text_query(opts)

state.cwd = opts.cwd
state.search_paths = opts.search_paths
M.render_search_ui()

if opts.is_insert_mode == true then
vim.api.nvim_feedkeys('A', 'n', true)
end
end

---@param regex RegexEngine
M.render_line = function(bufnr, namespace, text_opts, view_opts, regex)
local cfg = state.user_config
Expand Down
Loading