summaryrefslogtreecommitdiffstats
path: root/after/plugin/startpage.lua
blob: afd93dcd3cf5569beca1387f80a7d62a7a67df09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
local status_ok, alpha = pcall(require, "alpha")
if not status_ok then
	return
end

local function button(sc, txt, cmd, kopts, opts)
  opts = opts or {
    position = "center",
    shortcut = sc:gsub("<leader>", "LDR"),
    cursor = 0,
    width = 49,
    align_shortcut = "right",
    hl_shortcut = "AlphaShortcut",
    hl = "AlphaText",
  }
  if cmd then
    kopts = kopts or { noremap = true, silent = true, nowait = true }
    opts.keymap = { "n", sc, cmd, kopts }
  end

  local function on_press()
    local key = vim.api.nvim_replace_termcodes(cmd, true, false, true)
    vim.api.nvim_feedkeys(key, "t", false)
  end

  return {
    type = "button",
    val = txt,
    opts = opts,
    on_press = on_press,
  }
end

local header = {
  '█▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀█  █▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀█   ',
  '█ ░█████▀▀▀▀▀█████▓▄ ▀▀▀▀  ░   ░█   ░█   ░█  █   ',
  '█ ▒███████   ▓███████     ▒██ ▓███ ▓███ ▓███ █   ',
  '█ ▓███████   ▓███████     ▓█████████████████ █   ',
  '█ ▓███████   ▓███████     ███ ██████████████ █   ',
  '█ ▓███████   ▓███████     ███ ██████████████ █   ',
  '█ ▓███████   ▓███████     ███ ██████████████ █   ',
  '█ ▓███████   ▓███████     ███▄██████████████ █   ',
  '█ ▓███████   ▓███████     ██████▀▀██████████ █   ',
  '▀ ▓███████   ▓███████▄         ▄▄███████████ █   ',
  '█ ▓███████                ██████████████████ █▄▄▄',
  '█ ▓███████▀▀ ▀    ▀        ▀████████████████▄ ▄ █',
  '█▄▄▄▄▄▄▄ ▀ █▀▀▀▀▀▀▀▀▀▀▀▀█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█',
  '       █ ▀ █                                     ',
  '       ▀▀▀▀▀                                     ',
}
local footer = {
  '▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄',
}

alpha.setup {
  layout = {
    { type = 'text', val = function()
      local padding = {}
      for i = 1, math.floor((vim.api.nvim_win_get_height(0) - #header - 6 - #footer) / 2), 1 do
        table.insert(padding, " ")
      end
      return padding
    end },
    { type = 'text', val = header, opts = {
      position = 'center',
      hl = 'AlphaHeader',
    } },
    { type = 'padding', val = 1 },
    { type = 'group', val = {
      button('f', '? Find files', '<cmd>Telescope find_files<CR>'),
      button('r', '↺ Recent files', '<cmd>Telescope oldfiles <CR>'),
      button('n', '▣ Neorg workspace', '<cmd>Telescope neorg switch_workspace<CR>'),
      button('m', '≡ Menu', '<cmd>lua require("core.conf").configmenu()<CR>'),
      button('q', '✖ Quit', '<cmd>wqa<CR>'),
    } },
    { type = 'text', val = footer, opts = {
      position = 'center',
      hl = 'AlphaFooter',
    } },
  },
  opts = {
    keymap = {
      press = '<CR>',
      press_queue = nil
    },
    setup = function()
      vim.api.nvim_create_autocmd('User', {
        pattern = 'AlphaReady',
        desc = 'disable stuff for alpha',
        callback = function()
          vim.opt.laststatus = 0
          vim.opt.showtabline = 0
          vim.opt.more = false
          vim.opt.showcmd = false
          vim.opt.ruler = false
          vim.opt.number = false
          vim.opt.relativenumber = false
        end,
      })
      vim.api.nvim_create_autocmd('BufUnload', {
        buffer = 0,
        desc = 'enable stuff after alpha closes',
        callback = function()
          vim.opt.laststatus = 3
          vim.opt.showtabline = 2
          vim.opt.more = true
          vim.opt.showcmd = true
          vim.opt.ruler = true
          vim.opt.number = false
          vim.opt.relativenumber = false
        end,
      })
    end,
  }
}