Skip to content

Conversation

@bennypowers
Copy link
Contributor

following on from #185 , this allows users to calculate terminal window options like height and width dynamically

following on from goolord#185 , this allows users to calculate terminal window options like height and width dynamically
@bennypowers
Copy link
Contributor Author

bennypowers commented Feb 23, 2023

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
}

@goolord goolord force-pushed the main branch 2 times, most recently from e7b2cc3 to 1356b9e Compare January 30, 2024 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant