-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
executable file
·843 lines (752 loc) · 26.9 KB
/
Copy pathmain.lua
File metadata and controls
executable file
·843 lines (752 loc) · 26.9 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
-- SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
-- Copyright (c) 2022-2026 Thomas Floeren
local MYNAME, A = ...
local user_is_author = false
local WTC = WrapTextInColorCode
local tonumber = tonumber
local type = type
local format = format
local FLAGS = '' -- For our purpose, we do not want any outlining.
local colors = {
EFI = '1E90FF', -- dodgerblue
-- HEAD = 'FFEFD5', -- papayawhip
HEAD = 'FFE4B5', -- moccasin
WARN = 'FF4500', -- orangered
BAD = 'DC143C', -- crimson
ON = '32CD32', -- limegreen
OFF = 'C0C0C0', -- silver
-- CMD = '6495ED', -- cornflowerblue
CMD = 'FFA500', -- orange
KEY = 'FFD700', -- gold
FONT = '00FA9A', -- mediumspringgreen
PATH = '90EE90', -- lightgreen
-- DEBUG = 'EE82EE', -- violet
DEBUG = 'FF00FF', -- magenta
}
local CLR = setmetatable({}, {
__index = function(_, k)
local color = colors[k]
assert(color, format('Color %q not defined.', k))
color = 'FF' .. color
return function(text) return text and WTC(text, color) or '\124c' .. color end
end,
})
local MSG_PREFIX = CLR.EFI('EditBox Font Improver:')
local FONTPATH_WARNING = CLR.WARN('Font path is not valid!')
.. ' Make sure that a font file exists at this location, or change the path: \n%s'
local RESET_WARNING = format(
'Due to an update to the database structure, %s. If you were using EFI version 2 or older, please %s, as there are numerous changes in settings and usage.',
CLR.WARN("EFI's database has been reset to its default values"),
CLR.KEY('refer to the ReadMe or the description on CurseForge')
)
local NOTHING_FOUND = CLR.BAD('<NOTHING FOUND>')
local BLOCKSEP = CLR.EFI(strrep('+', 42))
-- We opt to not raise an error if a font cannot be set, and just print a one-time warning.
-- The user will notice that the font is not set when they open the relevant addon.
local function warnprint(msg)
print(format('%s %s %s', MSG_PREFIX, CLR.WARN('WARNING:'), msg))
end
local function efiprint(msg) print(format('%s %s', MSG_PREFIX, msg)) end
local ITERATORS = {
['-'] = -1, ['+'] = 1, ['='] = 1, [','] = -1, ['.'] = 1,
}
--[[===========================================================================
Defaults
===========================================================================]]--
local function merge_defaults(src, dst)
for k, v in pairs(src) do
local src_type = type(v)
if src_type == 'table' then
if type(dst[k]) ~= 'table' then dst[k] = {} end
merge_defaults(v, dst[k])
elseif type(dst[k]) ~= src_type then
dst[k] = v
end
end
end
local db_emptied = nil
local function empty_db()
if type(_G.EBFI_DB) == 'table' then
wipe(_G.EBFI_DB)
db_emptied = true
else
-- Should never happen.
warnprint "Unexpected: Failed to empty EBFI_DB, as it is not a table."
_G.EBFI_DB = {}
end
end
-- 1: v3.0.0, Oct 24, 2025: significant; removed/added/renamed keys --> reset all
local DB_VERSION_CURRENT = 1
local defaults = {
fontfile = 'Interface/AddOns/EditBox-Font-Improver/fonts/pt-mono_regular.ttf',
fontsize = 13,
userfonts = nil, -- TODO: user fonts
misceditors = {
enable = true,
ownsize = nil, -- Always EFI size, since these addons have no own size setting
},
wowlua = {
enable = true,
ownsize = true,
},
scriptlibrary = {
enable = true,
ownsize = true,
},
bugsack = {
enable = true,
ownsize = true,
},
weakauras = {
enable = false,
ownsize = true,
},
debugmode = false,
db_version = DB_VERSION_CURRENT,
db_touched = nil,
}
if type(_G.EBFI_DB) ~= 'table' then
_G.EBFI_DB = {}
-- empty_db() triggers a warn print that we don’t want to see during a first installation.
elseif not _G.EBFI_DB.db_version or _G.EBFI_DB.db_version ~= DB_VERSION_CURRENT then
empty_db()
_G.EBFI_DB.db_version = DB_VERSION_CURRENT
end
merge_defaults(defaults, _G.EBFI_DB)
local db = _G.EBFI_DB
--[[===========================================================================
Setup
===========================================================================]]--
local dfonts = A.defaultfonts
local base_path, extension = 'Interface/AddOns/EditBox-Font-Improver/fonts/', '.ttf'
for i, v in ipairs(dfonts) do
local name = v
local ext = name:sub(-4) -- with the dot
dfonts[i] = base_path .. name .. ((ext == '.otf' or ext == '.ttf') and '' or extension)
end
-- not yet implemented, TODO
local ufonts = db.userfonts
-- TODO: for the user font implementation: we should simply prepend the user table to our dfonts
-- This will greatly simplify array handling e.g in our fontlisting etc. functions
local efi_font = db.fontfile
local function debugprint(...)
if db.debugmode then
local a, b = strsplit('.', GetTimePreciseSec())
print(format('[%s.%s] %s', a:sub(-3), b:sub(1, 3), CLR.DEBUG('EFI Debug >')), ...)
end
end
local function create_fontobj()
local efi_fobj = EFI_Fobj or CreateFont 'EFI_Fobj'
efi_fobj:SetFont(efi_font, db.fontsize, FLAGS)
if efi_fobj:GetFont() == efi_font then return true end
warnprint(FONTPATH_WARNING:format(efi_font))
end
-- Potential candidates to add:
-- PasteNG
-- Chattynator chat EditBox
-- Blizz chat editbox
-- WeakAuras code editbox
-- LiteMount unavailable/combat macros: `Macro.EditBox`; `Macro` table is created on demand
local initial_setup_stopped
local addons = {
misceditors = {
PUBLIC = true,
DISPLAYNAME = 'misc editors',
ABBREV = 'me',
HAS_SIZECFG = false,
DOES_INHERIT = true,
loaded = true,
setup_done = false,
},
wowlua = {
PUBLIC = true,
DISPLAYNAME = 'WowLua',
ABBREV = 'wl',
HAS_SIZECFG = true,
DOES_INHERIT = false,
loaded = false,
setup_done = false,
},
scriptlibrary = {
PUBLIC = true,
DISPLAYNAME = 'ScriptLibrary',
ABBREV = 'sl',
HAS_SIZECFG = true,
DOES_INHERIT = false,
loaded = false,
hook_done = false,
setup_done = false,
},
bugsack = {
PUBLIC = true,
DISPLAYNAME = 'BugSack',
ABBREV = 'bs',
HAS_SIZECFG = true,
DOES_INHERIT = false,
loaded = false,
hook_done = false,
hook2_done = false,
setup_done = false,
},
weakauras = {
PUBLIC = false,
DISPLAYNAME = 'WeakAuras',
ABBREV = 'wa',
HAS_SIZECFG = true,
DOES_INHERIT = false,
loaded = false,
hook_done = false,
setup_done = false,
},
}
-- The Size Situation:
-- Blizz Macro: fix 10
-- M6 and OPie: fix 12
-- WoWLua: configurable 5 to 24
-- ScriptLibrary: configurable 8 to 16
-- BugSack: configurable 10 to 16
-- BugSack's built-in sizes:
-- Small = GameFontHighlightSmall: 10
-- Medium = GameFontHighlight: 12
-- Large = GameFontHighlightMedium: 14
-- X-Large = GameFontHighlightLarge: 16
--[[===========================================================================
Straightforward Frames (misc editors)
===========================================================================]]--
-- https://www.townlong-yak.com/addons/m6
-- https://www.townlong-yak.com/addons/opie
-- Easy stuff, where we can simply apply our font object.
-- The frames are created at load time, so no need to hook (Blizzard_MacroUI needs
-- OptionalDeps!). A missing addon doesn't pose a problem, as it just creates a
-- nil value in the array.
local function try_misc_ace_boxes()
if not user_is_author then return end
local t = {}
for i = 1, 10 do
tinsert(t, _G['MultiLineEditBox' .. i .. 'Edit'])
end
return unpack(t, 1, 10)
end
function addons.misceditors.setup()
local editboxes = {
MacroFrameText, -- Blizzard_MacroUI; also affects ImprovedMacroFrame.
ABE_MacroInputEB, -- M6 and OPie macro edit box.
try_misc_ace_boxes(),
-- ChatFrame1EditBox, -- Trying to hit the chatframe editbox
}
-- Don't use `ipairs' because the entries can be nil.
local count = 0
for _, box in pairs(editboxes) do
box:SetFontObject(EFI_Fobj)
debugprint('Set up ' .. box:GetName())
count = count + 1
end
addons.misceditors.setup_done = true
debugprint('Setup for misc editors finished (' .. count .. ' of ' .. #editboxes .. ').')
end
--[[===========================================================================
WoWLua
===========================================================================]]--
-- https://www.curseforge.com/wow/addons/wowlua
-- We directly manipulate WoWLua's font object, otherwise we get reset when the
-- user changes font size in WoWLua.
-- We use the font size as actually set in the WowLua GUI.
function addons.wowlua.setup()
if WowLuaMonoFontSpaced then
local size = db.wowlua.ownsize and WowLua_DB.fontSize or db.fontsize
WowLuaMonoFont:SetFont(efi_font, size, FLAGS)
WowLuaMonoFontSpaced:SetFont(efi_font, size, FLAGS)
-- Needed to apply the font (not only the size)
WowLua:UpdateFontSize(size)
addons.wowlua.setup_done = true
else
warnprint "WowLua's `WowLuaMonoFontSpaced` not found. Could not set font."
end
debugprint 'WowLua setup finished.'
end
--[[===========================================================================
BugSack
===========================================================================]]--
-- https://www.curseforge.com/wow/addons/bugsack
function addons.bugsack.setup()
if BugSackScrollText then
if not EFI_BugSackFobj then CreateFont 'EFI_BugSackFobj' end
if db.bugsack.ownsize then
local currentsize = BugSackScrollText:GetFontObject():GetFontHeight()
EFI_BugSackFobj:CopyFontObject(EFI_Fobj)
EFI_BugSackFobj:SetFontHeight(currentsize)
BugSackScrollText:SetFontObject(EFI_BugSackFobj)
else
BugSackScrollText:SetFontObject(EFI_Fobj)
end
if not addons.bugsack.hook2_done then
hooksecurefunc(BugSackScrollText, 'SetFontObject', function(self, fobj)
local path = fobj:GetFont()
if path and path:find('FRIZQT__') then
local new_size = fobj:GetFontHeight()
EFI_BugSackFobj:SetFontObject(EFI_Fobj)
EFI_BugSackFobj:SetFontHeight(new_size)
self:SetFontObject(EFI_BugSackFobj)
debugprint('BugSack size changed, reapplied EFI font at size ' .. new_size)
end
end)
addons.bugsack.hook2_done = true
debugprint 'BugSack SetFontObject hook installed.'
end
addons.bugsack.setup_done = true
debugprint 'BugSack setup finished.'
elseif not addons.bugsack.hook_done then
addons.bugsack.hook()
else
warnprint 'BugSack target frame not found. Could not set font.'
end
end
-- The main frame is not created before first open, so we have to hook.
function addons.bugsack.hook()
if not BugSack.OpenSack then
warnprint '`BugSack.OpenSack` not found. Could not hook.'
else
hooksecurefunc(BugSack, 'OpenSack', function()
if not addons.bugsack.setup_done then addons.bugsack.setup() end
end)
debugprint 'BugSack hooked.'
end
addons.bugsack.hook_done = true
end
--[[===========================================================================
ScriptLibrary
===========================================================================]]--
-- https://www.curseforge.com/wow/addons/script-library
function addons.scriptlibrary.setup()
if RuntimeEditorMainWindowCodeEditorCodeEditorEditBox then
local size = db.scriptlibrary.ownsize
and tonumber(
(select(2, RuntimeEditorMainWindowCodeEditorCodeEditorEditBox:GetFont()))
)
or db.fontsize
RuntimeEditorMainWindowCodeEditorCodeEditorEditBox:SetFont(efi_font, size, FLAGS)
-- RuntimeEditorMainWindowCodeEditorCodeEditorEditBox:SetFontObject(EFI_Fobj)
addons.scriptlibrary.setup_done = true
debugprint 'ScriptLibrary setup finished.'
elseif not addons.scriptlibrary.hook_done then
addons.scriptlibrary.hook()
else
warnprint 'ScriptLibrary target frame not found. Could not set font.'
end
end
-- The main frame is not created before first open, so we have to hook.
-- Couldn't find any accessible 'open' function, so we use the slash command.
function addons.scriptlibrary.hook()
if not SlashCmdList.SCRIPTLIBRARY then
warnprint '`SlashCmdList.SCRIPTLIBRARY` not found. Could not hook.'
return
end
hooksecurefunc(SlashCmdList, 'SCRIPTLIBRARY', function()
if not addons.scriptlibrary.setup_done then
addons.scriptlibrary.setup()
end
end)
addons.scriptlibrary.hook_done = true
debugprint 'ScriptLibrary hooked.'
end
-- I haven't found a way to grab the font size that is set in ScriptLibrary.
-- ScriptLibrary wipes its global DB after load, and practically all functions and variables are private.
--[[===========================================================================
WeakAuras --- WiP! -- not exposed
===========================================================================]]--
-- https://www.curseforge.com/wow/addons/weakauras-2
-- WA sets the font bruteforce with `MultiLineEditBox3Edit:SetFont`, no fontobject
-- We loose the font when the size is changed in WA.
-- The Ace box (e.g. MultiLineEditBox3Edit) is created only when the Expand button is first clicked.
function addons.weakauras.setup()
if MultiLineEditBox3Edit then -- We need a specific frame name
local size = db.fontsize
if db.weakauras.ownsize then
if WeakAurasSaved and WeakAurasSaved.editor_font_size then
size = WeakAurasSaved.editor_font_size
debugprint "WeakAuras' own font size aquired."
else
warnprint "Unable to read WeakAuras' own font size. Using EFI's size."
end
end
MultiLineEditBox3Edit:SetFont(efi_font, size, FLAGS)
addons.weakauras.setup_done = true
debugprint 'WeakAuras setup finished.'
elseif not addons.weakauras.hook_done then
addons.weakauras.hook()
else
warnprint 'WeakAuras target frame not found. Could not set font.'
end
end
function addons.weakauras.hook()
if not IndentationLib then
warnprint '`IndentationLib` not found. Could not hook WeakAuras.'
else
hooksecurefunc(IndentationLib, 'stripWowColorsWithPos', function()
if not addons.weakauras.setup_done then addons.weakauras.setup() end
end)
debugprint 'WeakAuras hooked.'
end
addons.weakauras.hook_done = true
end
--[[===========================================================================
Run the Stuff
===========================================================================]]--
local ef = CreateFrame('Frame', MYNAME .. '_eventframe')
-- TODO: merge this func with the update_setup func
local function initial_setup()
for k, v in pairs(addons) do
if db[k].enable and (v.PUBLIC or user_is_author) and v.loaded then v.setup() end
end
end
local function PLAYER_LOGIN()
-- Debug
user_is_author = tf6 and tf6.user_is_tflo
if user_is_author then db.db_touched = true end
if db_emptied then C_Timer.After(20, function() warnprint(RESET_WARNING) end) end
addons.wowlua.loaded = C_AddOns.IsAddOnLoaded 'WowLua'
addons.weakauras.loaded = user_is_author and C_AddOns.IsAddOnLoaded 'WeakAuras'
addons.scriptlibrary.loaded = C_AddOns.IsAddOnLoaded 'ScriptLibrary'
addons.bugsack.loaded = C_AddOns.IsAddOnLoaded 'BugSack'
if not create_fontobj() then
-- Print the msg once more when login chat spam is over.
C_Timer.After(25, function() warnprint(FONTPATH_WARNING:format(efi_font)) end)
-- NOTE XXX: WoW seems to cache the font file *and also the path* until game
-- exit; so this test may pass at login even with the file removed, and the
-- ghost font is also still rendered in-game!
initial_setup_stopped = true
debugprint 'Initial setup stopped!'
return
end
initial_setup()
end
local event_handlers = {
['PLAYER_LOGIN'] = PLAYER_LOGIN,
}
for event in pairs(event_handlers) do
ef:RegisterEvent(event)
end
ef:SetScript('OnEvent', function(_, event, ...)
event_handlers[event](...) ---@diagnostic disable-line: redundant-parameter
end)
--[[===========================================================================
UI
===========================================================================]]--
-- Potential UI improvements, TODO:
-- ambitious: a little font preview frame, which enables the scroll wheel to
-- quickly scan through the installed fonts
local function update_setup(force)
if not create_fontobj() then return end
for k, v in pairs(addons) do
-- If setup is not yet done then a hook was installed but not yet triggered.
if db[k].enable and (v.PUBLIC or user_is_author) and (not v.DOES_INHERIT and v.setup_done or initial_setup_stopped or force) then v.setup() end
end
return true
end
local function toggle_target(trg)
local enable = not db[trg].enable
db[trg].enable = enable
efiprint(format('EFI is now %s for %s.%s', enable and CLR.ON('enabled') or CLR.OFF('disabled'), CLR.KEY(addons[trg].DISPLAYNAME), enable and '' or '\nA ' .. CLR.WARN('UI reload') .. ' is necessary to restore the original font.'))
if enable and not addons[trg].setup_done then addons[trg].setup() end
end
-- Lookup for the target toggle command
local targetnames = setmetatable({}, {
__index = function(_, key)
if addons[key] then return key end
for k, v in pairs(addons) do
if v.ABBREV == key then return k end
end
end,
})
--[[----------------------------------------------------------------------------
Formatters
----------------------------------------------------------------------------]]--
local function prettyfontname(name)
return name:gsub('[_-]+', ' '):gsub('%W%l', strupper):gsub('^pt ', 'PT ')
end
local function idx_from_path(path, array)
local arrays = array and { array } or type(ufonts) == 'table' and { dfonts, ufonts } or { dfonts }
if not arrays or type(arrays[1]) ~= 'table' then return CLR.BAD('<invalid array>') end
for _, array in ipairs(arrays) do
for i, v in ipairs(array) do
if v == path then return array == ufonts and 'u' .. i or i end
end
end
return CLR.BAD('<INVALID INDEX>')
end
local function fontname(path, withidx, array)
withidx = withidx == nil and true or withidx
local idx = withidx and idx_from_path(path, array)
local pattern = db.debugmode and '[^/\\]+$' or '([^/\\]+)%.[tof]+'
local name = tostring(path):match(pattern)
if not name then return NOTHING_FOUND end
name = db.debugmode and name or prettyfontname(name)
return CLR.FONT(idx and '[' .. idx .. ']\194\160' .. name or name)
end
local function fontpath(path)
local pattern = '.+[/\\]'
return CLR.PATH(tostring(path):match(pattern)) or NOTHING_FOUND
end
local function listfonts(array, compact)
if type(array) ~= 'table' or #array == 0 then return NOTHING_FOUND end
local fonts = {}
for i, v in ipairs(array) do
tinsert(fonts, fontname(v)) -- , true, array
if compact and i == A.NUM_FONTS_COMPACTLIST then break end
end
-- We cannot print 30 lines as one string due to Blizz's broken chat scrolling
return compact and table.concat(fonts, ', ') or fonts
end
local function listfontpaths(array, sep)
if type(array) ~= 'table' or #array == 0 then return NOTHING_FOUND end
sep = sep or ', '
local seen, result = {}, {}
for _, v in ipairs(array) do
local path = fontpath(v)
if not seen[path] then
seen[path] = true
tinsert(result, path)
end
end
table.sort(result)
return table.concat(result, sep)
end
--[[----------------------------------------------------------------------------
Large texts
----------------------------------------------------------------------------]]--
local function print_multi(lines)
for _, v in ipairs(lines) do
print(v)
end
end
local function statusbody()
-- addon efi-enabled / loaded
local states = {}
for k, v in pairs(addons) do
if v.PUBLIC or user_is_author then
local str = format(
'%s: %s/%s',
v.DISPLAYNAME,
db[k].enable and CLR.ON('Yes') or CLR.OFF('No'),
v.loaded and CLR.ON('Yes') or CLR.OFF('No')
)
tinsert(states, str)
end
end
table.sort(states)
states = table.concat(states, '; ')
-- size policies TODO
local sizepols = {}
for k, v in pairs(addons) do
if v.PUBLIC or user_is_author then
local str = format(
'%s: %s',
v.DISPLAYNAME,
db[k].ownsize and CLR.KEY('Own') or CLR.KEY('Uni')
)
tinsert(sizepols, str)
end
end
table.sort(sizepols)
sizepols = table.concat(sizepols, '; ')
return db.debugmode
and {
format('%s %s', CLR.HEAD('Current font:'), fontname(db.fontfile)),
format('%s %s', CLR.HEAD('Current font size:'), CLR.KEY(db.fontsize)),
format('%s %s', CLR.HEAD('Current font path:'), fontpath(db.fontfile)), -- TODO: user fonts
format(
'%s %s; %s %s',
CLR.HEAD('Num fonts: default:'),
CLR.KEY(#dfonts),
CLR.HEAD('user [NYI!]:'),
CLR.KEY(type(ufonts) == 'table' and #ufonts or 'nil')
), -- TODO: user fonts
format('%s %s', CLR.HEAD('Default fonts:'), listfonts(dfonts, true)),
format('%s %s', CLR.HEAD('User fonts [NYI!]:'), listfonts(ufonts, true)), -- TODO: user fonts
format('%s \n %s', CLR.HEAD('User font paths [NYI!]:'), listfontpaths(ufonts, '\n ')), -- TODO: user fonts
format('%s %s', CLR.HEAD('Enabled for addon/loaded:'), states),
format('%s %s', CLR.HEAD('Ownsize/Unisize:'), sizepols),
format('%s %s', CLR.HEAD('Debug mode:'), db.debugmode and 'On' or 'Off'),
format('%s %s', CLR.HEAD('User is author:'), user_is_author and 'Yes' or 'No'),
}
or {
format('%s %s', CLR.HEAD('Current font:'), fontname(db.fontfile)),
format('%s %s', CLR.HEAD('Current font size:'), CLR.KEY(db.fontsize)),
format('%s %s. Use %q to list all.', CLR.HEAD('Number of installed fonts:'), CLR.KEY(#dfonts), CLR.CMD('/efi\194\160f')),
format('%s %s', CLR.HEAD(('Installed fonts ' .. CLR.KEY('[1\226\128\147' .. A.NUM_FONTS_COMPACTLIST .. ']') .. ':')), listfonts(dfonts, true)),
format('%s %s', CLR.HEAD('Enabled for addon/loaded:'), states),
format('%s %s', CLR.HEAD('Ownsize/Unisize:'), sizepols),
}
end
local function shorthelpbody()
return format(
'%s %q to set the font size, %q to select a font by index, %q for the complete help with all commands explained.',
CLR.EFI('Usage examples:'),
CLR.CMD('/efi\194\160s\194\16014'),
CLR.CMD('/efi\194\1603'),
CLR.CMD('/efi\194\160h')
)
end
local function fullhelpbody()
return {
format('%s : Select font by index (%s to %s).', CLR.CMD('/efi <index>'), CLR.KEY('1'), CLR.KEY(#dfonts)),
format('%s : List all %s available fonts.', CLR.CMD('/efi f'), CLR.KEY(#dfonts)),
format('%s : Set fontsize (default: %s).', CLR.CMD('/efi s <number>'), CLR.KEY(defaults.fontsize)),
format('%s : Do not change the font size of addons that have their own size setting (default).', CLR.CMD('/efi ownsize')),
format('%s : Apply font size to all addons, regardless of their own settings.', CLR.CMD('/efi unisize')),
format('%s : Refresh setup for all enabled targets.', CLR.CMD('/efi r')),
format('%s or just %s : Display status and info (index of fonts, current font, settings).', CLR.CMD('/efi s'), CLR.CMD('/efi')),
format('%s : Display this help text.', CLR.CMD('/efi h')),
}
end
--[[----------------------------------------------------------------------------
Slash function
----------------------------------------------------------------------------]]--
SLASH_EditBoxFontImprover1 = '/efi'
SLASH_EditBoxFontImprover2 = '/ebfi'
SLASH_EditBoxFontImprover3 = '/editboxfontimprover'
SlashCmdList.EditBoxFontImprover = function(msg)
local args = {}
for arg in msg:gmatch('[^ ]+') do
tinsert(args, arg)
end
-- Multi args: font
-- Font selection
if tonumber(args[1]) or ITERATORS[args[1]] then
local selection = tonumber(args[1]) and floor(args[1]) or idx_from_path(db.fontfile) + ITERATORS[args[1]]
if db.fontfile == dfonts[selection] then
efiprint(
format(
'The font you have selected (%s) is already loaded.',
CLR.FONT(fontname(dfonts[selection]))
)
)
elseif not dfonts[selection] then
efiprint(
format(
'The font you have selected (%s) does not exist. The font list contains only %s fonts.',
CLR.FONT('[' .. selection .. ']'),
CLR.KEY(#dfonts)
)
)
else
efi_font = dfonts[selection]
if update_setup() then
db.fontfile = dfonts[selection]
efiprint(format('Your new font: %s', CLR.FONT(fontname(db.fontfile))))
else
efiprint(
format(
'The path of your selected font (%s) is not valid!. Your previous font will be used instead.',
CLR.FONT('[' .. selection .. ']')
)
)
end
end
elseif args[1] == 'f' and args[2] == 'inval' then -- Debug
db.fontfile = db.fontfile:gsub('AddOns', 'INVALIDATED_PATH')
efiprint(format('Font path invalidated to: %s', db.fontfile))
elseif args[1] == 'f' and args[2] == 'reval' then -- Debug
db.fontfile = db.fontfile:gsub('INVALIDATED_PATH', 'AddOns')
efiprint(format('Font path revalidated to: %s', db.fontfile))
-- Multi args: database (debug)
elseif args[1] == 'db' and args[2] == 'reset' then -- Debug
empty_db()
merge_defaults(defaults, _G.EBFI_DB)
db = _G.EBFI_DB
efiprint(
format(
'Database reset to defaults: %s',
db.db_touched and CLR.BAD('Failed to reset the DB!') or 'Yes.'
)
)
elseif args[1] == 'db' and (args[2] == 'empty' or args[2] == 'wipe') then -- Debug
empty_db()
efiprint(
format(
'Database emptied: %s',
next(db) == nil and 'Yes. Reload now.' or CLR.BAD('Failed to wipe the DB!')
)
)
elseif args[1] == 'db' and args[2] == 'delete' then -- Debug
_G.EBFI_DB, db = nil, nil
efiprint(
format(
'Database deleted: %s',
db == nil and 'Yes. Reload now.' or CLR.BAD('Failed to delete the DB!')
)
)
elseif args[1] == 'db' and (args[2] == 'show' or args[2] == 'dump') then -- Debug
DevTools_Dump(db)
-- Multi args: fontsize
elseif args[1] == 's' and tonumber(args[2]) or ITERATORS[args[2]] then
db.fontsize = max(min(tonumber(args[2] or db.fontsize + ITERATORS[args[2]]), 28), 6)
local t = {}
for k, v in pairs(addons) do
if defaults[k].ownsize and (v.PUBLIC or user_is_author) then table.insert(t, v.DISPLAYNAME) end
end
local ownsizers = table.concat(t, ', ')
efiprint(
format(
'Font size set to %s. This does not affect any addon that is set to use its own font size setting (by default %s).',
CLR.KEY(db.fontsize),
CLR.KEY(ownsizers)
)
)
update_setup()
-- Single arg
elseif args[1] == 'unisize' then
for k, v in pairs(addons) do
if v.HAS_SIZECFG then db[k].ownsize = false end
end
efiprint "All addons set to use EFI's default font size."
update_setup()
elseif args[1] == 'ownsize' then
for k, v in pairs(addons) do
if v.HAS_SIZECFG then db[k].ownsize = true end
end
efiprint 'All addons with a configurable font size will keep their own size setting.'
update_setup()
elseif args[1] == 'r' then
efiprint 'Setup refreshed.'
update_setup(true)
elseif args[1] == 'notme' or args[1] == 'itsme' then -- Debug
user_is_author = not user_is_author
efiprint(user_is_author and CLR.ON("It's me.") or CLR.OFF("It's not me!"))
elseif args[1] == 'f' or args[1] == 'fonts' then
print(BLOCKSEP)
efiprint(CLR.HEAD('All Installed Fonts:'))
local fonts = listfonts(dfonts, false)
for _, v in ipairs(fonts) do
print(v)
end
print(BLOCKSEP)
-- Addon toggles
elseif targetnames[args[1]] then
toggle_target(targetnames[args[1]])
-- Status and help
elseif args[1] == nil or args[1] == 's' or args[1] == 'status' or args[1] == 'info' then
print(BLOCKSEP)
efiprint(CLR.HEAD('Status & Info:'))
print_multi(statusbody())
print(shorthelpbody())
print(BLOCKSEP)
elseif args[1] == 'h' or args[1] == 'help' then
print(BLOCKSEP)
efiprint(CLR.HEAD('Command Help:'))
print_multi(fullhelpbody())
print(BLOCKSEP)
elseif args[1] == 'dm' or args[1] == 'debug' then
db.debugmode = not db.debugmode
efiprint(format('Debug mode: %s', db.debugmode and 'On' or 'Off'))
else
print(BLOCKSEP)
efiprint(
CLR.BAD(
format('Your input %q was not a valid input.', CLR.KEY(table.concat(args, '\32')))
)
)
print(shorthelpbody())
print(BLOCKSEP)
end
end