From a252e1c79a3f1dd1026043b3062bf2af3e2d8ce1 Mon Sep 17 00:00:00 2001 From: Icelk Date: Wed, 5 Jul 2023 23:50:00 +0200 Subject: [PATCH] Make telescope theme change depending on screen size --- config/nvim/lua/plugins.lua | 50 ++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua index 3032cb2f..fd5c0853 100644 --- a/config/nvim/lua/plugins.lua +++ b/config/nvim/lua/plugins.lua @@ -70,23 +70,39 @@ vim.o.foldexpr = "nvim_treesitter#foldexpr()" local telescope = require "telescope" local telescope_actions = require "telescope.actions" local tele_builtin = require "telescope.builtin" --- local tele_theme = require "telescope.themes".get_ivy() -local tele_theme = nil +local tele_theme_dropdown = require "telescope.themes".get_dropdown() +local tele_theme_cursor = require "telescope.themes".get_cursor() +local tele_theme_default = nil + +function dynamic_theme() + local width = vim.api.nvim_win_get_width(0) + local height = vim.api.nvim_win_get_height(0) + + if width / 2 > height then + return tele_theme_default + else + return tele_theme_dropdown + end +end +local theme = dynamic_theme + telescope.setup { defaults = { mappings = { i = { [""] = telescope_actions.close } } } } -- Telescope for nvim UI -require "dressing".setup { select = { telescope = tele_theme } } +require "dressing".setup { select = { telescope = tele_theme_cursor } } -nmap("", function() tele_builtin.find_files(tele_theme) end) -nmap("", function() tele_builtin.oldfiles(tele_theme) end) -nmap("", function() tele_builtin.grep_string(tele_theme) end) -nmap("S", function() tele_builtin.spell_suggest(tele_theme) end) +nmap("", function() tele_builtin.find_files(theme()) end) +nmap("", function() tele_builtin.oldfiles(theme()) end) +nmap("", function() tele_builtin.treesitter(theme()) end) +nmap("", function() tele_builtin.grep_string(theme()) end) +nmap("S", function() tele_builtin.spell_suggest(theme()) end) +nmap("", function() tele_builtin.current_buffer_fuzzy_find(theme()) end) -nmap("a", function() tele_builtin.diagnostics(tele_theme) end) -nmap("b", function() tele_builtin.buffers(tele_theme) end) -nmap("c", function() tele_builtin.git_bcommits(tele_theme) end) -nmap("g", function() tele_builtin.git_stash(tele_theme) end) +nmap("a", function() tele_builtin.diagnostics(theme()) end) +nmap("b", function() tele_builtin.buffers(theme()) end) +nmap("c", function() tele_builtin.git_bcommits(theme()) end) +nmap("g", function() tele_builtin.git_stash(theme()) end) require('nvim_comment').setup({ create_mappings = true, line_mapping = "cc", operator_mapping = "c" }) @@ -168,10 +184,10 @@ local on_attach = function(client, bufnr) local opts = { noremap = true, silent = true, buffer = bufnr } -- Remap keys for gotos - nmapo("gd", function() tele_builtin.lsp_definitions(tele_theme) end, opts) - nmapo("gy", function() tele_builtin.lsp_type_definitions(tele_theme) end, opts) - nmapo("gi", function() tele_builtin.lsp_implementations(tele_theme) end, opts) - nmapo("gr", function() tele_builtin.lsp_references(tele_theme) end, opts) + nmapo("gd", function() tele_builtin.lsp_definitions(theme()) end, opts) + nmapo("gy", function() tele_builtin.lsp_type_definitions(theme()) end, opts) + nmapo("gi", function() tele_builtin.lsp_implementations(theme()) end, opts) + nmapo("gr", function() tele_builtin.lsp_references(theme()) end, opts) nmapo('gD', vim.lsp.buf.declaration, opts) -- nmapo('', vim.lsp.buf.signature_help, bufopts) @@ -204,8 +220,8 @@ local on_attach = function(client, bufnr) nvmapo("f", function() vim.lsp.buf.code_action(nil, nil, true) end); - nmapo("o", function() tele_builtin.lsp_dynamic_workspace_symbols(tele_theme) end, opts) - nmapo("s", function() tele_builtin.lsp_document_symbols(tele_theme) end, opts) + nmapo("o", function() tele_builtin.lsp_dynamic_workspace_symbols(theme()) end, opts) + nmapo("s", function() tele_builtin.lsp_document_symbols(theme()) end, opts) end