forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
1619 lines (1465 loc) · 38.2 KB
/
menu.c
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
/**
* @file
* GUI present the user with a selectable list
*
* @authors
* Copyright (C) 1996-2000,2002,2012 Michael R. Elkins <me@mutt.org>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @page menu GUI present the user with a selectable list
*
* GUI present the user with a selectable list
*/
#include "config.h"
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include "mutt/mutt.h"
#include "email/lib.h"
#include "mutt.h"
#include "color.h"
#include "commands.h"
#include "context.h"
#include "curs_lib.h"
#include "globals.h"
#include "keymap.h"
#include "mailbox.h"
#include "mutt_curses.h"
#include "mutt_logging.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "pattern.h"
#include "protos.h"
#ifdef USE_SIDEBAR
#include "sidebar.h"
#endif
/* These Config Variables are only used in menu.c */
short C_MenuContext; ///< Config: Number of lines of overlap when changing pages in the index
bool C_MenuMoveOff; ///< Config: Allow the last menu item to move off the bottom of the screen
bool C_MenuScroll; ///< Config: Scroll the menu/index by one line, rather than a page
char *SearchBuffers[MENU_MAX];
/* These are used to track the active menus, for redraw operations. */
static size_t MenuStackCount = 0;
static size_t MenuStackLen = 0;
static struct Menu **MenuStack = NULL;
#define DIRECTION ((neg * 2) + 1)
#define MUTT_SEARCH_UP 1
#define MUTT_SEARCH_DOWN 2
/**
* get_color - Choose a colour for a line of the index
* @param index Index number
* @param s String of embedded colour codes
* @retval num Colour pair in an integer
*
* Text is coloured by inserting special characters into the string, e.g.
* #MT_COLOR_INDEX_AUTHOR
*/
static int get_color(int index, unsigned char *s)
{
struct ColorLineHead *color = NULL;
struct ColorLine *np = NULL;
struct Email *e = Context->mailbox->emails[Context->mailbox->v2r[index]];
int type = *s;
switch (type)
{
case MT_COLOR_INDEX_AUTHOR:
color = &ColorIndexAuthorList;
break;
case MT_COLOR_INDEX_FLAGS:
color = &ColorIndexFlagsList;
break;
case MT_COLOR_INDEX_SUBJECT:
color = &ColorIndexSubjectList;
break;
case MT_COLOR_INDEX_TAG:
STAILQ_FOREACH(np, &ColorIndexTagList, entries)
{
if (strncmp((const char *) (s + 1), np->pattern, strlen(np->pattern)) == 0)
return np->pair;
const char *transform = mutt_hash_find(TagTransforms, np->pattern);
if (transform &&
(strncmp((const char *) (s + 1), transform, strlen(transform)) == 0))
{
return np->pair;
}
}
return 0;
default:
return ColorDefs[type];
}
STAILQ_FOREACH(np, color, entries)
{
if (mutt_pattern_exec(SLIST_FIRST(np->color_pattern),
MUTT_MATCH_FULL_ADDRESS, Context->mailbox, e, NULL))
return np->pair;
}
return 0;
}
/**
* print_enriched_string - Display a string with embedded colours and graphics
* @param index Index number
* @param attr Default colour for the line
* @param s String of embedded colour codes
* @param do_color If true, apply colour
*/
static void print_enriched_string(int index, int attr, unsigned char *s, bool do_color)
{
wchar_t wc;
size_t k;
size_t n = mutt_str_strlen((char *) s);
mbstate_t mbstate;
if (!stdscr)
return;
memset(&mbstate, 0, sizeof(mbstate));
while (*s)
{
if (*s < MUTT_TREE_MAX)
{
if (do_color)
#if defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS)
/* Combining tree fg color and another bg color requires
* having use_default_colors, because the other bg color
* may be undefined. */
ATTRSET(mutt_combine_color(ColorDefs[MT_COLOR_TREE], attr));
#else
SETCOLOR(MT_COLOR_TREE);
#endif
while (*s && *s < MUTT_TREE_MAX)
{
switch (*s)
{
case MUTT_TREE_LLCORNER:
if (C_AsciiChars)
addch('`');
#ifdef WACS_LLCORNER
else
add_wch(WACS_LLCORNER);
#else
else if (CharsetIsUtf8)
addstr("\342\224\224"); /* WACS_LLCORNER */
else
addch(ACS_LLCORNER);
#endif
break;
case MUTT_TREE_ULCORNER:
if (C_AsciiChars)
addch(',');
#ifdef WACS_ULCORNER
else
add_wch(WACS_ULCORNER);
#else
else if (CharsetIsUtf8)
addstr("\342\224\214"); /* WACS_ULCORNER */
else
addch(ACS_ULCORNER);
#endif
break;
case MUTT_TREE_LTEE:
if (C_AsciiChars)
addch('|');
#ifdef WACS_LTEE
else
add_wch(WACS_LTEE);
#else
else if (CharsetIsUtf8)
addstr("\342\224\234"); /* WACS_LTEE */
else
addch(ACS_LTEE);
#endif
break;
case MUTT_TREE_HLINE:
if (C_AsciiChars)
addch('-');
#ifdef WACS_HLINE
else
add_wch(WACS_HLINE);
#else
else if (CharsetIsUtf8)
addstr("\342\224\200"); /* WACS_HLINE */
else
addch(ACS_HLINE);
#endif
break;
case MUTT_TREE_VLINE:
if (C_AsciiChars)
addch('|');
#ifdef WACS_VLINE
else
add_wch(WACS_VLINE);
#else
else if (CharsetIsUtf8)
addstr("\342\224\202"); /* WACS_VLINE */
else
addch(ACS_VLINE);
#endif
break;
case MUTT_TREE_TTEE:
if (C_AsciiChars)
addch('-');
#ifdef WACS_TTEE
else
add_wch(WACS_TTEE);
#else
else if (CharsetIsUtf8)
addstr("\342\224\254"); /* WACS_TTEE */
else
addch(ACS_TTEE);
#endif
break;
case MUTT_TREE_BTEE:
if (C_AsciiChars)
addch('-');
#ifdef WACS_BTEE
else
add_wch(WACS_BTEE);
#else
else if (CharsetIsUtf8)
addstr("\342\224\264"); /* WACS_BTEE */
else
addch(ACS_BTEE);
#endif
break;
case MUTT_TREE_SPACE:
addch(' ');
break;
case MUTT_TREE_RARROW:
addch('>');
break;
case MUTT_TREE_STAR:
addch('*'); /* fake thread indicator */
break;
case MUTT_TREE_HIDDEN:
addch('&');
break;
case MUTT_TREE_EQUALS:
addch('=');
break;
case MUTT_TREE_MISSING:
addch('?');
break;
}
s++;
n--;
}
if (do_color)
ATTRSET(attr);
}
else if (*s == MUTT_SPECIAL_INDEX)
{
s++;
if (do_color)
{
if (*s == MT_COLOR_INDEX)
{
attrset(attr);
}
else
{
if (get_color(index, s) == 0)
{
attron(attr);
}
else
{
attron(get_color(index, s));
}
}
}
s++;
n -= 2;
}
else if ((k = mbrtowc(&wc, (char *) s, n, &mbstate)) > 0)
{
addnstr((char *) s, k);
s += k;
n -= k;
}
else
break;
}
}
/**
* menu_make_entry - Create string to display in a Menu (the index)
* @param buf Buffer for the result
* @param buflen Length of the buffer
* @param menu Current Menu
* @param i Selected item
*/
static void menu_make_entry(char *buf, size_t buflen, struct Menu *menu, int i)
{
if (menu->dialog)
{
mutt_str_strfcpy(buf, menu->dialog[i], buflen);
menu->current = -1; /* hide menubar */
}
else
menu->menu_make_entry(buf, buflen, menu, i);
}
/**
* menu_pad_string - Pad a string with spaces for display in the Menu
* @param menu Current Menu
* @param buf Buffer containing the string
* @param buflen Length of the buffer
*
* @note The string is padded in-place.
*/
static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen)
{
char *scratch = mutt_str_strdup(buf);
int shift = C_ArrowCursor ? 3 : 0;
int cols = menu->indexwin->cols - shift;
mutt_simple_format(buf, buflen, cols, cols, FMT_LEFT, ' ', scratch,
mutt_str_strlen(scratch), 1);
buf[buflen - 1] = '\0';
FREE(&scratch);
}
/**
* menu_redraw_full - Force the redraw of the Menu
* @param menu Current Menu
*/
void menu_redraw_full(struct Menu *menu)
{
mutt_window_reflow();
NORMAL_COLOR;
/* clear() doesn't optimize screen redraws */
move(0, 0);
clrtobot();
if (C_Help)
{
SETCOLOR(MT_COLOR_STATUS);
mutt_window_move(menu->helpwin, 0, 0);
mutt_paddstr(menu->helpwin->cols, menu->help);
NORMAL_COLOR;
}
menu->offset = 0;
menu->pagelen = menu->indexwin->rows;
mutt_show_error();
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
#ifdef USE_SIDEBAR
menu->redraw |= REDRAW_SIDEBAR;
#endif
}
/**
* menu_redraw_status - Force the redraw of the status bar
* @param menu Current Menu
*/
void menu_redraw_status(struct Menu *menu)
{
char buf[256];
snprintf(buf, sizeof(buf), "-- NeoMutt: %s", menu->title);
SETCOLOR(MT_COLOR_STATUS);
mutt_window_move(menu->statuswin, 0, 0);
mutt_paddstr(menu->statuswin->cols, buf);
NORMAL_COLOR;
menu->redraw &= ~REDRAW_STATUS;
}
#ifdef USE_SIDEBAR
/**
* menu_redraw_sidebar - Force the redraw of the sidebar
* @param menu Current Menu
*/
void menu_redraw_sidebar(struct Menu *menu)
{
menu->redraw &= ~REDRAW_SIDEBAR;
mutt_sb_draw();
}
#endif
/**
* menu_redraw_index - Force the redraw of the index
* @param menu Current Menu
*/
void menu_redraw_index(struct Menu *menu)
{
char buf[1024];
bool do_color;
int attr;
for (int i = menu->top; i < menu->top + menu->pagelen; i++)
{
if (i < menu->max)
{
attr = menu->menu_color(i);
menu_make_entry(buf, sizeof(buf), menu, i);
menu_pad_string(menu, buf, sizeof(buf));
ATTRSET(attr);
mutt_window_move(menu->indexwin, i - menu->top + menu->offset, 0);
do_color = true;
if (i == menu->current)
{
SETCOLOR(MT_COLOR_INDICATOR);
if (C_ArrowCursor)
{
addstr("->");
ATTRSET(attr);
addch(' ');
}
else
do_color = false;
}
else if (C_ArrowCursor)
addstr(" ");
print_enriched_string(i, attr, (unsigned char *) buf, do_color);
}
else
{
NORMAL_COLOR;
mutt_window_clearline(menu->indexwin, i - menu->top + menu->offset);
}
}
NORMAL_COLOR;
menu->redraw = 0;
}
/**
* menu_redraw_motion - Force the redraw of the list part of the menu
* @param menu Current Menu
*/
void menu_redraw_motion(struct Menu *menu)
{
char buf[1024];
if (menu->dialog)
{
menu->redraw &= ~REDRAW_MOTION;
return;
}
/* Note: menu->color() for the index can end up retrieving a message
* over imap (if matching against ~h for instance). This can
* generate status messages. So we want to call it *before* we
* position the cursor for drawing. */
const int old_color = menu->menu_color(menu->oldcurrent);
mutt_window_move(menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 0);
ATTRSET(old_color);
if (C_ArrowCursor)
{
/* clear the pointer */
addstr(" ");
if (menu->redraw & REDRAW_MOTION_RESYNC)
{
menu_make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
menu_pad_string(menu, buf, sizeof(buf));
mutt_window_move(menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 3);
print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, 1);
}
/* now draw it in the new location */
SETCOLOR(MT_COLOR_INDICATOR);
mutt_window_mvaddstr(menu->indexwin, menu->current + menu->offset - menu->top, 0, "->");
}
else
{
/* erase the current indicator */
menu_make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
menu_pad_string(menu, buf, sizeof(buf));
print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, 1);
/* now draw the new one to reflect the change */
const int cur_color = menu->menu_color(menu->current);
menu_make_entry(buf, sizeof(buf), menu, menu->current);
menu_pad_string(menu, buf, sizeof(buf));
SETCOLOR(MT_COLOR_INDICATOR);
mutt_window_move(menu->indexwin, menu->current + menu->offset - menu->top, 0);
print_enriched_string(menu->current, cur_color, (unsigned char *) buf, 0);
}
menu->redraw &= REDRAW_STATUS;
NORMAL_COLOR;
}
/**
* menu_redraw_current - Redraw the current menu
* @param menu Current Menu
*/
void menu_redraw_current(struct Menu *menu)
{
char buf[1024];
int attr = menu->menu_color(menu->current);
mutt_window_move(menu->indexwin, menu->current + menu->offset - menu->top, 0);
menu_make_entry(buf, sizeof(buf), menu, menu->current);
menu_pad_string(menu, buf, sizeof(buf));
SETCOLOR(MT_COLOR_INDICATOR);
if (C_ArrowCursor)
{
addstr("->");
ATTRSET(attr);
addch(' ');
menu_pad_string(menu, buf, sizeof(buf));
print_enriched_string(menu->current, attr, (unsigned char *) buf, 1);
}
else
print_enriched_string(menu->current, attr, (unsigned char *) buf, 0);
menu->redraw &= REDRAW_STATUS;
NORMAL_COLOR;
}
/**
* menu_redraw_prompt - Force the redraw of the message window
* @param menu Current Menu
*/
static void menu_redraw_prompt(struct Menu *menu)
{
if (!menu || !menu->dialog)
return;
if (OptMsgErr)
{
mutt_sleep(1);
OptMsgErr = false;
}
if (ErrorBufMessage)
mutt_clear_error();
mutt_window_mvaddstr(menu->messagewin, 0, 0, menu->prompt);
mutt_window_clrtoeol(menu->messagewin);
}
/**
* menu_check_recenter - Recentre the menu on screen
* @param menu Current Menu
*/
void menu_check_recenter(struct Menu *menu)
{
int c = MIN(C_MenuContext, menu->pagelen / 2);
int old_top = menu->top;
if (!C_MenuMoveOff && (menu->max <= menu->pagelen)) /* less entries than lines */
{
if (menu->top != 0)
{
menu->top = 0;
menu->redraw |= REDRAW_INDEX;
}
}
else
{
if (C_MenuScroll || (menu->pagelen <= 0) || (c < C_MenuContext))
{
if (menu->current < menu->top + c)
menu->top = menu->current - c;
else if (menu->current >= menu->top + menu->pagelen - c)
menu->top = menu->current - menu->pagelen + c + 1;
}
else
{
if (menu->current < menu->top + c)
{
menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) /
(menu->pagelen - c)) -
c;
}
else if ((menu->current >= menu->top + menu->pagelen - c))
{
menu->top +=
(menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c;
}
}
}
if (!C_MenuMoveOff) /* make entries stick to bottom */
menu->top = MIN(menu->top, menu->max - menu->pagelen);
menu->top = MAX(menu->top, 0);
if (menu->top != old_top)
menu->redraw |= REDRAW_INDEX;
}
/**
* menu_jump - Jump to another item in the menu
* @param menu Current Menu
*
* Ask the user for a message number to jump to.
*/
static void menu_jump(struct Menu *menu)
{
int n;
if (menu->max)
{
mutt_unget_event(LastKey, 0);
char buf[128];
buf[0] = '\0';
if ((mutt_get_field(_("Jump to: "), buf, sizeof(buf), 0) == 0) && buf[0])
{
if ((mutt_str_atoi(buf, &n) == 0) && (n > 0) && (n < menu->max + 1))
{
n--; /* msg numbers are 0-based */
menu->current = n;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error(_("Invalid index number"));
}
}
else
mutt_error(_("No entries"));
}
/**
* menu_next_line - Move the view down one line, keeping the selection the same
* @param menu Current Menu
*/
void menu_next_line(struct Menu *menu)
{
if (menu->max)
{
int c = MIN(C_MenuContext, menu->pagelen / 2);
if ((menu->top + 1 < menu->max - c) &&
(C_MenuMoveOff ||
((menu->max > menu->pagelen) && (menu->top < menu->max - menu->pagelen))))
{
menu->top++;
if ((menu->current < menu->top + c) && (menu->current < menu->max - 1))
menu->current++;
menu->redraw = REDRAW_INDEX;
}
else
mutt_error(_("You cannot scroll down farther"));
}
else
mutt_error(_("No entries"));
}
/**
* menu_prev_line - Move the view up one line, keeping the selection the same
* @param menu Current Menu
*/
void menu_prev_line(struct Menu *menu)
{
if (menu->top > 0)
{
int c = MIN(C_MenuContext, menu->pagelen / 2);
menu->top--;
if ((menu->current >= menu->top + menu->pagelen - c) && (menu->current > 1))
menu->current--;
menu->redraw = REDRAW_INDEX;
}
else
mutt_error(_("You cannot scroll up farther"));
}
/**
* menu_length_jump - Calculate the destination of a jump
* @param menu Current Menu
* @param jumplen Number of lines to jump
*
* * pageup: jumplen == -pagelen
* * pagedown: jumplen == pagelen
* * halfup: jumplen == -pagelen/2
* * halfdown: jumplen == pagelen/2
*/
static void menu_length_jump(struct Menu *menu, int jumplen)
{
const int neg = (jumplen >= 0) ? 0 : -1;
const int c = MIN(C_MenuContext, menu->pagelen / 2);
if (menu->max)
{
/* possible to scroll? */
int tmp;
if (DIRECTION * menu->top <
(tmp = (neg ? 0 : (menu->max /* -1 */) - (menu->pagelen /* -1 */))))
{
menu->top += jumplen;
/* jumped too long? */
if ((neg || !C_MenuMoveOff) && (DIRECTION * menu->top > tmp))
menu->top = tmp;
/* need to move the cursor? */
if ((DIRECTION *
(tmp = (menu->current - (menu->top + (neg ? (menu->pagelen - 1) - c : c))))) < 0)
{
menu->current -= tmp;
}
menu->redraw = REDRAW_INDEX;
}
else if ((menu->current != (neg ? 0 : menu->max - 1)) && !menu->dialog)
{
menu->current += jumplen;
menu->redraw = REDRAW_MOTION;
}
else
{
mutt_error(neg ? _("You are on the first page") : _("You are on the last page"));
}
menu->current = MIN(menu->current, menu->max - 1);
menu->current = MAX(menu->current, 0);
}
else
mutt_error(_("No entries"));
}
/**
* menu_next_page - Move the focus to the next page in the menu
* @param menu Current Menu
*/
void menu_next_page(struct Menu *menu)
{
menu_length_jump(menu, MAX(menu->pagelen /* - MenuOverlap */, 0));
}
/**
* menu_prev_page - Move the focus to the previous page in the menu
* @param menu Current Menu
*/
void menu_prev_page(struct Menu *menu)
{
menu_length_jump(menu, 0 - MAX(menu->pagelen /* - MenuOverlap */, 0));
}
/**
* menu_half_down - Move the focus down half a page in the menu
* @param menu Current Menu
*/
void menu_half_down(struct Menu *menu)
{
menu_length_jump(menu, menu->pagelen / 2);
}
/**
* menu_half_up - Move the focus up half a page in the menu
* @param menu Current Menu
*/
void menu_half_up(struct Menu *menu)
{
menu_length_jump(menu, 0 - menu->pagelen / 2);
}
/**
* menu_top_page - Move the focus to the top of the page
* @param menu Current Menu
*/
void menu_top_page(struct Menu *menu)
{
if (menu->current == menu->top)
return;
menu->current = menu->top;
menu->redraw = REDRAW_MOTION;
}
/**
* menu_bottom_page - Move the focus to the bottom of the page
* @param menu Current Menu
*/
void menu_bottom_page(struct Menu *menu)
{
if (menu->max)
{
menu->current = menu->top + menu->pagelen - 1;
if (menu->current > menu->max - 1)
menu->current = menu->max - 1;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error(_("No entries"));
}
/**
* menu_middle_page - Move the focus to the centre of the page
* @param menu Current Menu
*/
void menu_middle_page(struct Menu *menu)
{
if (menu->max)
{
int i = menu->top + menu->pagelen;
if (i > menu->max - 1)
i = menu->max - 1;
menu->current = menu->top + (i - menu->top) / 2;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error(_("No entries"));
}
/**
* menu_first_entry - Move the focus to the first entry in the menu
* @param menu Current Menu
*/
void menu_first_entry(struct Menu *menu)
{
if (menu->max)
{
menu->current = 0;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error(_("No entries"));
}
/**
* menu_last_entry - Move the focus to the last entry in the menu
* @param menu Current Menu
*/
void menu_last_entry(struct Menu *menu)
{
if (menu->max)
{
menu->current = menu->max - 1;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error(_("No entries"));
}
/**
* menu_current_top - Move the current selection to the top of the window
* @param menu Current Menu
*/
void menu_current_top(struct Menu *menu)
{
if (menu->max)
{
menu->top = menu->current;
menu->redraw = REDRAW_INDEX;
}
else
mutt_error(_("No entries"));
}
/**
* menu_current_middle - Move the current selection to the centre of the window
* @param menu Current Menu
*/
void menu_current_middle(struct Menu *menu)
{
if (menu->max)
{
menu->top = menu->current - menu->pagelen / 2;
if (menu->top < 0)
menu->top = 0;
menu->redraw = REDRAW_INDEX;
}
else
mutt_error(_("No entries"));
}
/**
* menu_current_bottom - Move the current selection to the bottom of the window
* @param menu Current Menu
*/
void menu_current_bottom(struct Menu *menu)
{
if (menu->max)
{
menu->top = menu->current - menu->pagelen + 1;
if (menu->top < 0)
menu->top = 0;
menu->redraw = REDRAW_INDEX;
}
else
mutt_error(_("No entries"));
}
/**
* menu_next_entry - Move the focus to the next item in the menu
* @param menu Current Menu
*/
static void menu_next_entry(struct Menu *menu)
{
if (menu->current < menu->max - 1)
{
menu->current++;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error(_("You are on the last entry"));
}
/**
* menu_prev_entry - Move the focus to the previous item in the menu
* @param menu Current Menu
*/
static void menu_prev_entry(struct Menu *menu)
{
if (menu->current)
{
menu->current--;
menu->redraw = REDRAW_MOTION;
}
else
mutt_error(_("You are on the first entry"));
}
/**
* default_color - Get the default colour for a line of the menu - Implements Menu::menu_color()
*/
static int default_color(int line)
{
return ColorDefs[MT_COLOR_NORMAL];
}
/**
* generic_search - Search a menu for a item matching a regex - Implements Menu::menu_search()
*/
static int generic_search(struct Menu *menu, regex_t *rx, int line)
{
char buf[1024];
menu_make_entry(buf, sizeof(buf), menu, line);
return regexec(rx, buf, 0, NULL, 0);
}
/**
* mutt_menu_init - Initialise all the Menus
*/
void mutt_menu_init(void)
{
for (int i = 0; i < MENU_MAX; i++)
SearchBuffers[i] = NULL;
}
/**
* mutt_menu_new - Create a new Menu
* @param type Menu type, e.g. #MENU_PAGER
* @retval ptr New Menu
*/
struct Menu *mutt_menu_new(enum MenuType type)
{
struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
if (type >= MENU_MAX)
type = MENU_GENERIC;
menu->menu = type;
menu->current = 0;
menu->top = 0;
menu->offset = 0;
menu->redraw = REDRAW_FULL;
menu->pagelen = MuttIndexWindow->rows;
menu->indexwin = MuttIndexWindow;
menu->statuswin = MuttStatusWindow;
menu->helpwin = MuttHelpWindow;
menu->messagewin = MuttMessageWindow;
menu->menu_color = default_color;
menu->menu_search = generic_search;
return menu;
}
/**
* mutt_menu_destroy - Destroy a menu