0e7b670acd51476661878f4d1d6eb4cecc2f759b
[apps/madmutt.git] / lib-ui / curses.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 2004 g10 Code GmbH
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10 #ifndef _MUTT_CURSES_H
11 #define _MUTT_CURSES_H
12
13 #include <lib-lib/lib-lib.h>
14 #include "mutt.h"
15
16 #ifdef USE_SLANG_CURSES
17
18 #ifndef unix                    /* this symbol is not defined by the hp-ux compiler (sigh) */
19 #define unix
20 #endif /* unix */
21
22 #include "slcurses.h"
23
24 #define KEY_DC SL_KEY_DELETE
25 #define KEY_IC SL_KEY_IC
26
27 /*
28  * ncurses and SLang seem to send different characters when the Enter key is
29  * pressed, so define some macros to properly detect the Enter key.
30  */
31 #define M_ENTER_C '\r'
32 #define M_ENTER_S "\r"
33
34 #else
35
36 #ifdef HAVE_NCURSESW_NCURSES_H
37 #include <ncursesw/ncurses.h>
38 #else
39 #ifdef HAVE_NCURSES_NCURSES_H
40 #include <ncurses/ncurses.h>
41 #else
42 #ifdef HAVE_NCURSES_H
43 #include <ncurses.h>
44 #else
45 #include <curses.h>
46 #endif
47 #endif
48 #endif
49
50 #define M_ENTER_C '\n'
51 #define M_ENTER_S "\n"
52
53 #endif /* USE_SLANG_CURSES */
54
55 /* AIX defines ``lines'' in <term.h>, but it's used as a var name in
56  * various places in Mutt
57  */
58 #ifdef lines
59 #undef lines
60 #endif /* lines */
61
62 #define CLEARLINE_WIN(x) move(x,(option(OPTMBOXPANE)?SidebarWidth:0)), clrtoeol()
63 #define CLEARLINE(x) move(x,0), clrtoeol()
64 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
65 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
66
67 #if ! (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
68 #define curs_set(x)
69 #endif
70
71 #if !defined(USE_SLANG_CURSES) && defined(HAVE_BKGDSET)
72 #define BKGDSET(x) bkgdset (ColorDefs[x] | ' ')
73 #else
74 #define BKGDSET(x)
75 #endif
76
77 #if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
78 void mutt_curs_set (int);
79 #else
80 #define mutt_curs_set(x)
81 #endif
82 #define PAGELEN (LINES-3)
83
84 #define ctrl(c) ((c)-'@')
85
86 #ifdef KEY_ENTER
87 #define CI_is_return(c) ((c) == '\r' || (c) == '\n' || (c) == KEY_ENTER)
88 #else
89 #define CI_is_return(c) ((c) == '\r' || (c) == '\n')
90 #endif
91
92 event_t mutt_getch (void);
93
94 void mutt_endwin (const char *);
95 void mutt_flushinp (void);
96 void mutt_refresh (void);
97 void mutt_resize_screen (void);
98 void mutt_ungetch (int, int);
99 void mutt_need_hard_redraw (void);
100
101 /* ----------------------------------------------------------------------------
102  * Support for color
103  */
104
105 enum {
106   MT_COLOR_HDEFAULT = 0,
107   MT_COLOR_QUOTED,
108   MT_COLOR_SIGNATURE,
109   MT_COLOR_INDICATOR,
110   MT_COLOR_STATUS,
111   MT_COLOR_TREE,
112   MT_COLOR_NORMAL,
113   MT_COLOR_ERROR,
114   MT_COLOR_TILDE,
115   MT_COLOR_MARKERS,
116   MT_COLOR_BODY,
117   MT_COLOR_HEADER,
118   MT_COLOR_MESSAGE,
119   MT_COLOR_ATTACHMENT,
120   MT_COLOR_SEARCH,
121   MT_COLOR_BOLD,
122   MT_COLOR_SIDEBAR,
123   MT_COLOR_UNDERLINE,
124   MT_COLOR_INDEX,
125   MT_COLOR_NEW,
126   MT_COLOR_FLAGGED,
127   MT_COLOR_MAX
128 };
129
130 typedef struct color_line {
131   regex_t rx;
132   char *pattern;
133   pattern_t *color_pattern;     /* compiled pattern to speed up index color
134                                    calculation */
135   short fg;
136   short bg;
137   int pair;
138   struct color_line *next;
139 } COLOR_LINE;
140
141 typedef struct {
142   const char* msg;
143   long pos;
144   long size;
145   char sizestr[SHORT_STRING];
146 } progress_t;
147
148 void mutt_progress_bar (progress_t* progress, long pos);
149 void mutt_clear_error (void);
150 void mutt_edit_file (const char *, const char *);
151 void mutt_curses_error (const char *, ...);
152 void mutt_curses_message (const char *, ...);
153 void mutt_format_string (char *, ssize_t, int, int, int, char, const char *,
154                          ssize_t, int);
155 void mutt_format_s (char *, ssize_t, const char *, const char *);
156 void mutt_format_s_tree (char *, ssize_t, const char *, const char *);
157 void mutt_free_color (int fg, int bg);
158 void mutt_paddstr (int, const char *);
159 #define mutt_perror(a) _mutt_perror (a, __FILE__, __LINE__)
160 void _mutt_perror (const char*, const char*,int);
161 void mutt_query_exit (void);
162 void mutt_query_menu (char *, ssize_t);
163 void mutt_show_error (void);
164 ssize_t mutt_pretty_size(char *s, ssize_t len, ssize_t n);
165
166 int mutt_addwch (wchar_t);
167 int mutt_alloc_color (int fg, int bg);
168 int mutt_any_key_to_continue (const char *);
169 int mutt_complete (char *, ssize_t);
170 #define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL)
171 int _mutt_enter_fname (const char *, char *, ssize_t, int *, int, int,
172                        char ***, int *);
173
174 #define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL)
175 int _mutt_get_field (const char *, char *, ssize_t, int, int, char ***, int *);
176 int mutt_get_field_unbuffered (char *, char *, ssize_t, int);
177 int mutt_index_menu (void);
178 int mutt_is_mail_list (address_t *);
179 int mutt_is_subscribed_list (address_t *);
180 int mutt_multi_choice (char *prompt, char *letters);
181 int mutt_parse_color (BUFFER *, BUFFER *, unsigned long, BUFFER *);
182 int mutt_parse_uncolor (BUFFER *, BUFFER *, unsigned long, BUFFER *);
183 int mutt_parse_mono (BUFFER *, BUFFER *, unsigned long, BUFFER *);
184 int mutt_parse_unmono (BUFFER *, BUFFER *, unsigned long, BUFFER *);
185 int mutt_query_complete (char *, ssize_t);
186 int mutt_strwidth (const char *);
187 int mutt_user_is_recipient (HEADER *);
188 int mutt_yesorno (const char *, int);
189 void mutt_set_header_color (CONTEXT *, HEADER *);
190
191 extern int *ColorQuote;
192 extern int ColorQuoteUsed;
193 extern int ColorDefs[];
194 extern COLOR_LINE *ColorHdrList;
195 extern COLOR_LINE *ColorBodyList;
196 extern COLOR_LINE *ColorIndexList;
197
198 void ci_init_color (void);
199 void ci_start_color (void);
200
201 #define mutt_make_string(A,B,C,D,E) _mutt_make_string(A,B,C,D,E,0)
202 void _mutt_make_string (char *, ssize_t, const char *, CONTEXT *,
203                         HEADER *, format_flag);
204
205
206 #define SETCOLOR(X) attrset(ColorDefs[X])
207 #define ADDCOLOR(X) attron(ColorDefs[X])
208
209 #define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); x = REDRAW_FULL; }
210
211 #endif /* !_MUTT_CURSES_H */