wezterm: refix font deletion, because aborting rebase yeeted my chages...
b58ace8250b9a1512d96a3009f0b76504fb1f7ff
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 404749a1a5fd
bugabingas dorkfiles
b58ace8250b9a1512d96a3009f0b76504fb1f7ff
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+9 / −281 text lines
+2 / −0 text lines
deleted file mode 100644+0 / −113 text lines
local wez = require 'wezterm'local csv_line_pattern = '^%s*(%d+)%s*,%s*(.-)%s*$'local adjust_font_randomness_weight = function ( font_family, adjust ) local code_fonts = io.open( wez.config_dir .. '/bugabinga/code_fonts.csv', 'r+' ) if code_fonts then local new_lines = {} for line in code_fonts:lines() do local weight, font_name = line:match( csv_line_pattern ) if not weight or not font_name then wez.log_error 'Could not parse code_fonts.csv. Borked?' return end weight = tonumber( weight ) if font_name == font_family then weight = math.max( 0, adjust( weight ) ) end table.insert( new_lines, weight .. ',' .. font_name ) end code_fonts:seek( 'set', 0 ) for _, new_line in ipairs( new_lines ) do code_fonts:write( new_line, '\n' ) end code_fonts:close() else wez.log_error 'Unable to read and write code_fonts.csv!' endend-- like the current font.-- liked fonts have higher probablity of being picked on wezterm boot.-- increase the weight of the font in code_fonts.csv.-- not to be confused with a font weigth (aka bold).-- here weight means the likelyhood of being "randomly" picked.local like_current_font = function ( window ) local font = window:effective_config().font.font -- not sure why font is a list local family = font[1].family adjust_font_randomness_weight( family, function ( weight ) local new_weight = weight + 1 -- TODO: remove notification once weight is displayed in status window:toast_notification( 'code_fonts', 'Font ' .. family .. '(' .. new_weight .. ') liked! ', nil, 500 ) return new_weight end )endlocal dislike_current_font = function ( window ) local font = window:effective_config().font.font -- not sure why font is a list local family = font[1].family adjust_font_randomness_weight( family, function ( weight ) local new_weight = weight - 1 window:toast_notification( 'code_fonts', 'Font ' .. family .. '(' .. new_weight .. ') NOT liked! ', nil, 500 ) return new_weight end )endlocal ban_current_font = function ( window ) local font = window:effective_config().font.font -- not sure why font is a list local family = font[1].family adjust_font_randomness_weight( family, function () window:toast_notification( 'code_fonts', 'Font ' .. family .. ' BANNED!', nil, 500 ) return 0 end )end-- register those events with wezterm, so that key binds can trigger themwez.on( 'like-current-font', like_current_font )wez.on( 'dislike-current-font', dislike_current_font )wez.on( 'ban-current-font', ban_current_font )local random = function () local selected = 'JetBrains Mono' -- safe default, because built in to wezterm local font_names = {} local weights = {} local total_weight = 1 -- to account for luas 1 based indexing local code_fonts = io.open( wez.config_dir .. '/bugabinga/code_fonts.csv', 'r' ) if code_fonts then for line in code_fonts:lines() do local weight, font_name = line:match( csv_line_pattern ) if not weight or not font_name then wez.log_error 'Could not parse code_fonts.csv. Borked?' break end weight = tonumber( weight ) table.insert( font_names, font_name ) table.insert( weights, weight ) total_weight = total_weight + weight end code_fonts:close() local random_weight = math.random( total_weight ) local cursor = 0 for idx, weight in ipairs( weights ) do cursor = cursor + weight if cursor >= random_weight then selected = font_names[idx] break end end end return wez.font( selected )endreturn { like_current_font = like_current_font, dislike_current_font = dislike_current_font, ban_current_font = ban_current_font, random = random,}deleted file mode 100644+0 / −7 text lines
deleted file mode 100644+0 / −124 text lines
local wez = require 'wezterm'local codefont = require 'bugabinga.code_font'wez.on( 'inc-font-size', function ( window ) local size = window:effective_config().font_size + 1 local overrides = window:get_config_overrides() or {} overrides.font_size = size window:set_config_overrides( overrides )end )wez.on( 'dec-font-size', function ( window ) local size = window:effective_config().font_size - 1 local overrides = window:get_config_overrides() or {} overrides.font_size = size window:set_config_overrides( overrides )end )wez.on( 'reset-font-size', function ( window ) local size = nil local overrides = window:get_config_overrides() or {} overrides.font_size = size window:set_config_overrides( overrides )end )wez.on( 'random-codefont', function ( window ) local random_font = codefont.random() local overrides = window:get_config_overrides() or {} overrides.font = random_font window:set_config_overrides( overrides )end )wez.on( 'change-font-size', function ( window, pane ) local font_sizes = {} for size = 8, 32 do table.insert( font_sizes, { id = tostring( size ), label = ' ' .. size, } ) end window:perform_action( wez.action.InputSelector { action = wez.action_callback( function ( win, _, id, label ) if not id and not label then window:toast_notification( 'font', 'Cancelled font size selection!', nil, 500 ) return end local overrides = win:get_config_overrides() or {} overrides.font_size = tonumber( id ) window:set_config_overrides( overrides ) window:toast_notification( 'font', 'Font set to size ' .. label, nil, 500 ) end ), title = 'Select font size', choices = font_sizes, alphabet = '1234567890', description = 'Pick the font size to apply to wezterm.', fuzzy = true, }, pane )end )return function ( cfg ) local harfbuzz_features = { 'calt', 'liga', 'dlig', 'ss01', 'ss02', 'ss03', 'ss04', 'ss05', 'ss06', 'ss07', 'ss08', } local font = wez.font { family = 'Monaspace Neon Var', weight = 'Medium', harfbuzz_features = harfbuzz_features, } local font_rules = { { -- Normal intensity = 'Normal', italic = false, font = wez.font { family = 'Monaspace Neon Var', weight = 'Medium', harfbuzz_features = harfbuzz_features, }, }, { -- Bold intensity = 'Bold', italic = false, font = wez.font { family = 'Monaspace Argon Var', weight = 'ExtraBold', harfbuzz_features = harfbuzz_features, }, }, { -- Normal italic intensity = 'Normal', italic = true, font = wez.font { family = 'Monaspace Radon Var', weight = 'Regular', style = 'Italic', harfbuzz_features = harfbuzz_features, }, }, { -- Bold italic intensity = 'Bold', italic = true, font = wez.font { family = 'Monaspace Krypton Var', weight = 'DemiBold', style = 'Italic', harfbuzz_features = harfbuzz_features, }, }, } cfg.font = font cfg.freetype_load_flags = 'NO_HINTING' cfg.font_shaper = 'Harfbuzz' cfg.font_size = 13.0 cfg.font_rules = font_rules cfg.underline_position = '142%' cfg.warn_about_missing_glyphs = falseend+0 / −1 text lines
+3 / −14 text lines
-- { key = '-', action = wez.action.DecreaseFontSize, }, -- { key = '=', action = wez.action.IncreaseFontSize, }, -- { key = '0', action = wez.action.ResetFontSize, }, { key = 'Enter', action = wez.action.EmitEvent 'change-font-size', }, { key = 'Space', action = wez.action.EmitEvent 'random-codefont', }, { key = 'UpArrow', action = wez.action.EmitEvent 'like-current-font', }, { key = 'DownArrow', action = wez.action.EmitEvent 'dislike-current-font', }, { key = 'Delete', action = wez.action.EmitEvent 'ban-current-font', },+0 / −14 text lines
local fonts = {} local config = window:effective_config() local font_size = config.font_size for _, font in pairs( config.font.font ) do table.insert( fonts, string.format( '%s:%s', font.family, font_size ) ) end local font = wez.format { { Text = ' Font ', }, { Attribute = { Intensity = 'Bold', }, }, { Text = table.concat( fonts, ', ' ), }, { Text = ' ', }, }+4 / −7 text lines
+0 / −1 text lines