-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstate.rs
More file actions
928 lines (846 loc) · 34.8 KB
/
state.rs
File metadata and controls
928 lines (846 loc) · 34.8 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
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
use ratatui::layout::Rect;
use ratatui::widgets::ListState;
use std::collections::BTreeSet;
use std::sync::mpsc::{Receiver, Sender, TryRecvError};
use crate::common::InstallLogMsg;
use crate::core::types::{
AdditionalPackage, CustomRepo, DiskPartitionSpec, Focus, InstallClickTarget, MenuEntry,
NetworkInterfaceConfig, PopupKind, Screen, UserAccount,
};
pub struct AppState {
/// True if a real install completed (not dry-run)
pub install_completed: bool,
// Reboot prompt state
pub reboot_prompt_open: bool,
pub reboot_confirmed: Option<bool>,
/// For visual indicator: last seen install_log length
pub last_install_log_len: Option<usize>,
pub dry_run: bool,
/// Enable extra debug logging to debug.log
pub debug_enabled: bool,
pub menu_entries: Vec<MenuEntry>,
pub selected_index: usize,
pub info_message: String,
pub focus: Focus,
pub last_menu_rect: Rect,
pub last_infobox_rect: Rect,
pub last_content_rect: Rect,
pub list_state: ListState,
// Locales screen state
pub locales_focus_index: usize, // 0: keyboard, 1: language, 2: encoding
pub keyboard_layout_options: Vec<String>,
pub keyboard_layout_index: usize,
pub locale_language_options: Vec<String>,
pub locale_language_index: usize,
pub locale_encoding_options: Vec<String>,
pub locale_encoding_index: usize,
pub locale_language_to_encoding: std::collections::BTreeMap<String, String>,
pub locales_loaded: bool,
// Popup state
pub popup_open: bool,
pub popup_kind: Option<PopupKind>,
pub popup_items: Vec<String>,
pub popup_visible_indices: Vec<usize>,
pub popup_selected_visible: usize,
pub popup_in_search: bool,
pub popup_search_query: String,
// Edit session (Locales)
pub editing_locales: bool,
pub draft_keyboard_layout_index: usize,
pub draft_locale_language_index: usize,
pub draft_locale_encoding_index: usize,
// Command line (vim-like) in decision menu
pub cmdline_open: bool,
pub cmdline_buffer: String,
// Disk Partitioning screen state
pub disks_focus_index: usize, // 0..=2 items + 3 Continue
pub disks_mode_index: usize, // selected mode index 0..=2
pub disks_devices: Vec<crate::app::disks::DiskDevice>,
pub disks_selected_device: Option<String>,
// Cached details of the selected device (for partitioning/mounting)
pub disks_selected_device_model: Option<String>,
pub disks_selected_device_devtype: Option<String>,
pub disks_selected_device_size: Option<String>,
pub disks_selected_device_freespace: Option<String>,
pub disks_selected_device_sector_size: Option<String>,
pub disks_selected_device_read_only: Option<bool>,
// Extended disk configuration
pub disks_label: Option<String>,
pub disks_wipe: bool,
pub disks_align: Option<String>,
pub disks_partitions: Vec<DiskPartitionSpec>,
pub btrfs_subvolume_preset: usize, // 0=Flat, 1=Standard, 2=Extended
/// Cached output of findmnt/swapon for pre-mounted mode (avoid subprocesses every render).
pub pre_mounted_cache_mount_lines: Vec<String>,
pub pre_mounted_cache_findmnt_failed: bool,
pub pre_mounted_cache_swap_devices: Vec<String>,
pub pre_mounted_cache_instant: Option<std::time::Instant>,
// Manual Partitioning: create partition popup state
pub manual_create_units_index: usize, // 0: B, 1: KiB/KB, 2: MiB/MB, 3: GiB/GB
pub manual_create_free_start_bytes: u64,
pub manual_create_free_end_bytes: u64,
pub manual_create_selected_size_bytes: u64,
pub manual_create_focus_units: bool,
pub manual_create_kind_index: usize, // 0: BOOT, 1: SWAP, 2: ROOT, 3: OTHER
pub manual_create_fs_options: Vec<String>,
pub manual_create_fs_index: usize,
pub manual_create_mountpoint: String,
pub manual_edit_index: Option<usize>,
// Manual Partitioning: per-row metadata for the table (selection handling)
pub manual_partition_row_meta: Vec<crate::core::types::ManualPartitionRowMeta>,
// Mirrors & Repositories screen state
pub mirrors_focus_index: usize, // 0..=3 items + 4 Continue
pub mirrors_regions_options: Vec<String>,
pub mirrors_regions_selected: BTreeSet<usize>,
pub mirrors_loaded: bool,
pub optional_repos_options: Vec<String>,
pub optional_repos_selected: BTreeSet<usize>,
pub mirrors_custom_servers: Vec<String>,
pub custom_input_buffer: String,
pub custom_repos: Vec<CustomRepo>,
pub draft_repo_name: String,
pub draft_repo_url: String,
pub draft_repo_sig_index: usize,
pub draft_repo_signopt_index: usize,
// AUR settings
pub aur_selected: bool, // true if AUR repo option was chosen
pub aur_helper_index: Option<usize>, // 0: yay, 1: paru
// Disk Encryption screen state
pub diskenc_focus_index: usize, // fields + Continue
pub disk_encryption_type_index: usize, // 0: None, 1: LUKS
pub disk_encryption_password: String,
pub disk_encryption_password_confirm: String,
pub diskenc_reopen_after_info: bool,
pub disk_encryption_selected_partition: Option<String>,
// Swap Partition state
pub swap_focus_index: usize, // 0: toggle, 1: Continue
pub swap_enabled: bool,
pub detected_ram_mib: u64,
pub swap_size_mib: u64,
// Unified Kernel Images state
pub uki_focus_index: usize, // 0: toggle, 1: Continue
pub uki_enabled: bool,
// Bootloader state
pub bootloader_focus_index: usize, // 0: selector, 1: Continue
pub bootloader_index: usize, // 0: systemd-boot, 1: grub, 2: efistub, 3: limine
/// When `Some`, install code treats the host as UEFI or BIOS without probing `/sys/firmware/efi` (tests).
pub firmware_uefi_override: Option<bool>,
/// Secure Boot status detected at startup (or forced in tests via override).
pub secure_boot_enabled: bool,
/// True when Secure Boot status was detected confidently.
pub secure_boot_known: bool,
/// True when the firmware is in UEFI Setup Mode (no keys enrolled).
pub secure_boot_setup_mode: bool,
/// Optional test override for Secure Boot state.
pub secure_boot_override: Option<bool>,
// Kernels state
pub kernels_focus_index: usize, // 0: select, 1: Continue
pub selected_kernels: std::collections::BTreeSet<String>,
// Audio state
pub audio_focus_index: usize, // 0..=2 choices + 3 Continue
pub audio_index: usize, // 0: None, 1: pipewire, 2: pulseaudio
// Network Configuration state
pub network_focus_index: usize, // 0..=2 choices + 3 Continue
pub network_mode_index: usize, // 0: Copy ISO, 1: Manual, 2: NetworkManager
pub network_configs: Vec<NetworkInterfaceConfig>,
pub network_selected_interface: Option<String>,
pub network_draft_mode_static: bool,
pub network_draft_ip_cidr: String,
pub network_draft_gateway: String,
pub network_draft_dns: String,
pub network_reopen_after_info_ip: bool,
pub network_reopen_after_info_gateway: bool,
pub network_reopen_after_info_dns: bool,
// Experience Mode state
pub experience_focus_index: usize, // 0..=3 items + 4 Continue
pub experience_mode_index: usize, // 0: Desktop, 1: Minimal, 2: Server, 3: Xorg
pub selected_desktop_envs: std::collections::BTreeSet<String>,
pub selected_server_types: std::collections::BTreeSet<String>,
pub selected_server_packages:
std::collections::BTreeMap<String, std::collections::BTreeSet<String>>,
// Xorg popup: selected types and packages (mirrors Server structure)
pub selected_xorg_types: std::collections::BTreeSet<String>,
pub selected_xorg_packages:
std::collections::BTreeMap<String, std::collections::BTreeSet<String>>,
// Desktop popup: selected packages per environment
pub selected_env_packages:
std::collections::BTreeMap<String, std::collections::BTreeSet<String>>,
// Desktop popup: focus and selection within packages list
pub popup_packages_focus: bool,
pub popup_packages_selected_index: usize,
// Graphic Drivers selection shared by Desktop/Xorg popups
pub selected_graphic_drivers: std::collections::BTreeSet<String>,
pub popup_drivers_focus: bool,
pub popup_drivers_selected_index: usize,
// Desktop popup: globally selected login manager (None means no manager)
pub selected_login_manager: Option<String>,
pub login_manager_user_set: bool,
// Desktop popup: focus and selection within login managers list
pub popup_login_focus: bool,
pub popup_login_selected_index: usize,
// Hostname state
pub hostname_focus_index: usize, // 0 input, 1 Continue
pub hostname_value: String,
pub hostname_reopen_after_info: bool,
// Timezone state
pub timezone_focus_index: usize, // 0: select, 1: Continue
pub timezone_value: String,
// Automatic Time Sync state
pub ats_focus_index: usize, // 0: Yes, 1: No, 2: Continue
pub ats_enabled: bool,
// Root Password state
pub rootpass_focus_index: usize, // 0 set, 1 confirm, 2 Continue
pub root_password: String,
pub root_password_confirm: String,
pub root_password_hash: Option<String>,
pub rootpass_reopen_after_info: bool,
// User Account state
pub user_focus_index: usize, // 0: Add user, 1: Continue
pub users: Vec<UserAccount>,
pub selected_user_index: usize,
pub draft_user_username: String,
pub draft_user_password: String,
pub draft_user_password_confirm: String,
pub draft_user_is_sudo: bool,
pub username_reopen_after_info: bool,
pub userpass_reopen_after_info: bool,
pub useredit_reopen_after_info: bool,
// Configuration screen state
pub config_focus_index: usize, // 0: Save, 1: Load, 2: Continue
pub config_preset_rows: Vec<crate::app::config::presets::ConfigPresetTableRow>,
pub config_popup_rows: Vec<crate::app::config::presets::ConfigPresetTableRow>,
// Load feedback
pub last_load_missing_sections: Vec<String>,
// Additional Packages state
pub addpkgs_focus_index: usize, // 0: Add package, 1: Select groups, 2: Continue
pub additional_packages: Vec<AdditionalPackage>,
pub addpkgs_selected_index: usize, // highlighted row in the package list (↑/↓, j/k)
pub addpkgs_reopen_after_info: bool,
// Additional Packages: groups
pub addpkgs_group_focus: bool, // focus within groups vs main
pub addpkgs_group_names: Vec<String>,
pub addpkgs_group_index: usize,
pub addpkgs_group_pkg_index: usize,
pub addpkgs_group_pkg_selected: std::collections::BTreeSet<String>,
pub addpkgs_group_accum_selected: std::collections::BTreeSet<String>,
// Persistent selections per group across popup sessions
pub addpkgs_group_selected:
std::collections::BTreeMap<String, std::collections::BTreeSet<String>>,
// Sections processed
pub processed_sections: BTreeSet<Screen>,
// Install flow temp state
pub pending_wipe_confirm: Option<bool>,
// Live install logging state
pub install_running: bool,
pub install_log: Vec<String>,
pub install_log_tx: Option<Sender<InstallLogMsg>>,
pub install_log_rx: Option<Receiver<InstallLogMsg>>,
// Install progress (for in-TUI progress view)
pub install_section_titles: Vec<String>,
pub install_section_done: Vec<bool>,
pub install_current_section: Option<usize>,
// Request to exit TUI and run install in stdout mode
pub exit_tui_after_install: bool,
pub pending_install_sections:
Option<Vec<(String, Vec<crate::common::install_cmd::InstallCmd>)>>,
// Clickable targets in Install decision menu (computed each render)
pub install_click_targets: Vec<(ratatui::layout::Rect, InstallClickTarget)>,
// Keyboard selection within Install decision menu (index into install_click_targets)
pub install_focus_index: usize,
// Ephemeral toast overlay (bottom-right)
pub toast_message: Option<String>,
pub toast_deadline: Option<std::time::Instant>,
}
impl AppState {
pub fn new(dry_run: bool) -> Self {
let menu_entries = vec![
MenuEntry {
label: "Overview".into(),
content: "Welcome to archinstall-rs. Use Up/Down, Enter".into(),
screen: Screen::Overview,
},
MenuEntry {
label: "Locales".into(),
content: String::new(),
screen: Screen::Locales,
},
MenuEntry {
label: "Mirrors and Repositories".into(),
content: String::new(),
screen: Screen::MirrorsRepos,
},
MenuEntry {
label: "Disk Partitioning".into(),
content: String::new(),
screen: Screen::Disks,
},
MenuEntry {
label: "Disk Encryption".into(),
content: String::new(),
screen: Screen::DiskEncryption,
},
MenuEntry {
label: "Swap Partition".into(),
content: String::new(),
screen: Screen::SwapPartition,
},
MenuEntry {
label: "Bootloader".into(),
content: String::new(),
screen: Screen::Bootloader,
},
MenuEntry {
label: "Unified Kernel Images".into(),
content: String::new(),
screen: Screen::UnifiedKernelImages,
},
MenuEntry {
label: "Hostname".into(),
content: String::new(),
screen: Screen::Hostname,
},
MenuEntry {
label: "Root Password".into(),
content: String::new(),
screen: Screen::RootPassword,
},
MenuEntry {
label: "User Account".into(),
content: String::new(),
screen: Screen::UserAccount,
},
MenuEntry {
label: "Experience Mode".into(),
content: String::new(),
screen: Screen::ExperienceMode,
},
MenuEntry {
label: "Audio".into(),
content: String::new(),
screen: Screen::Audio,
},
MenuEntry {
label: "Kernels".into(),
content: String::new(),
screen: Screen::Kernels,
},
MenuEntry {
label: "Network Configuration".into(),
content: "Network setup and status.".into(),
screen: Screen::NetworkConfiguration,
},
MenuEntry {
label: "Additional Packages".into(),
content: "Package selection and groups.".into(),
screen: Screen::AdditionalPackages,
},
MenuEntry {
label: "Timezone".into(),
content: String::new(),
screen: Screen::Timezone,
},
MenuEntry {
label: "Automatic Time Sync".into(),
content: String::new(),
screen: Screen::AutomaticTimeSync,
},
MenuEntry {
label: "Configuration".into(),
content: String::new(),
screen: Screen::SaveConfiguration,
},
MenuEntry {
label: "Install".into(),
content: "Review and start installation.".into(),
screen: Screen::Install,
},
MenuEntry {
label: "Abort (Ctrl + C)".into(),
content: String::new(),
screen: Screen::Abort,
},
];
let mut list_state = ListState::default();
list_state.select(Some(0));
let detected_ram = crate::common::utils::detect_ram_mib();
let swap_size = crate::common::utils::compute_swap_size_mib(detected_ram);
let mut s = Self {
install_completed: false,
reboot_prompt_open: false,
reboot_confirmed: None,
last_install_log_len: None,
dry_run,
debug_enabled: false,
menu_entries,
selected_index: 0,
info_message: String::new(),
focus: Focus::Menu,
last_menu_rect: Rect::default(),
last_infobox_rect: Rect::default(),
last_content_rect: Rect::default(),
list_state,
locales_focus_index: 0,
keyboard_layout_options: Vec::new(),
keyboard_layout_index: 0,
locale_language_options: Vec::new(),
locale_language_index: 0,
locale_encoding_options: Vec::new(),
locale_encoding_index: 0,
locale_language_to_encoding: std::collections::BTreeMap::new(),
locales_loaded: false,
popup_open: false,
popup_kind: None,
popup_items: Vec::new(),
popup_visible_indices: Vec::new(),
popup_selected_visible: 0,
popup_in_search: false,
popup_search_query: String::new(),
editing_locales: false,
draft_keyboard_layout_index: 0,
draft_locale_language_index: 0,
draft_locale_encoding_index: 0,
cmdline_open: false,
cmdline_buffer: String::new(),
disks_focus_index: 0,
disks_mode_index: 0,
disks_devices: Vec::new(),
disks_selected_device: None,
disks_selected_device_model: None,
disks_selected_device_devtype: None,
disks_selected_device_size: None,
disks_selected_device_freespace: None,
disks_selected_device_sector_size: None,
disks_selected_device_read_only: None,
disks_label: Some("gpt".into()),
disks_wipe: true,
disks_align: Some("1MiB".into()),
disks_partitions: Vec::new(),
btrfs_subvolume_preset: 0, // Flat (no subvolumes) by default
pre_mounted_cache_mount_lines: Vec::new(),
pre_mounted_cache_findmnt_failed: false,
pre_mounted_cache_swap_devices: Vec::new(),
pre_mounted_cache_instant: None,
manual_create_units_index: 0,
manual_create_free_start_bytes: 0,
manual_create_free_end_bytes: 0,
manual_create_selected_size_bytes: 0,
manual_create_focus_units: false,
manual_create_kind_index: 0,
manual_create_fs_options: Vec::new(),
manual_create_fs_index: 0,
manual_create_mountpoint: String::new(),
manual_edit_index: None,
manual_partition_row_meta: Vec::new(),
mirrors_focus_index: 0,
mirrors_regions_options: Vec::new(),
mirrors_regions_selected: BTreeSet::new(),
mirrors_loaded: false,
optional_repos_options: vec!["multilib".into(), "testing".into(), "AUR".into()],
optional_repos_selected: {
let mut s = BTreeSet::new();
s.insert(0);
s
},
mirrors_custom_servers: Vec::new(),
custom_input_buffer: String::new(),
custom_repos: Vec::new(),
draft_repo_name: String::new(),
draft_repo_url: String::new(),
draft_repo_sig_index: 2,
draft_repo_signopt_index: 0,
aur_selected: false,
aur_helper_index: None,
diskenc_focus_index: 0,
disk_encryption_type_index: 0,
disk_encryption_password: String::new(),
disk_encryption_password_confirm: String::new(),
diskenc_reopen_after_info: false,
disk_encryption_selected_partition: None,
swap_focus_index: 0,
swap_enabled: true,
detected_ram_mib: detected_ram,
swap_size_mib: swap_size,
uki_focus_index: 0,
uki_enabled: false,
bootloader_focus_index: 0,
bootloader_index: 0,
firmware_uefi_override: None,
secure_boot_enabled: false,
secure_boot_known: false,
secure_boot_setup_mode: false,
secure_boot_override: None,
kernels_focus_index: 0,
selected_kernels: {
let mut s = std::collections::BTreeSet::new();
s.insert("linux".into());
s
},
audio_focus_index: 0,
audio_index: 1,
network_focus_index: 0,
network_mode_index: 2,
network_configs: Vec::new(),
network_selected_interface: None,
network_draft_mode_static: false,
network_draft_ip_cidr: String::new(),
network_draft_gateway: String::new(),
network_draft_dns: String::new(),
network_reopen_after_info_ip: false,
network_reopen_after_info_gateway: false,
network_reopen_after_info_dns: false,
experience_focus_index: 0,
experience_mode_index: 0,
selected_desktop_envs: {
let mut s = std::collections::BTreeSet::new();
s.insert("KDE Plasma".into());
s
},
selected_server_types: std::collections::BTreeSet::new(),
selected_server_packages: std::collections::BTreeMap::new(),
selected_xorg_types: std::collections::BTreeSet::new(),
selected_xorg_packages: std::collections::BTreeMap::new(),
selected_env_packages: std::collections::BTreeMap::new(),
popup_packages_focus: false,
popup_packages_selected_index: 0,
selected_graphic_drivers: {
let mut s = std::collections::BTreeSet::new();
s.insert("intel-media-driver".into());
s.insert("libva-intel-driver".into());
s.insert("mesa".into());
s.insert("vulkan-intel".into());
s.insert("vulkan-nouveau".into());
s.insert("vulkan-radeon".into());
s.insert("xf86-video-amdgpu".into());
s.insert("xf86-video-ati".into());
s.insert("xf86-video-nouveau".into());
s.insert("xorg-server".into());
s.insert("xorg-xinit".into());
s
},
popup_drivers_focus: false,
popup_drivers_selected_index: 0,
selected_login_manager: Some("sddm".into()),
login_manager_user_set: false,
popup_login_focus: false,
popup_login_selected_index: 0,
hostname_focus_index: 0,
hostname_value: "Archlinux".into(),
hostname_reopen_after_info: false,
timezone_focus_index: 0,
timezone_value: "Europe/London".into(),
ats_focus_index: 0,
ats_enabled: true,
rootpass_focus_index: 0,
root_password: String::new(),
root_password_confirm: String::new(),
root_password_hash: None,
rootpass_reopen_after_info: false,
user_focus_index: 0,
users: Vec::new(),
selected_user_index: 0,
draft_user_username: String::new(),
draft_user_password: String::new(),
draft_user_password_confirm: String::new(),
draft_user_is_sudo: false,
username_reopen_after_info: false,
userpass_reopen_after_info: false,
useredit_reopen_after_info: false,
config_focus_index: 0,
config_preset_rows: Vec::new(),
config_popup_rows: Vec::new(),
last_load_missing_sections: Vec::new(),
addpkgs_focus_index: 0,
additional_packages: Vec::new(),
addpkgs_selected_index: 0,
addpkgs_reopen_after_info: false,
addpkgs_group_focus: false,
addpkgs_group_names: vec![
"Terminals".into(),
"Shells".into(),
"Browsers".into(),
"Text Editors".into(),
"dotfile Management".into(),
],
addpkgs_group_index: 0,
addpkgs_group_pkg_index: 0,
addpkgs_group_pkg_selected: std::collections::BTreeSet::new(),
addpkgs_group_accum_selected: std::collections::BTreeSet::new(),
addpkgs_group_selected: std::collections::BTreeMap::new(),
processed_sections: BTreeSet::new(),
pending_wipe_confirm: None,
install_running: false,
install_log: Vec::new(),
install_log_tx: None,
install_log_rx: None,
install_section_titles: Vec::new(),
install_section_done: Vec::new(),
install_current_section: None,
exit_tui_after_install: false,
pending_install_sections: None,
install_click_targets: Vec::new(),
install_focus_index: 0,
toast_message: None,
toast_deadline: None,
};
// Initialize dynamic option lists and apply startup defaults
let _ = s.load_locales_options();
// Keyboard: us
if let Some(idx) = s.keyboard_layout_options.iter().position(|k| k == "us") {
s.keyboard_layout_index = idx;
s.draft_keyboard_layout_index = idx;
}
// Locale language: en_US.UTF-8
if let Some(idx) = s
.locale_language_options
.iter()
.position(|l| l == "en_US.UTF-8")
{
s.locale_language_index = idx;
s.draft_locale_language_index = idx;
}
// Encoding: UTF-8
if let Some(idx) = s
.locale_encoding_options
.iter()
.position(|e| e.eq_ignore_ascii_case("UTF-8"))
{
s.locale_encoding_index = idx;
s.draft_locale_encoding_index = idx;
}
let _ = s.load_mirrors_options();
if s.mirrors_regions_selected.is_empty()
&& let Some(idx) = s
.mirrors_regions_options
.iter()
.position(|c| c == "United States US 186")
.or_else(|| {
s.mirrors_regions_options
.iter()
.position(|c| c.contains("United States"))
})
{
s.mirrors_regions_selected.insert(idx);
}
s.update_unified_kernel_images_visibility();
// Seed default Desktop Environment packages for preselected environments
if s.selected_desktop_envs.contains("KDE Plasma")
&& !s.selected_env_packages.contains_key("KDE Plasma")
{
let defaults: Vec<&str> = vec![
"ark",
"dolphin",
"kate",
"konsole",
"plasma-meta",
"plasma-workspace",
// Common tools
"htop",
"iwd",
"nano",
"openssh",
"smartmontools",
"vim",
"wget",
"wireless_tools",
"wpa_supplicant",
"xdg-utils",
];
let set: std::collections::BTreeSet<String> =
defaults.into_iter().map(|s| s.to_string()).collect();
s.selected_env_packages.insert("KDE Plasma".into(), set);
}
// Discover bundled/repo example config presets
s.config_preset_rows = crate::app::config::presets::list_example_preset_rows();
s
}
pub fn current_screen(&self) -> Screen {
self.menu_entries[self.selected_index].screen
}
fn refresh_install_info_popup_body(&mut self) {
let info_open = self.popup_open && matches!(self.popup_kind, Some(PopupKind::Info));
if !info_open {
return;
}
let body = self.install_log.join("\n");
if self.popup_items.is_empty() {
self.popup_items.push(body);
} else {
self.popup_items[0] = body;
}
}
/// Apply one message from the install thread (line append or in-place progress update).
pub fn append_install_log_msg(&mut self, msg: InstallLogMsg) {
match msg {
InstallLogMsg::Line(line) => {
// Interpret simple progress markers and update state
if let Some(rest) = line.strip_prefix("::section_start::") {
if let Some(idx) = self.install_section_titles.iter().position(|t| t == rest) {
self.install_current_section = Some(idx);
self.debug_log(&format!(
"append_install_log_msg: section_start '{rest}' idx={idx}"
));
}
return;
}
if let Some(rest) = line.strip_prefix("::section_done::") {
if let Some(idx) = self.install_section_titles.iter().position(|t| t == rest)
&& idx < self.install_section_done.len()
{
self.install_section_done[idx] = true;
self.debug_log(&format!(
"append_install_log_msg: section_done '{rest}' idx={idx}"
));
}
return;
}
self.install_log.push(line);
// No log line limit: allow install_log to grow as needed
self.refresh_install_info_popup_body();
}
InstallLogMsg::ReplaceLastLine(line) => {
if line.is_empty() {
return;
}
if self.install_log.is_empty() {
self.install_log.push(line);
} else {
let n = self.install_log.len().saturating_sub(1);
self.install_log[n] = line;
}
self.refresh_install_info_popup_body();
}
}
}
pub fn drain_install_logs(&mut self) {
let Some(rx) = self.install_log_rx.take() else {
if self.install_running {
self.debug_log("drain_install_logs: no install_log_rx");
}
return;
};
let mut drained: Vec<InstallLogMsg> = Vec::new();
let mut disconnected = false;
loop {
match rx.try_recv() {
Ok(msg) => drained.push(msg),
Err(TryRecvError::Empty) => break,
Err(TryRecvError::Disconnected) => {
disconnected = true;
self.debug_log("drain_install_logs: channel disconnected, will set install_running = false");
break;
}
}
}
let drained_count = drained.len();
for msg in drained {
self.append_install_log_msg(msg);
}
// Update last_install_log_len for visual indicator
self.last_install_log_len = Some(self.install_log.len());
// Summarize this drain cycle
if drained_count > 0 {
self.debug_log(&format!(
"drain_install_logs: drained {} line(s) this cycle (total_log_len={})",
drained_count,
self.install_log.len()
));
if self.popup_open && matches!(self.popup_kind, Some(PopupKind::Info)) {
self.debug_log("drain_install_logs: info popup body updated");
}
}
if disconnected {
self.install_running = false;
self.install_log_rx = None;
self.install_log_tx = None;
self.debug_log("drain_install_logs: install_running set to false");
// Show a message in the TUI log output when channel is disconnected
self.install_log
.push("[Install process ended: no more output will be received.]".to_string());
} else {
self.install_log_rx = Some(rx);
}
}
pub(crate) fn debug_log(&self, msg: &str) {
if !self.debug_enabled {
return;
}
let now = chrono::Local::now();
let ts = now.format("%Y-%m-%d %H:%M:%S");
let _ = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open("debug.log")
.and_then(|mut f| {
use std::io::Write;
writeln!(f, "[DEBUG {ts}] {msg}")
});
}
// Helper mutators with debug logging
pub fn set_selected_index(&mut self, idx: usize) {
if self.selected_index != idx {
self.debug_log(&format!(
"state: selected_index {} -> {} (screen={:?})",
self.selected_index, idx, self.menu_entries[idx].screen
));
self.selected_index = idx;
self.list_state.select(Some(idx));
}
}
pub fn set_focus(&mut self, new_focus: Focus) {
if self.focus != new_focus {
self.debug_log(&format!("state: focus {:?} -> {:?}", self.focus, new_focus));
self.focus = new_focus;
}
}
pub fn set_popup_open(&mut self, open: bool) {
if self.popup_open != open {
self.debug_log(&format!(
"state: popup_open {} -> {}",
self.popup_open, open
));
self.popup_open = open;
}
}
pub fn set_popup_kind(&mut self, kind: Option<PopupKind>) {
if self.popup_kind != kind {
self.debug_log(&format!(
"state: popup_kind {:?} -> {:?}",
self.popup_kind, kind
));
self.popup_kind = kind;
}
}
pub fn set_popup_in_search(&mut self, in_search: bool) {
if self.popup_in_search != in_search {
self.debug_log(&format!(
"state: popup_in_search {} -> {}",
self.popup_in_search, in_search
));
self.popup_in_search = in_search;
}
}
pub fn reset_install_progress(&mut self, titles: Vec<String>) {
self.install_section_titles = titles.clone();
self.install_section_done = vec![false; titles.len()];
self.install_current_section = None;
let summary = titles.join(", ");
self.debug_log(&format!(
"state: install_* initialized count={} [{}]",
titles.len(),
summary
));
}
// Open the AUR helper selection popup
pub fn open_aur_helper_popup(&mut self) {
self.popup_kind = Some(PopupKind::AurHelperSelect);
self.popup_items = vec![
"yay — Yet another yogurt. Pacman wrapper and AUR helper written in go.".into(),
"paru — Feature packed AUR helper written in Rust".into(),
];
self.popup_visible_indices = (0..self.popup_items.len()).collect();
self.popup_selected_visible = 0;
self.popup_in_search = false;
self.popup_search_query.clear();
self.popup_open = true;
}
}