From 2129bcf84f59b84301f745e1f374bcf8806f52e5 Mon Sep 17 00:00:00 2001 From: NTBBloodbath Date: Fri, 17 Sep 2021 05:59:45 -0400 Subject: [PATCH] feat: add SearchResults provider, see glepnir#205 --- README.md | 26 +++++++++++++++----------- lua/galaxyline/provider.lua | 2 ++ lua/galaxyline/providers/search.lua | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 lua/galaxyline/providers/search.lua diff --git a/README.md b/README.md index 0e45965..5f0446f 100644 --- a/README.md +++ b/README.md @@ -74,21 +74,23 @@ using multiple then you must provide an array table for `provider`. ```lua ---- source provider functions -- Code diagnostics -local diagnostic = require("galaxyline.provider_diagnostic") +local diagnostic = require("galaxyline.providers.diagnostic") -- Version control -local vcs = require("galaxyline.provider_vcs") +local vcs = require("galaxyline.providers.vcs") -- Core files information -local fileinfo = require("galaxyline.provider_fileinfo") --- File extension -local extension = require("galaxyline.provider_extensions") +local fileinfo = require("galaxyline.providers.fileinfo") +-- Extensions, aka plugins +local extension = require("galaxyline.providers.extensions") -- Neovim highlighting -local colors = require("galaxyline.colors") +local colors = require("galaxyline.highlighting") -- Buffer information, e.g. corresponding icon -local buffer = require("galaxyline.provider_buffer") +local buffer = require("galaxyline.providers.buffer") +-- Search results +local search = require("galaxyline.providers.search") -- Spacing -local whitespace = require("galaxyline.provider_whitespace") +local whitespace = require("galaxyline.providers.whitespace") -- Active language server information -local lspclient = require("galaxyline.provider_lsp") +local lspclient = require("galaxyline.providers.lsp") ---- Providers @@ -100,6 +102,8 @@ GitBranch = vcs.get_git_branch DiffAdd = vcs.diff_add -- support vim-gitgutter vim-signify gitsigns DiffModified = vcs.diff_modified -- support vim-gitgutter vim-signify gitsigns DiffRemove = vcs.diff_remove -- support vim-gitgutter vim-signify gitsigns +-- Search Provider +SearchResults = search.get_search_results, -- File Provider LineColumn = fileinfo.line_column FileFormat = fileinfo.get_file_format @@ -123,9 +127,9 @@ GetLspClient = lspclient.get_lsp_client ---- Public libs -- Get file icon color -require("galaxyline.provider_fileinfo").get_file_icon_color +require("galaxyline.providers.fileinfo").get_file_icon_color -- Custom file icon with color -local my_icons = require("galaxyline.provider_fileinfo").define_file_icon() +local my_icons = require("galaxyline.providers.fileinfo").define_file_icon() my_icons['your file type here'] = { color code, icon} -- If your filetype does is not defined in neovim you can use file extensions my_icons['your file ext in here'] = { color code, icon} diff --git a/lua/galaxyline/provider.lua b/lua/galaxyline/provider.lua index 71d11e6..c96d0e8 100644 --- a/lua/galaxyline/provider.lua +++ b/lua/galaxyline/provider.lua @@ -2,6 +2,7 @@ local function load_providers() local vcs = require("galaxyline.providers.vcs") local fileinfo = require("galaxyline.providers.fileinfo") local buffer = require("galaxyline.providers.buffer") + local search = require("galaxyline.providers.search") local extension = require("galaxyline.providers.extensions") local whitespace = require("galaxyline.providers.whitespace") local lspclient = require("galaxyline.providers.lsp") @@ -26,6 +27,7 @@ local function load_providers() VistaPlugin = extension.vista_nearest, WhiteSpace = whitespace.get_item, GetLspClient = lspclient.get_lsp_client, + SearchResults = search.get_search_results, } local diagnostic = require("galaxyline.providers.diagnostic") diff --git a/lua/galaxyline/providers/search.lua b/lua/galaxyline/providers/search.lua new file mode 100644 index 0000000..63806fb --- /dev/null +++ b/lua/galaxyline/providers/search.lua @@ -0,0 +1,16 @@ +local search = {} + +function search.get_results() + local search_term = vim.fn.getreg("/") + local search_count = vim.fn.searchcount({ + recompute = 1, + maxcount = -1, + }) + + local active_result = vim.v.hlsearch == 1 and search_count.total > 0 + if active_result then + return string.format("/%s [%d/%d]", search_term, search_count.current, search_count.total) + end +end + +return search