repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/after/ftplugin/vfp.lua
RawFile outline
-- File: C:\Users\okr\AppData\Local\nvim\ftplugin\vfp.lua
-- Always-on dark flair for Visual FoxPro 9.0 (.prg files), blended with current theme
local api = vim.api
-- Dark flair palette
local dark_flair = {
neon_red = '#FF1A1A',
cyber_green = '#00FF66',
shadow_purple = '#8A2BE2',
toxic_yellow = '#FFFF33',
gunmetal_gray = '#333333',
faint_glow = '#666666',
}
-- OKLab blending
local function rgb_to_oklab( r, g, b )
r, g, b = r / 255, g / 255, b / 255
local l = 0.412221 * r + 0.536332 * g + 0.051447 * b
local m = 0.211666 * r + 0.680525 * g + 0.107809 * b
local s = 0.088302 * r + 0.281718 * g + 0.629980 * b
l, m, s = l ^ (1 / 3), m ^ (1 / 3), s ^ (1 / 3)
local L = 0.210454 * l + 0.793617 * m - 0.004071 * s
local a = 1.977998 * l - 2.428592 * m + 0.450594 * s
local b_ = 0.025904 * l + 0.782771 * m - 0.808675 * s
return L, a, b_
end
local function oklab_to_rgb( L, a, b_ )
local l = L + 0.396337 * a + 0.215803 * b_
local m = L - 0.105561 * a - 0.063854 * b_
local s = L - 0.089484 * a - 1.291485 * b_
l, m, s = l ^ 3, m ^ 3, s ^ 3
local r = 4.076741 * l - 3.307711 * m + 0.230969 * s
local g = -1.268143 * l + 2.609757 * m - 0.341319 * s
local b = -0.004196 * l - 0.703228 * m + 1.707614 * s
r, g, b = math.max( 0, math.min( 1, r ) ) * 255, math.max( 0, math.min( 1, g ) ) * 255,
math.max( 0, math.min( 1, b ) ) * 255
return math.floor( r ), math.floor( g ), math.floor( b )
end
local function blend_colors( fg_hex, bg_hex, factor )
local fr, fg, fb = fg_hex:match '#(%x%x)(%x%x)(%x%x)'
fr, fg, fb = tonumber( fr, 16 ) or 0, tonumber( fg, 16 ) or 0, tonumber( fb, 16 ) or 0
local br, bg, bb = bg_hex:match '#(%x%x)(%x%x)(%x%x)'
br, bg, bb = tonumber( br, 16 ) or 0, tonumber( bg, 16 ) or 0, tonumber( bb, 16 ) or 0
local fL, fa, fb_ = rgb_to_oklab( fr, fg, fb )
local bL, ba, bb_ = rgb_to_oklab( br, bg, bb )
local L = bL + factor * (fL - bL)
local a = ba + factor * (fa - ba)
local b = bb_ + factor * (fb_ - bb_)
local r, g, b = oklab_to_rgb( L, a, b ) ---@diagnostic disable-line: redefined-local
return string.format( '#%02x%02x%02x', r, g, b )
end
-- Fetch theme colors with nvim_get_hl
local function get_theme_colors()
local comment = api.nvim_get_hl( 0, { name = 'Comment' } ) or {}
local statement = api.nvim_get_hl( 0, { name = 'Statement' } ) or {}
local identifier = api.nvim_get_hl( 0, { name = 'Identifier' } ) or {}
local str = api.nvim_get_hl( 0, { name = 'String' } ) or {}
local constant = api.nvim_get_hl( 0, { name = 'Constant' } ) or {}
local operator = api.nvim_get_hl( 0, { name = 'Operator' } ) or {}
local err = api.nvim_get_hl( 0, { name = 'Error' } ) or {}
return {
comment = comment.fg and string.format( '#%06x', comment.fg ) or '#808080',
statement = statement.fg and string.format( '#%06x', statement.fg ) or '#FFFF00',
identifier = identifier.fg and string.format( '#%06x', identifier.fg ) or '#00FFFF',
str = str.fg and string.format( '#%06x', str.fg ) or '#FF00FF',
constant = constant.fg and string.format( '#%06x', constant.fg ) or '#00FF00',
operator = operator.fg and string.format( '#%06x', operator.fg ) or '#FF0000',
error = err.fg and string.format( '#%06x', err.fg ) or '#FF0000',
}
end
-- Apply dark flair
local function apply_dark_flair( buf )
local theme = get_theme_colors()
local blend_factor = 0.7
-- Create a buffer-local namespace
local ns_id = api.nvim_create_namespace( 'vfp_dark_flair_' .. buf )
-- Blend colors
local blended = {
special = blend_colors( dark_flair.neon_red, theme.operator, blend_factor ),
preproc = blend_colors( dark_flair.shadow_purple, theme.str, blend_factor ),
cmd = blend_colors( dark_flair.toxic_yellow, theme.statement, blend_factor ),
func = blend_colors( dark_flair.toxic_yellow, theme.identifier, blend_factor ),
sysvar = blend_colors( dark_flair.shadow_purple, theme.str, blend_factor ),
str = blend_colors( dark_flair.shadow_purple, theme.str, blend_factor ),
const = blend_colors( dark_flair.cyber_green, theme.constant, blend_factor ),
number = blend_colors( dark_flair.cyber_green, theme.constant, blend_factor ),
operator = blend_colors( dark_flair.neon_red, theme.operator, blend_factor ),
comment = blend_colors( dark_flair.faint_glow, theme.comment, blend_factor ),
error = blend_colors( dark_flair.neon_red, theme.error, blend_factor ),
xmlfunc = blend_colors( dark_flair.cyber_green, theme.identifier, blend_factor ),
oop = blend_colors( dark_flair.cyber_green, theme.identifier, blend_factor ),
line = blend_colors( dark_flair.faint_glow, theme.comment, 0.4 ),
}
api.nvim_set_hl( ns_id, 'vfpSpecial', { fg = blended.special, bold = true } )
api.nvim_set_hl( ns_id, 'vfpPreProc', { fg = blended.preproc, italic = true } )
api.nvim_set_hl( ns_id, 'vfpCmd', { fg = blended.cmd, bold = true } )
api.nvim_set_hl( ns_id, 'vfpFunc', { fg = blended.func } )
api.nvim_set_hl( ns_id, 'vfpSysVar', { fg = blended.sysvar } )
api.nvim_set_hl( ns_id, 'vfpString', { fg = blended.str, italic = true } )
api.nvim_set_hl( ns_id, 'vfpConst', { fg = blended.const } )
api.nvim_set_hl( ns_id, 'vfpNumber', { fg = blended.number } )
api.nvim_set_hl( ns_id, 'vfpFloat', { fg = blended.number } )
api.nvim_set_hl( ns_id, 'vfpOperator', { fg = blended.operator, bold = true } )
api.nvim_set_hl( ns_id, 'vfpComment', { fg = blended.comment, italic = true } )
api.nvim_set_hl( ns_id, 'vfpError', { fg = blended.error, bg = blended.bg, underline = true } )
api.nvim_set_hl( ns_id, 'vfpXmlFunc', { fg = blended.xmlfunc, bold = true } )
api.nvim_set_hl( ns_id, 'vfpOop', { fg = blended.oop, italic = true } )
api.nvim_set_hl( ns_id, 'Normal', { bg = blended.bg } )
api.nvim_set_hl( ns_id, 'LineNr', { fg = blended.line } )
end
-- Autocommand to apply flair only to VFP buffers
api.nvim_create_autocmd( 'BufEnter', {
pattern = '*.prg',
callback = function ()
local buf = api.nvim_get_current_buf()
apply_dark_flair( buf )
end,
} )