slightly better small screen UX

This commit is contained in:
TJ DeVries
2020-08-27 22:55:44 -04:00
parent bb446421c5
commit 4100795d0c
3 changed files with 24 additions and 6 deletions

View File

@@ -52,7 +52,8 @@ keymap["control-p"] = function(prompt_bufnr, _)
end end
keymap["enter"] = function(prompt_bufnr, results_bufnr) keymap["enter"] = function(prompt_bufnr, results_bufnr)
local entry = state.get_status(prompt_bufnr).picker:get_selection() local picker = state.get_status(prompt_bufnr).picker
local entry = picker:get_selection()
if not entry then if not entry then
print("[telescope] Nothing currently selected") print("[telescope] Nothing currently selected")
@@ -72,6 +73,8 @@ keymap["enter"] = function(prompt_bufnr, results_bufnr)
vim.cmd(string.format([[bdelete! %s]], prompt_bufnr)) vim.cmd(string.format([[bdelete! %s]], prompt_bufnr))
a.nvim_set_current_win(picker.original_win_id or 0)
local bufnr = vim.fn.bufnr(filename, true) local bufnr = vim.fn.bufnr(filename, true)
a.nvim_set_current_buf(bufnr) a.nvim_set_current_buf(bufnr)
a.nvim_buf_set_option(bufnr, 'buflisted', true) a.nvim_buf_set_option(bufnr, 'buflisted', true)

View File

@@ -51,9 +51,12 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
enter = true enter = true
} }
-- TODO: Test with 120 width terminal
local width_padding = 10 local width_padding = 10
if max_columns < 150 then if max_columns < 150 then
preview.width = 60 width_padding = 5
preview.width = math.floor(max_columns * 0.4)
elseif max_columns < 200 then elseif max_columns < 200 then
preview.width = 80 preview.width = 80
else else
@@ -64,7 +67,13 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
results.width = other_width results.width = other_width
prompt.width = other_width prompt.width = other_width
results.height = 25 local base_height
if max_lines < 40 then
base_height = math.floor(max_lines * 0.5)
else
base_height = math.floor(max_lines * 0.8)
end
results.height = base_height
results.minheight = results.height results.minheight = results.height
prompt.height = 1 prompt.height = 1
prompt.minheight = prompt.height prompt.minheight = prompt.height
@@ -76,7 +85,8 @@ function Picker._get_window_options(max_columns, max_lines, prompt_title)
prompt.col = width_padding prompt.col = width_padding
preview.col = results.col + results.width + 2 preview.col = results.col + results.width + 2
local height_padding = math.floor(0.95 * max_lines) -- TODO: Center this in the page a bit better.
local height_padding = math.max(math.floor(0.95 * max_lines), 2)
results.line = max_lines - height_padding results.line = max_lines - height_padding
prompt.line = results.line + results.height + 2 prompt.line = results.line + results.height + 2
preview.line = results.line preview.line = results.line
@@ -97,6 +107,8 @@ function Picker:find(opts)
local sorter = opts.sorter local sorter = opts.sorter
local prompt_string = opts.prompt local prompt_string = opts.prompt
self.original_win_id = a.nvim_get_current_win()
-- Create three windows: -- Create three windows:
-- 1. Prompt window -- 1. Prompt window
-- 2. Options window -- 2. Options window

View File

@@ -5,6 +5,9 @@ local previewers = {}
local Previewer = {} local Previewer = {}
Previewer.__index = Previewer Previewer.__index = Previewer
local bat_options = "--style=grid --paging=always --wrap=never"
-- --terminal-width=%s
function Previewer:new(opts) function Previewer:new(opts)
opts = opts or {} opts = opts or {}
@@ -122,7 +125,7 @@ previewers.vimgrep = previewers.new {
setup = function() setup = function()
local command_string = "cat %s" local command_string = "cat %s"
if vim.fn.executable("bat") then if vim.fn.executable("bat") then
command_string = "bat %s --style=grid --paging=always --highlight-line %s -r %s:%s" command_string = "bat %s --highlight-line %s -r %s:%s" .. bat_options
end end
return { return {
@@ -160,7 +163,7 @@ previewers.qflist = previewers.new {
setup = function() setup = function()
local command_string = "cat %s" local command_string = "cat %s"
if vim.fn.executable("bat") then if vim.fn.executable("bat") then
command_string = "bat %s --style=grid --paging=always --highlight-line %s -r %s:%s" command_string = "bat %s --highlight-line %s -r %s:%s"
end end
return { return {