feat: allow term window_options to be a function#188
Open
bennypowers wants to merge 1 commit intogoolord:mainfrom
Open
feat: allow term window_options to be a function#188bennypowers wants to merge 1 commit intogoolord:mainfrom
bennypowers wants to merge 1 commit intogoolord:mainfrom
Conversation
following on from goolord#185 , this allows users to calculate terminal window options like height and width dynamically
Contributor
Author
|
example config which selects a colorscript based on vim window size, then calculates the term size to match return { 'goolord/alpha-nvim',
enabled = true,
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-tree/nvim-web-devicons',
},
config = function()
local mru = require'utils'.mru
local alpha = require 'alpha'
local term = require 'alpha.term'
local dashboard = require 'alpha.themes.dashboard'
local nvim_web_devicons = require 'nvim-web-devicons'
local width = 16
local height = 16
local heights = {
[16] = 12,
[32] = 16,
[48] = 28,
[64] = 32,
}
local custom_heights = {
['ness.bike'] = 24,
nessy = 30,
runaway5 = 24,
phasedistorter = 24,
skyrunner = 24,
}
alpha.setup {
layout = {
{
type = 'terminal',
command = function()
local cats = {16}
local winwidth = vim.fn.winwidth'%'
local winheight = vim.fn.winheight'%'
if winheight >= 40 then table.insert(cats, 32) end
if winheight >= 60 then table.insert(cats, 48) end
if winwidth >= 100 and winheight >= 60 then table.insert(cats, 64) end
local headers_dir = vim.fn.expand'~/.config/nvim/headers/'
local headers = {}
for _, size in ipairs(cats) do
for _, filename in ipairs(vim.fn.readdir(headers_dir .. size)) do
table.insert(headers, { size, headers_dir .. size .. '/' .. filename })
end
end
local size, path = unpack(headers[math.random(1, #headers)])
local name = path:match'/([%w%.]+)%.sh$'
width = size
height = custom_heights[name] or heights[size] or 16
return 'cat | ' .. path
end,
opts = {
redraw = true,
window_config = function()
return {
noautocmd = true,
focusable = false,
zindex = 1,
width = width,
height = height,
}
end,
},
},
{ type = 'padding', val = function() return height + 4 end },
{
type = 'group',
val = function()
-- mru
end,
},
{ type = 'padding', val = 2 },
{
type = 'group',
val = { }, -- buttons
},
}
end
} |
e7b2cc3 to
1356b9e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
following on from #185 , this allows users to calculate terminal window options like height and width dynamically