eilmeldung 1.4.2

a feature-rich TUI RSS Reader based on the news-flash library
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
mod parse;

use ratatui::style::Color;
use std::fmt::Display;
use std::str::FromStr;
use strum::EnumMessage;

use news_flash::models::{Enclosure, Url};

pub mod prelude {
    pub use super::parse::CommandParseError;
    pub use super::{ActionScope, Command, CommandSequence, EnclosureType, Panel, PastePosition};
}

use crate::prelude::*;

#[derive(
    Clone,
    Copy,
    Debug,
    Default,
    Eq,
    PartialEq,
    strum::EnumString,
    strum::EnumMessage,
    strum::EnumIter,
    strum::AsRefStr,
)]
#[strum(
    parse_err_fn = CommandParseError::panel_expected,
    parse_err_ty = CommandParseError)]
pub enum Panel {
    #[default]
    #[strum(serialize = "feeds")]
    #[strum(
        message = "feeds",
        detailed_message = "panel with tree of feeds, categories, tags, etc."
    )]
    FeedList,

    #[strum(serialize = "articles")]
    #[strum(
        message = "article list",
        detailed_message = "panel with the list of articles"
    )]
    ArticleList,

    #[strum(serialize = "content")]
    #[strum(
        message = "article content",
        detailed_message = "content of the selected article"
    )]
    ArticleContent,
}
impl Display for Panel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.get_message().unwrap().fmt(f) // <- if this fails, it must fail hard
    }
}

impl CommandParseError {
    fn panel_expected(_: &str) -> CommandParseError {
        CommandParseError::PanelExpected
    }
}

#[derive(Clone, Debug, Default, strum::EnumIter, strum::EnumMessage, strum::AsRefStr)]
pub enum ActionScope {
    #[default]
    #[strum(
        serialize = "current",
        message = "current",
        detailed_message = "currently selected item"
    )]
    Current,

    #[strum(
        serialize = "above",
        message = "above",
        detailed_message = "currently selected item and all above"
    )]
    Above,

    #[strum(
        serialize = "below",
        message = "below",
        detailed_message = "currently selected item and all below"
    )]
    Below,

    #[strum(serialize = "all", message = "all", detailed_message = "all items")]
    All,
    #[strum(
        message = "query",
        detailed_message = "all articles defined by a query"
    )]
    Query(ArticleQuery),
}

impl FromStr for ActionScope {
    type Err = CommandParseError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        use ActionScope as S;
        match s {
            "." | "current" => Ok(S::Current),
            "%" | "all" => Ok(S::All),
            "above" => Ok(S::Above),
            "below" => Ok(S::Below),
            _ => Ok(S::Query(ArticleQuery::from_str(s)?)),
        }
    }
}

impl ActionScope {
    fn from_option_string(s: Option<&str>) -> Result<ActionScope, CommandParseError> {
        match s {
            Some(s) => Ok(ActionScope::from_str(s)?),
            None => Ok(ActionScope::Current),
        }
    }
}

impl Display for ActionScope {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        use ActionScope as S;
        match self {
            S::Current => write!(f, "current article")?,
            S::All => write!(f, "all articles")?,
            S::Below => write!(f, "current article and all below")?,
            S::Above => write!(f, "current article and all above")?,
            S::Query(query) => write!(f, "all articles matching {}", query.query_string())?,
        };
        Ok(())
    }
}

#[derive(
    Debug,
    Clone,
    Copy,
    strum::EnumString,
    strum::EnumIter,
    strum::EnumMessage,
    strum::AsRefStr,
    PartialEq,
    Eq,
)]
#[strum(serialize_all = "lowercase")]
pub enum EnclosureType {
    #[strum(message = "audio", detailed_message = "audio enclosure")]
    Audio,

    #[strum(message = "video", detailed_message = "video enclosure")]
    Video,

    #[strum(message = "image", detailed_message = "image enclosure")]
    Image,
}

impl Display for EnclosureType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.get_message().unwrap().fmt(f) // <- if this fails, it must fail hard
    }
}

impl From<&Enclosure> for EnclosureType {
    fn from(enclosure: &Enclosure) -> Self {
        if enclosure.is_video() {
            EnclosureType::Video
        } else if enclosure.is_audio() {
            EnclosureType::Audio
        } else {
            EnclosureType::Image
        }
    }
}

#[derive(Debug, Clone, Copy, Default, strum::EnumString, strum::EnumIter, strum::EnumMessage)]
#[strum(serialize_all = "lowercase")]
pub enum PastePosition {
    #[default]
    #[strum(
        message = "after",
        detailed_message = "position after the current element"
    )]
    After,
    #[strum(
        message = "before",
        detailed_message = "position before the current element"
    )]
    Before,
}

impl Display for PastePosition {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.get_message().unwrap().fmt(f) // <- if this fails, it must fail hard
    }
}

#[derive(
    Clone, Debug, Default, strum::AsRefStr, strum::EnumString, strum::EnumIter, strum::EnumMessage,
)]
pub enum Command {
    #[default]
    #[strum(
        serialize = "nop",
        message = "nop",
        detailed_message = "no operation (for unmapping key bindings)"
    )]
    NoOperation,

    // general navigation
    #[strum(
        serialize = "up",
        message = "up",
        detailed_message = "nagivates up in the current context (all)"
    )]
    NavigateUp,

    #[strum(
        serialize = "down",
        message = "down",
        detailed_message = "nagivates down in the current context (all)"
    )]
    NavigateDown,

    #[strum(
        serialize = "pageup",
        message = "pageup",
        detailed_message = "navigates up by several items (all)"
    )]
    NavigatePageUp,
    #[strum(
        serialize = "pagedown",
        message = "pagedown",
        detailed_message = "navigates down by several items (all)"
    )]
    NavigatePageDown,

    #[strum(
        serialize = "gotofirst",
        message = "gotofirst",
        detailed_message = "navigate to first element (all)"
    )]
    NavigateFirst,

    #[strum(
        serialize = "gotolast",
        message = "gotolast",
        detailed_message = "navigate to last element (all)"
    )]
    NavigateLast,

    #[strum(
        serialize = "left",
        message = "left",
        detailed_message = "nagivate left in the current context (all)"
    )]
    NavigateLeft,

    #[strum(
        serialize = "right",
        message = "right",
        detailed_message = "nagivate right in the current context (all)"
    )]
    NavigateRight,

    #[strum(
        serialize = "nextunread",
        message = "nextunread",
        detailed_message = "select next unread item (feed list, article list)"
    )]
    SelectNextUnread,

    #[strum(
        serialize = "_search",
        message = "_search",
        detailed_message = "open prompt to search"
    )]
    InputSearch,

    #[strum(
        serialize = "_abort",
        message = "abort",
        detailed_message = "abort current dialog"
    )]
    InputAbort,

    #[strum(
        serialize = "_submit",
        message = "submit",
        detailed_message = "submit current input"
    )]
    InputSubmit,

    #[strum(
        serialize = "_clear",
        message = "clear",
        detailed_message = "clear current input"
    )]
    InputClear,

    // Panels
    #[strum(
        serialize = "next",
        message = "next",
        detailed_message = "focus next panel until article content (all)"
    )]
    PanelFocusNext,
    #[strum(
        serialize = "prev",
        message = "prev",
        detailed_message = "focus previous panel until feed list (all)"
    )]
    PanelFocusPrevious,
    #[strum(
        serialize = "nextc",
        message = "nextc",
        detailed_message = "focus next panel, cycling back to feed list (all)"
    )]
    PanelFocusNextCyclic,
    #[strum(
        serialize = "prevc",
        message = "prevc",
        detailed_message = "focus previous panel, cycling back to article content (all)"
    )]
    PanelFocusPreviousCyclic,

    #[strum(
        serialize = "focus",
        message = "focus <panel>",
        detailed_message = "focuses the given panel (all)"
    )]
    PanelFocus(Panel),

    #[strum(
        serialize = "zen",
        message = "zen",
        detailed_message = "toggle distraction-free mode (article content)"
    )]
    ToggleDistractionFreeMode,

    // feed list
    #[strum(
        serialize = "sync",
        message = "sync",
        detailed_message = "sync all feeds (feed list)"
    )]
    FeedListSync,
    #[strum(
        serialize = "categoryadd",
        message = "categoryadd <category name>",
        detailed_message = "add a new category with the given name (feed list)"
    )]
    FeedListCategoryAdd(String),

    #[strum(
        serialize = "feedadd",
        message = "feedadd <feed URL> [<name>]",
        detailed_message = "add a new feed with the given URL and optional name (feed list)"
    )]
    FeedListFeedAdd(Option<Url>, Option<String>),

    #[strum(
        serialize = "tagchangecolor",
        message = "tagchangecolor <color>",
        detailed_message = "change the color of the selected tag (feed list)"
    )]
    FeedListTagChangeColor(Color),

    #[strum(
        serialize = "rename",
        message = "rename <new name>",
        detailed_message = "rename the selected item (feed list)"
    )]
    FeedListRenameEntity(String),

    #[strum(
        serialize = "remove",
        message = "remove",
        detailed_message = "remove the selected childless item (feed list)"
    )]
    FeedListRemoveEntity,

    #[strum(
        serialize = "removeall",
        message = "removeall",
        detailed_message = "remove the selected item with children (feed list)"
    )]
    FeedListRemoveEntityWithChildren,

    #[strum(
        serialize = "feedchangeurl",
        message = "feedchangeurl",
        detailed_message = "change URL of the selected feed (feed list)"
    )]
    FeedListFeedChangeUrl(Option<Url>),

    #[strum(
        serialize = "yank",
        message = "yank",
        detailed_message = "yank the selected item (feed or category) for moving (feed list)"
    )]
    FeedListYankFeedOrCategory,

    #[strum(
        serialize = "paste",
        message = "paste <paste position>",
        detailed_message = "paste the yanked item before/after selected item (feed list)"
    )]
    FeedListPasteFeedOrCategory(PastePosition),

    #[strum(
        serialize = "toggle",
        message = "toggle",
        detailed_message = "toggle selected item open/closed (feed list)"
    )]
    FeedListToggleExpand,

    #[strum(
        serialize = "expandcategories",
        message = "expandcategories <scope>",
        detailed_message = "expands current selected item or all categories belonging to scope (feed list)"
    )]
    FeedListExpandCategories(ArticleScope),

    #[strum(
        serialize = "expand",
        message = "expand",
        detailed_message = "expands current selected item (feed list)"
    )]
    FeedListExpand,

    #[strum(
        serialize = "collapse",
        message = "collapse",
        detailed_message = "collapses the currently selected item (feed list)"
    )]
    FeedListCollapse,

    #[strum(
        serialize = "collapseall",
        message = "collapseall",
        detailed_message = "collapses all items (feed list)"
    )]
    FeedListCollapseAll,

    #[strum(
        serialize = "read",
        message = "read [<scope>]",
        detailed_message = "set all articles matching the scope in the target to read (feed list, article list)"
    )]
    ActionSetRead(ActionScope),

    #[strum(
        serialize = "unread",
        message = "unread <scope>",
        detailed_message = "set all articles matching the scope to unread (feed list, article list)"
    )]
    ActionSetUnread(ActionScope),

    #[strum(
        serialize = "mark",
        message = "mark <scope>",
        detailed_message = "marks all articles matching the scope (article list)"
    )]
    ActionSetMarked(ActionScope),

    #[strum(
        serialize = "unmark",
        message = "unmark <scope>",
        detailed_message = "unmarks all articles matching the scope (article list)"
    )]
    ActionSetUnmarked(ActionScope),

    #[strum(
        serialize = "flag",
        message = "flag <scope>",
        detailed_message = "flags all articles matching the scope (article list)"
    )]
    ActionSetFlagged(ActionScope),

    #[strum(
        serialize = "unflag",
        message = "unflag <scope>",
        detailed_message = "unflags all articles matching the scope (article list)"
    )]
    ActionSetUnflagged(ActionScope),

    #[strum(
        serialize = "flaginvert",
        message = "flaginvert <scope>",
        detailed_message = "inverts flagged articles (article list)"
    )]
    ActionFlagInvert(ActionScope),

    #[strum(
        serialize = "open",
        message = "open",
        detailed_message = "opens all articles matching the scope in the webbrowser (article list)"
    )]
    ActionOpenInBrowser(ActionScope),

    #[strum(
        serialize = "tag",
        message = "tag <tag name> [<scope>]",
        detailed_message = "adds the tag to all articles matching the scope (article list)"
    )]
    ActionTagArticles(ActionScope, String),

    #[strum(
        serialize = "untag",
        message = "untag <tag name> [<scope>]",
        detailed_message = "removes the tag from all articles matching the scope (article list)"
    )]
    ActionUntagArticles(ActionScope, String),

    #[strum(
        serialize = "tagadd",
        message = "tagadd <tag name> [<color>]",
        detailed_message = "adds a new tag with the given name and optional color (feed list)"
    )]
    TagAdd(String, Option<Color>),

    // article list commands
    #[strum(
        serialize = "show",
        message = "show <article scope>",
        detailed_message = "show only articles in the article scope (feed list, article list)"
    )]
    Show(ArticleScope),

    #[strum(
        serialize = "openenclosure",
        message = "openenclosure [<enclosure type>]",
        detailed_message = "open the default enclosure or the enclosure of the given type (article content)"
    )]
    ArticleOpenEnclosure(Option<EnclosureType>),

    #[strum(
        serialize = "scrape",
        message = "scrape",
        detailed_message = "scrape the current article (article list, article content)"
    )]
    ArticleCurrentScrape,

    // article list searching
    #[strum(
        serialize = "searcharticles",
        message = "searcharticles <article query>",
        detailed_message = "search for articles matching the query (article list)"
    )]
    ArticleListSearch(ArticleQuery),

    #[strum(
        serialize = "search",
        message = "search <search term>",
        detailed_message = "search item by search term (feed list)"
    )]
    Search(Option<SearchTerm>),

    #[strum(
        serialize = "searchnext",
        message = "searchnext",
        detailed_message = "search next matching item (feed list, article list)"
    )]
    SearchNext,

    #[strum(
        serialize = "searchprev",
        message = "searchprev",
        detailed_message = "search previous matching item (feed list, article list)"
    )]
    SearchPrevious,

    #[strum(
        serialize = "filter",
        message = "filter <article query>",
        detailed_message = "filter articles by query (article list)"
    )]
    ArticleListFilterSet(ArticleQuery),

    #[strum(
        serialize = "filtersticky",
        message = "filtersticky <article query>",
        detailed_message = "filter articles by query sticky, i.e., always apply filter (article list)"
    )]
    ArticleListFilterSetSticky(ArticleQuery),

    #[strum(
        serialize = "filterapply",
        message = "filterapply",
        detailed_message = "apply current filter (article list)"
    )]
    ArticleListFilterApply,

    #[strum(
        serialize = "filterclear",
        message = "filterclear",
        detailed_message = "clear current filter (article list)"
    )]
    ArticleListFilterClear,

    #[strum(
        serialize = "sort",
        message = "sort <sort order>",
        detailed_message = "sort articles according to sort order (article list)"
    )]
    ArticleListSort(SortOrder),

    #[strum(
        serialize = "hintfollow",
        message = "hintfollow <url hint>",
        detailed_message = "opens the URL of the given hint (article content)"
    )]
    ContentFollowHint(String),

    #[strum(
        serialize = "hintshare",
        message = "hintshare <share> <url hint>",
        detailed_message = "shares the URL of the given hint (article content)"
    )]
    ContentShareHint(String, String),

    #[strum(
        serialize = "sortfeeds",
        message = "sortfeeds",
        detailed_message = "sorts the feeds alphabetically (cannot be undone)"
    )]
    FeedListSort,

    #[strum(
        serialize = "sortreverse",
        message = "sortreverse",
        detailed_message = "reverse the current sort order (article list)"
    )]
    ArticleListSortReverse,

    #[strum(
        serialize = "sortclear",
        message = "sortclear",
        detailed_message = "clear the current sort order (article list)"
    )]
    ArticleListSortClear,

    #[strum(
        serialize = "query",
        message = "query <article query>",
        detailed_message = "executes a query on all articles (article list)"
    )]
    ArticleListQuery(ArticleQuery),

    #[strum(
        serialize = "share",
        message = "share <target>",
        detailed_message = "shares title and url with target (article list, article content)"
    )]
    ArticleShare(String),

    #[strum(
        serialize = "importopml",
        message = "importopml <path>",
        detailed_message = "imports an OPML file from the given path (all)"
    )]
    ImportOpml(String),

    #[strum(
        serialize = "exportopml",
        message = "exportopml <path>",
        detailed_message = "exports an OPML file to the given path (all)"
    )]
    ExportOpml(String),

    // application
    #[strum(
        serialize = "quit",
        message = "quit",
        detailed_message = "quit eilmeldung (all)"
    )]
    ApplicationQuit,

    // command line
    #[strum(
        serialize = "cmd",
        message = "cmd [<command line content>]",
        detailed_message = "open command line with optional content (all)"
    )]
    #[allow(clippy::enum_variant_names)]
    CommandLineOpen(Option<String>),

    #[strum(
        serialize = "LOGOUT",
        message = "LOGOUT <confirmation>",
        detailed_message = "logout, NOTE: this will remove ALL LOCAL DATA! Pass `NOW` as parameter to confirm."
    )]
    Logout(String),

    #[strum(
        serialize = "helpinput",
        message = "helpinput",
        detailed_message = "show help on in put mappings (all)"
    )]
    HelpInput,

    #[strum(
        serialize = "confirm",
        message = "confirm <command>",
        detailed_message = "ask user for confirmation to execute command and, if positive, execute command (all)"
    )]
    #[allow(clippy::enum_variant_names)]
    CommandConfirm(Box<Command>),

    #[strum(
        serialize = "in",
        message = "in <panel> <command>",
        detailed_message = "execute command in the panel"
    )]
    In(Panel, Box<Command>),

    // redraw command
    #[strum(
        serialize = "redraw",
        message = "redraw",
        detailed_message = "redraw screen (all)"
    )]
    Redraw,

    #[strum(
        serialize = "refresh",
        message = "refresh",
        detailed_message = "refreshes contents of all panels according to selections (all)"
    )]
    Refresh,
}

impl Command {
    pub fn unwrap_in(&self, panel: Panel) -> Option<&Command> {
        if let Command::In(target_panel, command) = self {
            return (*target_panel == panel).then_some(command);
        }
        Some(self)
    }
}

impl Display for Command {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        use Command::*;
        match self.clone() {
            NoOperation => write!(f, "no operation"),
            NavigateUp => write!(f, "up"),
            NavigateDown => write!(f, "down"),
            NavigatePageUp => write!(f, "page up"),
            NavigatePageDown => write!(f, "page down"),
            NavigateFirst => write!(f, "to first"),
            NavigateLast => write!(f, "to last"),
            NavigateLeft => write!(f, "left"),
            NavigateRight => write!(f, "right"),
            InputSearch => write!(f, "open find prompt"),
            InputAbort => write!(f, "abort current input"),
            InputSubmit => write!(f, "submit current input"),
            InputClear => write!(f, "clear current input"),
            PanelFocusNext => write!(f, "focus next"),
            PanelFocus(panel) => write!(f, "focus {}", panel),
            PanelFocusPrevious => write!(f, "focus previous"),
            PanelFocusNextCyclic => write!(f, "focus previous (wrapping)"),
            PanelFocusPreviousCyclic => write!(f, "focus next (wrapping)"),
            ToggleDistractionFreeMode => write!(f, "distraction free mode"),
            FeedListToggleExpand => write!(f, "toggle selected node"),
            FeedListExpand => write!(f, "expand the selected node"),
            FeedListCollapse => write!(f, "collapse the selected node"),
            FeedListCollapseAll => write!(f, "collapse the selected node"),
            FeedListExpandCategories(ArticleScope::All) => write!(f, "expand all nodes"),
            FeedListExpandCategories(ArticleScope::Unread) => {
                write!(f, "expand all categories with unread items")
            }
            FeedListExpandCategories(ArticleScope::Marked) => {
                write!(f, "expand all categories with marked items")
            }
            FeedListCategoryAdd(name) => write!(f, "add category {name}"),
            FeedListFeedAdd(Some(url), Some(name)) => write!(f, "add feed {name} with url {url}"),
            FeedListFeedAdd(Some(url), None) => write!(f, "add feed with url {url}"),
            FeedListFeedAdd(None, _) => unreachable!(),
            FeedListRenameEntity(name) => write!(f, "rename selected to {name}"),
            FeedListRemoveEntity => write!(f, "remove selected"),
            FeedListRemoveEntityWithChildren => write!(f, "remove selected and its children"),
            FeedListFeedChangeUrl(Some(url)) => write!(f, "change url of selected feed to {url}"),
            FeedListFeedChangeUrl(None) => unreachable!(),
            FeedListYankFeedOrCategory => write!(f, "yank selected feed or category"),
            FeedListPasteFeedOrCategory(position) => {
                write!(
                    f,
                    "paste yanked feed or category {position} selected element"
                )
            }
            FeedListTagChangeColor(color) => {
                write!(f, "change color of tag to {}", color)
            }
            FeedListSort => write!(f, "sort feed list alphabetically"),
            SelectNextUnread => write!(f, "select next unread"),
            Show(ArticleScope::Marked) => write!(f, "show only marked"),
            Show(ArticleScope::Unread) => write!(f, "show only unread"),
            Show(ArticleScope::All) => write!(f, "show all"),
            ArticleOpenEnclosure(None) => write!(f, "open default enclosure"),
            ArticleOpenEnclosure(Some(enclosure_type)) => {
                write!(f, "open {enclosure_type} enclosure")
            }
            ArticleShare(share_target) => write!(f, "share article to {share_target}"),

            ArticleCurrentScrape => write!(f, "scrape content"),

            ImportOpml(path) => write!(f, "import OPML file from {path}"),
            ExportOpml(path) => write!(f, "export OPML file to {path}"),

            ApplicationQuit => write!(f, "quit application"),
            Redraw => write!(f, "redraw UI"),
            Refresh => write!(f, "refresh UI"),
            CommandLineOpen(input) => write!(f, ":{}", input.unwrap_or_default()),
            ArticleListSearch(query) => {
                write!(f, "search article by query: {}", query.query_string())
            }
            SearchNext => write!(f, "article search next"),
            SearchPrevious => write!(f, "article search previous"),
            Search(Some(search_term)) => write!(f, "search for {search_term}"),
            Search(None) => write!(f, "clear search"),
            ArticleListFilterSet(query) => {
                write!(
                    f,
                    "filter current article list by query: {}",
                    query.query_string()
                )
            }
            ArticleListFilterSetSticky(query) => {
                write!(
                    f,
                    "always filter article list by query: {}",
                    query.query_string()
                )
            }
            ArticleListQuery(query) => {
                write!(f, "query all articles by: {}", query.query_string())
            }
            ArticleListFilterApply => write!(f, "apply current article filter"),
            ArticleListFilterClear => write!(f, "clear article filter"),
            ArticleListSort(sort_order) => write!(f, "sort article list by {}", sort_order),
            ArticleListSortReverse => write!(f, "reverse current sort order"),
            ArticleListSortClear => write!(f, "clear current sort order"),
            ContentFollowHint(hint) => write!(f, "open URL behind {hint}"),
            ContentShareHint(target, hint) => write!(f, "share URL behind {hint} to {target}"),

            FeedListSync => write!(f, "sync all"),
            ActionSetRead(action_scope) => {
                write!(f, "mark {action_scope} as read",)
            }
            ActionSetUnread(action_scope) => write!(f, "mark {} as unread", action_scope),
            ActionSetMarked(action_scope) => write!(f, "mark {}", action_scope),
            ActionSetUnmarked(action_scope) => write!(f, "unmark {}", action_scope),
            ActionSetFlagged(action_scope) => write!(f, "flag {}", action_scope),
            ActionSetUnflagged(action_scope) => write!(f, "unflag {}", action_scope),
            ActionFlagInvert(action_scope) => write!(f, "invert flags {}", action_scope),
            ActionOpenInBrowser(action_scope) => write!(f, "open {} in browser", action_scope),
            ActionTagArticles(action_scope, tag) => {
                write!(f, "add #{} to {}", tag, &action_scope)
            }
            ActionUntagArticles(action_scope, tag) => {
                write!(f, "remove #{} from {}", tag, &action_scope)
            }
            Logout(_) => write!(
                f,
                "logout from provider, NOTE: this will remove ALL LOCAL DATA!"
            ),
            HelpInput => write!(f, "show help on input mappings"),
            TagAdd(tag_title, _) => {
                write!(f, "add tag #{}", tag_title)
            }
            CommandConfirm(command) => write!(f, "{}?", command),
            In(panel, command) => write!(f, "{command} in {panel}"),
        }
    }
}

impl Command {
    pub(crate) fn is_async(&self) -> bool {
        use Command as C;
        match self {
            C::FeedListSync
            | C::FeedListCategoryAdd(..)
            | C::FeedListFeedAdd(..)
            | C::FeedListTagChangeColor(..)
            | C::FeedListRenameEntity(..)
            | C::FeedListRemoveEntity
            | C::FeedListRemoveEntityWithChildren
            | C::FeedListFeedChangeUrl(..)
            | C::FeedListPasteFeedOrCategory(..)
            | C::TagAdd(..)
            | C::ImportOpml(..)
            | C::ExportOpml(..)
            | C::Logout(..) => true,
            C::CommandConfirm(command) => command.is_async(),
            C::In(_, command) => command.is_async(),
            _ => false,
        }
    }
}

#[derive(Clone, Debug, serde::Deserialize, Default)]
#[serde(transparent)]
pub struct CommandSequence {
    pub commands: Vec<Command>,
}

impl From<Command> for CommandSequence {
    fn from(single_command: Command) -> Self {
        Self {
            commands: vec![single_command],
        }
    }
}

impl From<Vec<Command>> for CommandSequence {
    fn from(commands: Vec<Command>) -> Self {
        Self { commands }
    }
}

impl<const N: usize> From<[Command; N]> for CommandSequence {
    fn from(value: [Command; N]) -> Self {
        value.into_iter().collect::<Vec<Command>>().into()
    }
}

impl<const N: usize> From<[&str; N]> for CommandSequence {
    fn from(value: [&str; N]) -> Self {
        value
            .iter()
            .map(|s| Command::from_str(s).unwrap()) // <- if this fails it should fail hard
            .collect::<Vec<Command>>()
            .into()
    }
}

impl From<&str> for CommandSequence {
    fn from(value: &str) -> Self {
        Command::from_str(value).unwrap().into() // <- if this fails it should fail hard
    }
}

impl Display for CommandSequence {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let mut first = true;
        for command in self.commands.iter() {
            if !first {
                f.write_str(",")?;
            }
            command.fmt(f)?;

            first = false;
        }

        Ok(())
    }
}