repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

wezterm: refix font deletion, because aborting rebase yeeted my chages...

b58ace8250b9a1512d96a3009f0b76504fb1f7ff

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (9)

+9 / −281 text lines

Diff layout

.gitignore

Modified

+2 / −0 text lines

2727.*syncthing.*
2929tresor/*.key
31.trash/

wezterm/bugabinga/code_font.lua

Deleted
deleted file mode 100644

+0 / −113 text lines

1local wez = require 'wezterm'
2local csv_line_pattern = '^%s*(%d+)%s*,%s*(.-)%s*$'
3
4local adjust_font_randomness_weight = function ( font_family, adjust )
5 local code_fonts = io.open( wez.config_dir .. '/bugabinga/code_fonts.csv', 'r+' )
6 if code_fonts then
7 local new_lines = {}
8 for line in code_fonts:lines() do
9 local weight, font_name = line:match( csv_line_pattern )
10 if not weight or not font_name then
11 wez.log_error 'Could not parse code_fonts.csv. Borked?'
12 return
13 end
14 weight = tonumber( weight )
15 if font_name == font_family then
16 weight = math.max( 0, adjust( weight ) )
17 end
18 table.insert( new_lines, weight .. ',' .. font_name )
19 end
20 code_fonts:seek( 'set', 0 )
21 for _, new_line in ipairs( new_lines ) do
22 code_fonts:write( new_line, '\n' )
23 end
24 code_fonts:close()
25 else
26 wez.log_error 'Unable to read and write code_fonts.csv!'
27 end
28end
30-- like the current font.
31-- liked fonts have higher probablity of being picked on wezterm boot.
32-- increase the weight of the font in code_fonts.csv.
33-- not to be confused with a font weigth (aka bold).
34-- here weight means the likelyhood of being "randomly" picked.
35local like_current_font = function ( window )
36 local font = window:effective_config().font.font
37 -- not sure why font is a list
38 local family = font[1].family
39 adjust_font_randomness_weight( family, function ( weight )
40 local new_weight = weight + 1
41 -- TODO: remove notification once weight is displayed in status
42 window:toast_notification( 'code_fonts', 'Font ' .. family .. '(' .. new_weight .. ') liked! ', nil, 500 )
43 return new_weight
44 end )
45end
47local dislike_current_font = function ( window )
48 local font = window:effective_config().font.font
49 -- not sure why font is a list
50 local family = font[1].family
51 adjust_font_randomness_weight( family, function ( weight )
52 local new_weight = weight - 1
53 window:toast_notification( 'code_fonts', 'Font ' .. family .. '(' .. new_weight .. ') NOT liked! ', nil, 500 )
54 return new_weight
55 end )
56end
58local ban_current_font = function ( window )
59 local font = window:effective_config().font.font
60 -- not sure why font is a list
61 local family = font[1].family
62 adjust_font_randomness_weight( family, function ()
63 window:toast_notification( 'code_fonts', 'Font ' .. family .. ' BANNED!', nil, 500 )
64 return 0
65 end )
66end
68-- register those events with wezterm, so that key binds can trigger them
69wez.on( 'like-current-font', like_current_font )
70wez.on( 'dislike-current-font', dislike_current_font )
71wez.on( 'ban-current-font', ban_current_font )
73local random = function ()
74 local selected = 'JetBrains Mono' -- safe default, because built in to wezterm
75 local font_names = {}
76 local weights = {}
77 local total_weight = 1 -- to account for luas 1 based indexing
78 local code_fonts = io.open( wez.config_dir .. '/bugabinga/code_fonts.csv', 'r' )
80 if code_fonts then
81 for line in code_fonts:lines() do
82 local weight, font_name = line:match( csv_line_pattern )
83 if not weight or not font_name then
84 wez.log_error 'Could not parse code_fonts.csv. Borked?'
85 break
86 end
87 weight = tonumber( weight )
88 table.insert( font_names, font_name )
89 table.insert( weights, weight )
90 total_weight = total_weight + weight
91 end
92 code_fonts:close()
94 local random_weight = math.random( total_weight )
95 local cursor = 0
96 for idx, weight in ipairs( weights ) do
97 cursor = cursor + weight
98 if cursor >= random_weight then
99 selected = font_names[idx]
100 break
101 end
102 end
103 end
105 return wez.font( selected )
106end
108return {
109 like_current_font = like_current_font,
110 dislike_current_font = dislike_current_font,
111 ban_current_font = ban_current_font,
112 random = random,
113}

wezterm/bugabinga/code_fonts.csv

Deleted
deleted file mode 100644

+0 / −7 text lines

115,M+ 2m
250,IBM Plex Mono
321,Generic Mono II
430, Monaspace Neon Var
520,Hermit
633, Tsukurimashou Kaku
717,Oxygen Mono

wezterm/bugabinga/fonts.lua

Deleted
deleted file mode 100644

+0 / −124 text lines

1local wez = require 'wezterm'
2local codefont = require 'bugabinga.code_font'
3
4wez.on( 'inc-font-size', function ( window )
5 local size = window:effective_config().font_size + 1
6 local overrides = window:get_config_overrides() or {}
7 overrides.font_size = size
8 window:set_config_overrides( overrides )
9end )
11wez.on( 'dec-font-size', function ( window )
12 local size = window:effective_config().font_size - 1
13 local overrides = window:get_config_overrides() or {}
14 overrides.font_size = size
15 window:set_config_overrides( overrides )
16end )
18wez.on( 'reset-font-size', function ( window )
19 local size = nil
20 local overrides = window:get_config_overrides() or {}
21 overrides.font_size = size
22 window:set_config_overrides( overrides )
23end )
25wez.on( 'random-codefont', function ( window )
26 local random_font = codefont.random()
27 local overrides = window:get_config_overrides() or {}
28 overrides.font = random_font
29 window:set_config_overrides( overrides )
30end )
32wez.on( 'change-font-size', function ( window, pane )
33 local font_sizes = {}
34 for size = 8, 32 do
35 table.insert( font_sizes, { id = tostring( size ), label = ' ' .. size, } )
36 end
38 window:perform_action(
39 wez.action.InputSelector {
40 action = wez.action_callback( function ( win, _, id, label )
41 if not id and not label then
42 window:toast_notification( 'font', 'Cancelled font size selection!', nil, 500 )
43 return
44 end
45 local overrides = win:get_config_overrides() or {}
46 overrides.font_size = tonumber( id )
47 window:set_config_overrides( overrides )
48 window:toast_notification( 'font', 'Font set to size ' .. label, nil, 500 )
49 end ),
50 title = 'Select font size',
51 choices = font_sizes,
52 alphabet = '1234567890',
53 description = 'Pick the font size to apply to wezterm.',
54 fuzzy = true,
55 }, pane )
56end )
58return function ( cfg )
59 local harfbuzz_features = {
60 'calt',
61 'liga',
62 'dlig',
63 'ss01',
64 'ss02',
65 'ss03',
66 'ss04',
67 'ss05',
68 'ss06',
69 'ss07',
70 'ss08',
71 }
72 local font = wez.font {
73 family = 'Monaspace Neon Var',
74 weight = 'Medium',
75 harfbuzz_features = harfbuzz_features,
76 }
77 local font_rules = {
78 { -- Normal
79 intensity = 'Normal',
80 italic = false,
81 font = wez.font {
82 family = 'Monaspace Neon Var',
83 weight = 'Medium',
84 harfbuzz_features = harfbuzz_features,
85 },
86 },
87 { -- Bold
88 intensity = 'Bold',
89 italic = false,
90 font = wez.font {
91 family = 'Monaspace Argon Var',
92 weight = 'ExtraBold',
93 harfbuzz_features = harfbuzz_features,
94 },
95 },
96 { -- Normal italic
97 intensity = 'Normal',
98 italic = true,
99 font = wez.font {
100 family = 'Monaspace Radon Var',
101 weight = 'Regular',
102 style = 'Italic',
103 harfbuzz_features = harfbuzz_features,
104 },
105 },
106 { -- Bold italic
107 intensity = 'Bold',
108 italic = true,
109 font = wez.font {
110 family = 'Monaspace Krypton Var',
111 weight = 'DemiBold',
112 style = 'Italic',
113 harfbuzz_features = harfbuzz_features,
114 },
115 },
116 }
117 cfg.font = font
118 cfg.freetype_load_flags = 'NO_HINTING'
119 cfg.font_shaper = 'Harfbuzz'
120 cfg.font_size = 13.0
121 cfg.font_rules = font_rules
122 cfg.underline_position = '142%'
123 cfg.warn_about_missing_glyphs = false
124end

wezterm/bugabinga/hosts/fedora.lua

Modified

+0 / −1 text lines

22 cfg.enable_wayland = true
33 cfg.max_fps = 144
44 cfg.font_size = 16
5 cfg.term = 'wezterm'
65end

wezterm/bugabinga/key_binds.lua

Modified

+3 / −14 text lines

2626 { key = 'Escape', action = 'PopKeyTable', },
2727 },
2828 [font_mode] = {
29 { key = '-', action = wez.action.EmitEvent 'dec-font-size', },
30 { key = '=', action = wez.action.EmitEvent 'inc-font-size', },
31 { key = '0', action = wez.action.EmitEvent 'reset-font-size', },
3329 -- these actually SCALE the font, not actually change the size...
34 -- { key = '-', action = wez.action.DecreaseFontSize, },
35 -- { key = '=', action = wez.action.IncreaseFontSize, },
36 -- { key = '0', action = wez.action.ResetFontSize, },
38 { key = 'Enter', action = wez.action.EmitEvent 'change-font-size', },
39 { key = 'Space', action = wez.action.EmitEvent 'random-codefont', },
41 { key = 'UpArrow', action = wez.action.EmitEvent 'like-current-font', },
42 { key = 'DownArrow', action = wez.action.EmitEvent 'dislike-current-font', },
43 { key = 'Delete', action = wez.action.EmitEvent 'ban-current-font', },
30 { key = '-', action = wez.action.DecreaseFontSize, },
31 { key = '=', action = wez.action.IncreaseFontSize, },
32 { key = '0', action = wez.action.ResetFontSize, },
4534 { key = 'Escape', action = 'PopKeyTable', },
4635 },

wezterm/bugabinga/status.lua

Modified

+0 / −14 text lines

2525 if window:leader_is_active() then
2626 leader = '󱁐 '
2727 end
28 local fonts = {}
29 local config = window:effective_config()
30 local font_size = config.font_size
31 for _, font in pairs( config.font.font ) do
32 table.insert( fonts, string.format( '%s:%s', font.family, font_size ) )
33 end
34 local font = wez.format {
35 { Text = ' Font ', },
36 { Attribute = { Intensity = 'Bold', }, },
37 { Text = table.concat( fonts, ', ' ), },
38 { Text = ' ', },
39 }
4028 local pane_domain = pane:get_domain_name()
4230 local os_icon = wez.target_triple:find 'windows' and ' ' or ' '
6048 }
6149 table.insert( status, context )
63 table.insert( status, font )
6551 window:set_right_status(
6652 wez.format {
6753 { Text = table.concat( status, DELIMITER ), },

wezterm/bugabinga/window.lua

Modified

+4 / −7 text lines

1010 cfg.use_resize_increments = true
1111 cfg.adjust_window_size_when_changing_font_size = false
14 if wez.version > '2025' then
15 cfg.window_content_alignment = {
16 horizontal = 'Center',
17 vertical = 'Center',
18 }
19 end
13 cfg.window_content_alignment = {
14 horizontal = 'Center',
15 vertical = 'Center',
16 }
2118 cfg.window_padding = {
2219 left = 0,

wezterm/wezterm.lua

Modified

+0 / −1 text lines

66require 'bugabinga.options' ( cfg )
77require 'bugabinga.key_binds' ( cfg )
88require 'bugabinga.mouse_binds' ( cfg )
9require 'bugabinga.fonts' ( cfg )
109require 'bugabinga.window' ( cfg )
1110require 'bugabinga.status' ( cfg )
1211require 'bugabinga.titles' ( cfg )