-
Notifications
You must be signed in to change notification settings - Fork 17
/
flexprompt_wizard.lua
1402 lines (1189 loc) · 42.5 KB
/
flexprompt_wizard.lua
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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- luacheck: no max line length
-- luacheck: globals console os.isfile NONL
-- luacheck: globals flexprompt
local normal = "\x1b[m"
local bold = "\x1b[1m"
local brightgreen = "\x1b[92m"
local brightyellow = "\x1b[93m"
local static_cursor = "\x1b[7m " .. normal
local _transient
local _striptime
local _timeformat
local clink_prompt_spacing = (settings.get("prompt.spacing") ~= nil)
local function spairs(t, order)
local keys = {}
local num = 0
for k in pairs(t) do
num = num + 1
keys[num] = k
end
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
local function readinput()
if console.readinput then
local key = console.readinput()
return key
else
clink.print("\x1b[s", NONL)
local line = io.read("*l")
clink.print("\x1b[u\x1b[J", NONL)
return line
end
end
local function readchoice(choices)
if not choices then error("missing choices") end
repeat
clink.print("Choice [" .. choices .. "]: ", NONL)
local s = readinput()
clink.print("\x1b[G\x1b[K", NONL)
if not s then -- Happens when resizing the terminal.
s = ""
end
if #s == 1 and string.find(choices, s) then
return s
end
until false
end
local function refresh_width(preview)
preview.width = console.getwidth() - 10 -- Align with "(1) <-Here".
end
local function clear_screen()
clink.print("\x1b[H\x1b[J", NONL)
end
local function get_settings_filename()
local script_name
local profile_name
local force_dir = flexprompt_autoconfig_dir -- luacheck: no global
if force_dir then
script_name = path.join(force_dir, "flexprompt_autoconfig.lua")
end
if not script_name then
local info = debug.getinfo(1, 'S')
if info.source and info.source:sub(1, 1) == "@" then
local dir = path.toparent(info.source:sub(2))
if os.isdir(dir) then
script_name = path.join(dir, "flexprompt_autoconfig.lua")
end
end
end
local dir = os.getenv("=clink.profile")
if dir then
profile_name = path.join(dir, "flexprompt_autoconfig.lua")
end
local name = script_name or profile_name
local delete_name = (script_name ~= profile_name) and profile_name
if not name then
error("Unable to write settings; file location unknown.")
end
return name, delete_name
end
local function inc_line(line)
line[1] = line[1] + 1
end
local function order_table(a, b)
local typea = type(a)
local typeb = type(b)
if typea == typeb then
return a < b
elseif typea == "number" then
return true
elseif typeb == "number" then
return false
else
return tostring(a) < tostring(b)
end
end
local function write_var(file, line, name, value, indent)
local t = type(value)
if not indent then indent = "" end
local comma = ((#indent > 0) and "," or "")
if t == "table" then
if type(name) == "string" then
file:write(indent .. name .. " =\n")
inc_line(line)
end
file:write(indent .. "{\n")
inc_line(line)
for n,v in ipairs(value) do
write_var(file, line, tonumber(n), v, indent .. " ")
end
for n,v in spairs(value, order_table) do
if type(n) == "string" then
write_var(file, line, n, v, indent .. " ")
end
end
file:write(indent .. "}" .. comma .. "\n")
inc_line(line)
return
end
if t == "string" then
value = string.format("%q", value)
elseif t == "boolean" then
value = value and "true" or "false"
elseif t == "number" then
value = tostring(value)
else
local msg
if type(name) == "string" then
msg = "flexprompt couldn't write '" .. name .. "' at line " .. line[1] .. "; unknown type '" .. t .. "'."
else
msg = "flexprompt couldn't write [" .. name .. "] at line " .. line[1] .. "; unknown type '" .. t .. "'."
end
log.info(msg)
return msg
end
if name and tonumber(name) then
name = ""
else
name = name .. " = "
end
file:write(indent .. name .. value .. comma .. "\n")
inc_line(line)
end
local function write_settings(settings)
local name, delete_name = get_settings_filename()
local file = io.open(name, "w")
if not file then
error("Unable to write settings; unable to write to '" .. name .. "'.")
end
file:write("-- WARNING: This file gets overwritten by the 'flexprompt configure' wizard!\n")
file:write("--\n")
file:write("-- If you want to make changes, consider copying the file to\n")
file:write("-- 'flexprompt_config.lua' and editing that file instead.\n\n")
-- Avoid errors if flexprompt isn't present or hasn't been initialized yet.
file:write("flexprompt = flexprompt or {}\n")
file:write("flexprompt.settings = flexprompt.settings or {}\n")
local line = { 8 }
local errors
for n,v in spairs(settings) do
if n ~= "wizard" and n ~= "width" then
local msg = write_var(file, line, "flexprompt.settings."..n, v)
if msg then
errors = errors or {}
table.insert(errors, msg)
end
end
end
file:close()
if delete_name then
os.remove(delete_name)
end
if _transient then
local command = string.format('2>nul >nul "%s" set prompt.transient %s', CLINK_EXE, _transient)
os.execute(command)
end
if clink_prompt_spacing then
local command = string.format('2>nul >nul "%s" set prompt.spacing %s', CLINK_EXE, settings.spacing)
os.execute(command)
end
return errors
end
local function copy_table(settings)
local copy = {}
for n,v in pairs(settings) do
if type(v) == "table" then
copy[n] = copy_table(v)
else
copy[n] = v
end
end
return copy
end
local function display_callout(row, col, text)
clink.print("\x1b[s\x1b[" .. row .. ";" .. col .. "H" .. text .. "\x1b[u", NONL)
end
local function display_centered(s)
local cells = console.cellcount(s)
local width = console.getwidth()
if width > 80 then width = 80 end
if cells < width then
clink.print(string.rep(" ", (width - cells) / 2), NONL)
end
clink.print(s)
end
local function display_title(s)
display_centered(bold .. s .. normal)
end
local function replace_arg(s, module, arg, value)
if s:find("{" .. module) then
local args = s:match("{" .. module .. "(:[^}]*)}")
value = value and (":" .. arg .. "=" .. value) or ""
if not args then
args = value
elseif args:find(":" .. arg) then
args = args:gsub(":" .. arg .. "=[^:]*", value)
else
args = args .. value
end
s = s:gsub("{" .. module .. "[^}]*}", "{" .. module .. args .. "}")
end
return s
end
local function apply_time_format(s)
if not s then return end
if _striptime then
s = s:gsub("{time[^}]*}", "")
s = replace_arg(s, "rbubble", "format", nil)
elseif _timeformat then
if _timeformat == "2" then
s = replace_arg(s, "time", "format", "%%H:%%M:%%S")
s = replace_arg(s, "rbubble", "format", "%%H:%%M:%%S")
elseif _timeformat == "3" then
s = replace_arg(s, "time", "format", "%%a %%H:%%M")
s = replace_arg(s, "rbubble", "format", "%%a %%H:%%M")
elseif _timeformat == "4" then
s = replace_arg(s, "time", "format", "%%I:%%M:%%S %%p")
s = replace_arg(s, "rbubble", "format", "%%I:%%M:%%S %%p")
elseif _timeformat == "5" then
s = replace_arg(s, "time", "format", "%%a %%I:%%M %%p")
s = replace_arg(s, "rbubble", "format", "%%a %%I:%%M %%p")
else
s = replace_arg(s, "time", "format", "")
s = replace_arg(s, "rbubble", "format", "")
end
end
return s
end
local function replace_modules(s)
if not s then return end
s = s:gsub("{histlabel[^}]*}", "")
s = apply_time_format(s)
return s
end
local function translate_bubbles(settings, final)
if settings.style == "bubbles" then
settings.style = "lean"
settings.top_prompt = "{tbubble}"
settings.left_prompt = "{lbubble}"
settings.right_prompt = "{rbubble}"
if final then
settings.right_prompt = apply_time_format(settings.right_prompt)
end
end
end
local function display_preview(settings, command, show_cursor, callout)
local preview = copy_table(settings)
translate_bubbles(preview)
if preview.left_prompt then
preview.left_prompt = replace_modules(preview.left_prompt)
end
if preview.right_prompt then
preview.right_prompt = replace_modules(preview.right_prompt)
end
local left, right, col, anchors = flexprompt.render_wizard(preview, callout and true or nil)
if callout and anchors then
local x
if type(callout[2]) == "table" then
x = anchors[callout[2][1]] + callout[2][2]
else
x = anchors[callout[2]]
end
display_callout(callout[1], x, callout[3])
end
clink.print(left .. normal .. (command or "") .. ((show_cursor ~= false) and static_cursor or ""), NONL)
if right then
clink.print("\x1b[" .. col .. "G" .. right .. normal)
else
clink.print()
end
end
local function display_yes(choices, extra)
clink.print("(y) Yes. " .. (extra or "") .. "\n")
return choices .. "y"
end
local function display_no(choices, extra)
clink.print("(n) No. " .. (extra or "") .. "\n")
return choices .. "n"
end
local function display_restart(choices)
clink.print("(r) Restart from the beginning.")
return choices .. "r"
end
local function display_quit(choices)
clink.print("(q) Quit and do nothing.\n")
return choices .. "q"
end
local function friendly_case(text)
if text == "ascii" then return "ASCII" end
return text:sub(1, 1):upper() .. text:sub(2)
end
local function choose_setting(settings, title, choices_name, setting_name, subset, callout) -- luacheck: no unused
local choices = ""
refresh_width(settings)
clear_screen()
display_title(title)
clink.print()
for index,name in ipairs(subset) do
if index > 5 then
break
end
choices = choices .. tostring(index)
clink.print("(" .. index .. ") " .. friendly_case(name) .. ".\n")
local preview = copy_table(settings)
preview[setting_name] = name
display_preview(preview, nil, nil, callout)
callout = nil
clink.print()
end
choices = display_restart(choices)
choices = display_quit(choices)
local s = readchoice(choices)
if not s then return end
if s == "r" then -- luacheck: ignore 542
elseif s == "q" then -- luacheck: ignore 542
else
settings[setting_name] = subset[tonumber(s)]
end
return s
end
local function choose_sides(settings, title)
local choices = "" -- luacheck: ignore 311
local prompts = flexprompt.choices.prompts[settings.style]
local withbreaks = flexprompt.choices.prompts["breaks"]
local preview
refresh_width(settings)
clear_screen()
display_title(title)
clink.print()
choices = (settings.style == "rainbow") and "1234" or "12"
clink.print("(1) Left.\n")
preview = copy_table(settings)
preview.left_prompt = prompts.left[1]
preview.right_prompt = prompts.left[2]
display_preview(preview)
clink.print()
clink.print("(2) Both.\n")
preview = copy_table(settings)
preview.left_prompt = prompts.both[1]
preview.right_prompt = prompts.both[2]
display_preview(preview)
clink.print()
if settings.style == "rainbow" then
clink.print("(3) Left with breaks between groups of related segments.\n")
preview = copy_table(settings)
preview.wizard.exit = 1
preview.wizard.git = { status={ staged={ modify=3 } } }
preview.left_prompt = withbreaks.left[1]
preview.right_prompt = withbreaks.left[2]
display_preview(preview)
clink.print()
clink.print("(4) Both with breaks between groups of related segments.\n")
preview = copy_table(settings)
preview.wizard.exit = 1
preview.wizard.git = { status={ staged={ modify=3 } } }
preview.left_prompt = withbreaks.both[1]
preview.right_prompt = withbreaks.both[2]
display_preview(preview)
clink.print()
end
choices = display_restart(choices)
choices = display_quit(choices)
local s = readchoice(choices)
if not s then return end
if s == "r" then -- luacheck: ignore 542
elseif s == "q" then -- luacheck: ignore 542
else
if s == "1" then
settings.left_prompt = apply_time_format(prompts.left[1])
settings.right_prompt = apply_time_format(prompts.left[2])
elseif s == "2" then
settings.left_prompt = apply_time_format(prompts.both[1])
settings.right_prompt = apply_time_format(prompts.both[2])
elseif s == "3" then
settings.left_prompt = apply_time_format(withbreaks.left[1])
settings.right_prompt = apply_time_format(withbreaks.left[2])
elseif s == "4" then
settings.left_prompt = apply_time_format(withbreaks.both[1])
settings.right_prompt = apply_time_format(withbreaks.both[2])
end
_timeformat = nil
end
return s
end
local function choose_time(settings, title)
local choices = "" -- luacheck: ignore 311
local preview
refresh_width(settings)
clear_screen()
display_title(title)
clink.print()
choices = "12345"
clink.print("(1) No.\n")
preview = copy_table(settings)
_timeformat = "1"
display_preview(preview)
clink.print()
clink.print("(2) 24-hour format.\n")
preview = copy_table(settings)
_timeformat = "2"
display_preview(preview)
clink.print()
clink.print("(3) 24-hour format with day.\n")
preview = copy_table(settings)
_timeformat = "3"
display_preview(preview)
clink.print()
clink.print("(4) 12-hour format.\n")
preview = copy_table(settings)
_timeformat = "4"
display_preview(preview)
clink.print()
clink.print("(5) 12-hour format with day.\n")
preview = copy_table(settings)
_timeformat = "5"
display_preview(preview)
clink.print()
choices = display_restart(choices)
choices = display_quit(choices)
local s = readchoice(choices)
if not s then return end
if s == "r" then -- luacheck: ignore 542
elseif s == "q" then -- luacheck: ignore 542
else
_timeformat = s
end
return s
end
local function choose_frames(settings, title)
local choices = "" -- luacheck: ignore 311
local preview
refresh_width(settings)
clear_screen()
display_title(title)
clink.print()
choices = "1234"
clink.print("(1) No frame.\n")
preview = copy_table(settings)
preview.left_frame = "none"
preview.right_frame = "none"
display_preview(preview)
clink.print()
clink.print("(2) Left.\n")
preview = copy_table(settings)
preview.left_frame = "round"
preview.right_frame = "none"
display_preview(preview)
clink.print()
clink.print("(3) Right.\n")
preview = copy_table(settings)
preview.left_frame = "none"
preview.right_frame = "round"
display_preview(preview)
clink.print()
clink.print("(4) Full.\n")
preview = copy_table(settings)
preview.left_frame = "round"
preview.right_frame = "round"
display_preview(preview)
clink.print()
choices = display_restart(choices)
choices = display_quit(choices)
local s = readchoice(choices)
if not s then return end
if s == "r" then -- luacheck: ignore 542
elseif s == "q" then -- luacheck: ignore 542
else
settings.left_frame = (s == "1" or s == "3") and "none" or "round"
settings.right_frame = (s == "1" or s == "2") and "none" or "round"
end
return s
end
local function choose_spacing(settings, title)
local choices = "" -- luacheck: ignore 311
refresh_width(settings)
clear_screen()
display_title(title)
clink.print()
choices = "123"
clink.print("(1) Normal.\n")
clink.print(" Normally the prompt doesn't remove or add blank lines.")
clink.print(" Whatever blank lines already exist are kept.\n")
clink.print("(2) Compact.\n")
clink.print(" Removes any blank lines from the end of the previous")
clink.print(" command's output.\n")
display_preview(settings, nil, false)
display_preview(settings)
clink.print()
clink.print("(3) Sparse.\n")
clink.print(" Removes any blank lines from the end of the previous")
clink.print(" command's output, and then inserts one blank line.\n")
display_preview(settings, nil, false)
clink.print()
display_preview(settings)
clink.print()
choices = display_restart(choices)
choices = display_quit(choices)
local s = readchoice(choices)
if not s then return end
if s == "r" then -- luacheck: ignore 542
elseif s == "q" then -- luacheck: ignore 542
else
if s == "2" then
settings.spacing = "compact"
elseif s == "3" then
settings.spacing = "sparse"
else
settings.spacing = "normal"
end
end
return s
end
local function choose_icons(settings, title)
local choices = "" -- luacheck: ignore 311
local preview
refresh_width(settings)
clear_screen()
display_title(title)
clink.print()
choices = "12"
local few_no = (settings.style == "lean") and "No" or "Few"
clink.print("(1) " .. few_no .. " icons.\n")
preview = copy_table(settings)
preview.use_icons = nil
display_preview(preview)
clink.print()
clink.print("(2) Many icons.\n")
preview = copy_table(settings)
preview.use_icons = true
display_preview(preview)
clink.print()
if clink.getansihost and clink.getansihost() == "winterminal" then
choices = choices .. "3"
clink.print("(3) Many icons, and use color emoji in Windows Terminal.\n")
preview = copy_table(settings)
preview.use_icons = true
preview.use_color_emoji = true
display_preview(preview)
clink.print()
end
choices = display_restart(choices)
choices = display_quit(choices)
local s = readchoice(choices)
if not s then return end
if s == "r" then -- luacheck: ignore 542
elseif s == "q" then -- luacheck: ignore 542
else
settings.use_icons = nil
if s == "2" then
settings.use_icons = true
elseif s == "3" then
settings.use_icons = true
settings.use_color_emoji = true
end
end
return s
end
local function choose_transient(settings, title)
local choices = "" -- luacheck: ignore 311
refresh_width(settings)
clear_screen()
display_title(title)
clink.print()
choices = "yn"
clink.print("(y) Yes.\n")
clink.print(" Past prompts are compacted, if the current directory")
clink.print(" hasn't changed.\n")
-- This initializes the settings.wizard.prefix needed below.
flexprompt.render_wizard(settings)
clink.print(settings.wizard.prefix .. flexprompt.render_transient_wizard(settings.wizard) .. "git pull")
clink.print(settings.wizard.prefix .. flexprompt.render_transient_wizard(settings.wizard) .. "git branch x")
if settings.spacing == "sparse" then clink.print() end
display_preview(settings, "git checkout x")
clink.print()
clink.print("(n) No.\n")
display_preview(settings, "git pull", false)
if settings.spacing == "sparse" then clink.print() end
display_preview(settings, "git branch x", false)
if settings.spacing == "sparse" then clink.print() end
display_preview(settings, "git checkout x")
clink.print()
choices = display_restart(choices)
choices = display_quit(choices)
local s = readchoice(choices)
if not s then return end
if s == "r" then -- luacheck: ignore 542
elseif s == "q" then -- luacheck: ignore 542
else
if s == "y" then
_transient = "same_dir"
else
_transient = "off"
end
end
return s
end
local function make_8bit_color_test()
local s = ""
for index = 0, 11, 1 do
local color = 234 + index
s = s .. "\x1b[48;5;"..color..";38;5;"..(color + 4 + math.floor(index*2/3)).."m" .. string.char(65 + index)
end
return s .. "\x1b[m"
end
local function wizard_can_use_extended_colors(settings)
local can
local old_settings = flexprompt.settings
flexprompt.settings = settings
can = flexprompt.can_use_extended_colors(true)
flexprompt.settings = old_settings
return can
end
local function make_icon_list(icons)
local out = "X"
local colors = { --[["\x1b[31m", "\x1b[33m",]] "\x1b[32m", --[["\x1b[34m", "\x1b[35m", "\x1b[36m"]] }
for i = 1, #icons, 1 do
out = out .. colors[((i - 1) % #colors) + 1] .. icons[i] .. normal .. "X"
end
return out
end
local function config_wizard()
local s
local settings_filename, delete_filename = get_settings_filename()
local errors
local hasicons
local eight_bit_color_test = make_8bit_color_test()
local four_bit_color
local style_choices
local callout
local choices
local wrote
local nerdfonts_version
local nerdfonts_width
print(string.rep("\n", console.getheight()))
clear_screen()
repeat
local preview =
{
wizard =
{
cwd = "c:\\directory",
type = "git",
branch = "main",
duration = 5,
exit = 0,
battery = {},
},
lines = "two",
left_prompt = "{cwd}{git}",
right_prompt = "{duration}{time}",
}
_transient = nil
_striptime = true
_timeformat = nil
hasicons = nil
nerdfonts_version = nil
nerdfonts_width = nil
four_bit_color = false
-- Find out about the font being used.
refresh_width(preview)
clear_screen()
display_title("Welcome to the configuration wizard for flexprompt.")
display_centered("This will ask a few questions and configure your prompt.")
clink.print()
display_centered("Does this look like a "..brightgreen.."diamond"..normal.." (rotated square)?")
clink.print("\n")
display_centered("--> "..brightgreen..""..normal.." <--")
clink.print("\n")
choices = ""
choices = display_yes(choices)
choices = display_no(choices)
clink.print(" Visit "..brightgreen.."https://nerdfonts.com"..normal.." to find fonts that support the")
clink.print(" powerline symbols flexprompt uses for its fancy text-mode graphics.")
clink.print("\n Some excellent fonts to consider are Meslo NF, Fira Code NF,")
clink.print(" or Cascadia Code PL (and many other suitable fonts exist).\n\n")
choices = display_quit(choices)
s = readchoice(choices)
if not s or s == "q" then break end
if s == "y" then
preview.charset = "unicode"
preview.powerline_font = true
end
if not preview.charset then
refresh_width(preview)
clink.print("\x1b[4H\x1b[J", NONL)
display_centered("Does this look like a "..brightgreen.."rectangle"..normal.."?")
clink.print()
display_centered(brightgreen..flexprompt.choices.left_frames["square"][1]..flexprompt.choices.right_frames["square"][1]..normal)
display_centered("--> "..brightgreen.."│ │"..normal.." <--")
display_centered(brightgreen..flexprompt.choices.left_frames["square"][2]..flexprompt.choices.right_frames["square"][2]..normal)
clink.print()
choices = ""
choices = display_yes(choices)
choices = display_no(choices)
choices = display_restart(choices)
choices = display_quit(choices)
s = readchoice(choices)
if not s or s == "q" then break end
if s == "r" then goto continue end
if s == "y" then
preview.charset = "unicode"
else
preview.charset = "ascii"
if clink.getansihost then
local term = clink.getansihost()
if term ~= "clink" and term ~= "winterminal" then
preview.symbols = preview.symbols or {}
preview.symbols.prompt = { ">", winterminal="❯" }
end
end
end
end
if preview.charset ~= "ascii" then
refresh_width(preview)
clink.print("\x1b[4H\x1b[J", NONL)
display_centered("Which of these looks like an icon of a "..brightgreen.."wrist watch"..normal.."?")
clink.print("\n")
clink.print("(1) "..brightgreen..""..normal.."\n")
clink.print("(2) "..brightgreen..""..normal.."\n")
clink.print("(3) Neither.\n")
choices = "123"
choices = display_restart(choices)
choices = display_quit(choices)
s = readchoice(choices)
if not s or s == "q" then break end
if s == "r" then goto continue end
if s == "1" then
nerdfonts_version = 3
elseif s == "2" then
nerdfonts_version = 2
end
hasicons = nerdfonts_version and true or false
end
if hasicons then
refresh_width(preview)
clink.print("\x1b[4H\x1b[J", NONL)
display_centered("Which of these fit better between the crosses without being cut off?")
clink.print("\n")
clink.print("(1) Mono width icons. These should fit tightly, without being cut off.\n")
clink.print(" --> " .. make_icon_list({"","","",""}) .. " <--\n")
clink.print("(2) Double-width icons. These should fit loosely, without being cut off.\n")
clink.print(" --> " .. make_icon_list({" "," "," "," "}) .. " <--\n")
clink.print("(3) Neither of them look right.\n")
choices = "123"
choices = display_restart(choices)
choices = display_quit(choices)
s = readchoice(choices)
if not s or s == "q" then break end
if s == "r" then goto continue end
if s == "3" then
hasicons = false
nerdfonts_version = nil
nerdfonts_width = nil
elseif s == "2" then
nerdfonts_width = 2
else
nerdfonts_width = 1
end
end
preview.nerdfonts_version = nerdfonts_version
preview.nerdfonts_width = nerdfonts_width
if preview.charset == "ascii" then
callout = { 4, {1,1}, "\x1b[1;33m/\x1b[A\x1b[Dseparator\x1b[m" }
preview.left_frame = "none"
preview.right_frame = "none"
else
callout = { 4, 1, "\x1b[1;33m↓\x1b[A\x1b[2Dseparator\x1b[m" }
preview.heads = preview.powerline_font and "pointed" or nil
preview.left_frame = "round"
preview.right_frame = "round"
refresh_width(preview)
clink.print("\x1b[4H\x1b[J", NONL)
display_centered("Does this look like "..brightgreen.."><"..normal.." but taller and fatter?")
clink.print("\n")
display_centered("--> "..brightgreen.."❯❮"..normal.." <--")
clink.print("\n")
choices = ""
choices = display_yes(choices)
choices = display_no(choices)
choices = display_restart(choices)
choices = display_quit(choices)
s = readchoice(choices)
if not s or s == "q" then break end
if s == "r" then goto continue end
preview.symbols = preview.symbols or {}
preview.symbols.prompt = { ">", winterminal="❯" }
if os.getenv("WT_SESSION") then
if s == "n" then
preview.symbols.prompt = ">"
end
else
if s == "y" then
preview.symbols.prompt = "❯"
end
end
end
if wizard_can_use_extended_colors(preview) then
refresh_width(preview)
clink.print("\x1b[4H\x1b[J", NONL)
display_centered("Are the letters "..brightgreen.."A"..normal.." to "..brightgreen.."L"..normal.." readable, in a smooth gradient?")
clink.print("\n")
display_centered("--> "..eight_bit_color_test.." <--")
clink.print("\n")
choices = ""
choices = display_yes(choices)
choices = display_no(choices)
choices = display_restart(choices)
choices = display_quit(choices)
s = readchoice(choices)
if not s or s == "q" then break end