a vim plugin that displays stuff on an led matrix
1-- Braille Typing Indicator Plugin for Neovim
2-- This is a proper plugin structure for installation in your Neovim config
3
4local M = {}
5
6-- Braille unicode characters (⠀ to ⣿)
7local brailleChars = {
8 '⠀', '⠁', '⠂', '⠃', '⠄', '⠅', '⠆', '⠇', '⠈', '⠉', '⠊', '⠋', '⠌', '⠍', '⠎', '⠏',
9 '⠐', '⠑', '⠒', '⠓', '⠔', '⠕', '⠖', '⠗', '⠘', '⠙', '⠚', '⠛', '⠜', '⠝', '⠞', '⠟',
10 '⠠', '⠡', '⠢', '⠣', '⠤', '⠥', '⠦', '⠧', '⠨', '⠩', '⠪', '⠫', '⠬', '⠭', '⠮', '⠯',
11 '⠰', '⠱', '⠲', '⠳', '⠴', '⠵', '⠶', '⠷', '⠸', '⠹', '⠺', '⠻', '⠼', '⠽', '⠾', '⠿',
12 '⡀', '⡁', '⡂', '⡃', '⡄', '⡅', '⡆', '⡇', '⡈', '⡉', '⡊', '⡋', '⡌', '⡍', '⡎', '⡏',
13 '⡐', '⡑', '⡒', '⡓', '⡔', '⡕', '⡖', '⡗', '⡘', '⡙', '⡚', '⡛', '⡜', '⡝', '⡞', '⡟',
14 '⡠', '⡡', '⡢', '⡣', '⡤', '⡥', '⡦', '⡧', '⡨', '⡩', '⡪', '⡫', '⡬', '⡭', '⡮', '⡯',
15 '⡰', '⡱', '⡲', '⡳', '⡴', '⡵', '⡶', '⡷', '⡸', '⡹', '⡺', '⡻', '⡼', '⡽', '⡾', '⡿',
16 '⢀', '⢁', '⢂', '⢃', '⢄', '⢅', '⢆', '⢇', '⢈', '⢉', '⢊', '⢋', '⢌', '⢍', '⢎', '⢏',
17 '⢐', '⢑', '⢒', '⢓', '⢔', '⢕', '⢖', '⢗', '⢘', '⢙', '⢚', '⢛', '⢜', '⢝', '⢞', '⢟',
18 '⢠', '⢡', '⢢', '⢣', '⢤', '⢥', '⢦', '⢧', '⢨', '⢩', '⢪', '⢫', '⢬', '⢭', '⢮', '⢯',
19 '⢰', '⢱', '⢲', '⢳', '⢴', '⢵', '⢶', '⢷', '⢸', '⢹', '⢺', '⢻', '⢼', '⢽', '⢾', '⢿',
20 '⣀', '⣁', '⣂', '⣃', '⣄', '⣅', '⣆', '⣇', '⣈', '⣉', '⣊', '⣋', '⣌', '⣍', '⣎', '⣏',
21 '⣐', '⣑', '⣒', '⣓', '⣔', '⣕', '⣖', '⣗', '⣘', '⣙', '⣚', '⣛', '⣜', '⣝', '⣞', '⣟',
22 '⣠', '⣡', '⣢', '⣣', '⣤', '⣥', '⣦', '⣧', '⣨', '⣩', '⣪', '⣫', '⣬', '⣭', '⣮', '⣯',
23 '⣰', '⣱', '⣲', '⣳', '⣴', '⣵', '⣶', '⣷', '⣸', '⣹', '⣺', '⣻', '⣼', '⣽', '⣾', '⣿'
24}
25
26-- Current braille character
27local currentBraille = brailleChars[1]
28
29-- Update braille character randomly
30local function updateBrailleChar()
31 -- Use os.time() for randomness
32 math.randomseed(os.time() * 1000 + os.clock() * 10000)
33 local idx = math.random(1, #brailleChars)
34 currentBraille = brailleChars[idx]
35 return currentBraille
36end
37
38-- Get current braille character for statusline
39function M.getBrailleIndicator()
40 return currentBraille
41end
42
43-- Setup function with options
44function M.setup(opts)
45 opts = opts or {}
46
47 -- Make sure statusline is visible
48 vim.o.laststatus = 2
49
50 -- Key press handler
51 local function onKeyPress()
52 -- Update braille character
53 updateBrailleChar()
54 end
55
56 -- Set up autocommands
57 vim.api.nvim_create_autocmd({"InsertCharPre", "CursorMovedI"}, {
58 callback = onKeyPress,
59 group = vim.api.nvim_create_augroup("BrailleIndicator", { clear = true })
60 })
61
62 -- Make the function available globally for statusline
63 _G.getBrailleIndicator = M.getBrailleIndicator
64
65 -- Add to statusline if requested
66 if opts.update_statusline then
67 vim.o.statusline = "%{v:lua.getBrailleIndicator()} %f %m %r %= %l,%c "
68 end
69
70 -- Print setup message
71 if opts.verbose then
72 print("Braille indicator active. The character will change as you type.")
73 print("Add %{v:lua.getBrailleIndicator()} to your statusline if not already there.")
74 end
75end
76
77return M