Move more things about stdscr in lib-ui.
[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 #if defined(HAVE_NCURSESW_NCURSES_H)
17 #include <ncursesw/ncurses.h>
18 #elif defined(HAVE_NCURSES_NCURSES_H)
19 #include <ncurses/ncurses.h>
20 #elif defined(HAVE_NCURSES_H)
21 #include <ncurses.h>
22 #else
23 #include <curses.h>
24 #endif
25
26 /* AIX defines ``lines'' in <term.h>, but it's used as a var name in
27  * various places in Mutt
28  */
29 #ifdef lines
30 #undef lines
31 #endif /* lines */
32
33 #define CLEARLINE_WIN(x) wmove(stdscr, x,(option(OPTMBOXPANE)?SidebarWidth:0)), wclrtoeol(stdscr)
34 #define CLEARLINE(x) wmove(stdscr, x,0), wclrtoeol(stdscr)
35 #define CENTERLINE(x,y) wmove(stdscr, y, (COLS-strlen(x))/2), waddstr(stdscr, x)
36 #define BEEP() do { if (mod_core.beep) beep(); } while (0)
37
38 #define BKGDSET(x)  wbkgdset(stdscr, ColorDefs[x] | ' ')
39
40 void mutt_curs_set (int);
41 #define PAGELEN (LINES-3)
42
43 #define ctrl(c) ((c)-'@')
44
45 #ifdef KEY_ENTER
46 #define CI_is_return(c) ((c) == '\r' || (c) == '\n' || (c) == KEY_ENTER)
47 #else
48 #define CI_is_return(c) ((c) == '\r' || (c) == '\n')
49 #endif
50
51 event_t mutt_getch (void);
52
53 void curses_initialize(void);
54 void curses_install(void);
55
56 void mutt_endwin (const char *);
57 void mutt_flushinp (void);
58 void mutt_refresh (void);
59 void mutt_resize_screen (void);
60 void mutt_ungetch (int, int);
61 void mutt_need_hard_redraw (void);
62
63 /* ----------------------------------------------------------------------------
64  * Support for color
65  */
66
67 enum {
68   MT_COLOR_HDEFAULT = 0,
69   MT_COLOR_QUOTED,
70   MT_COLOR_SIGNATURE,
71   MT_COLOR_INDICATOR,
72   MT_COLOR_STATUS,
73   MT_COLOR_TREE,
74   MT_COLOR_NORMAL,
75   MT_COLOR_ERROR,
76   MT_COLOR_TILDE,
77   MT_COLOR_MARKERS,
78   MT_COLOR_BODY,
79   MT_COLOR_HEADER,
80   MT_COLOR_MESSAGE,
81   MT_COLOR_ATTACHMENT,
82   MT_COLOR_SEARCH,
83   MT_COLOR_BOLD,
84   MT_COLOR_SIDEBAR,
85   MT_COLOR_UNDERLINE,
86   MT_COLOR_INDEX,
87   MT_COLOR_NEW,
88   MT_COLOR_FLAGGED,
89   MT_COLOR_MAX
90 };
91
92 typedef struct color_line {
93   regex_t rx;
94   char *pattern;
95   pattern_t *color_pattern;     /* compiled pattern to speed up index color
96                                    calculation */
97   short fg;
98   short bg;
99   int pair;
100   struct color_line *next;
101 } COLOR_LINE;
102
103 typedef struct {
104   const char* msg;
105   long pos;
106   long size;
107   char sizestr[STRING];
108 } progress_t;
109
110 void mutt_progress_bar (progress_t* progress, long pos);
111 void mutt_clear_error (void);
112 void mutt_edit_file (const char *);
113 void mutt_curses_error (const char *, ...)
114     __attribute__((format(printf, 1, 2)));
115 void mutt_curses_message (const char *, ...)
116     __attribute__((format(printf, 1, 2)));
117 void mutt_format_string (char *, ssize_t, int, int, int, char, const char *,
118                          ssize_t, int);
119 void mutt_format_s (char *, ssize_t, const char *, const char *);
120 void mutt_format_s_tree (char *, ssize_t, const char *, const char *);
121 void mutt_free_color (int fg, int bg);
122 void mutt_paddstr (int, const char *);
123 #define mutt_perror(a) _mutt_perror (a, __FILE__, __LINE__)
124 void _mutt_perror (const char*, const char*,int);
125 void mutt_query_exit (void);
126 void mutt_query_menu (char *, ssize_t);
127 void mutt_show_error (void);
128 ssize_t mutt_pretty_size(char *s, ssize_t len, ssize_t n);
129
130 int mutt_addwch (wchar_t);
131 int mutt_alloc_color (int fg, int bg);
132 int mutt_any_key_to_continue (const char *);
133 void mutt_what_key (void);
134 int mutt_complete (char *, ssize_t);
135 #define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL)
136 int _mutt_enter_fname (const char *, char *, ssize_t, int *, int, int,
137                        char ***, int *);
138
139 #define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL)
140 int _mutt_get_field (const char *, char *, ssize_t, int, int, char ***, int *);
141 int mutt_get_field_unbuffered (char *, char *, ssize_t, int);
142 int mutt_index_menu (void);
143 int mutt_is_mail_list (address_t *);
144 int mutt_is_subscribed_list (address_t *);
145 int mutt_multi_choice (const char *prompt, const char *letters);
146 int mutt_parse_color (BUFFER *, BUFFER *, unsigned long, BUFFER *);
147 int mutt_parse_uncolor (BUFFER *, BUFFER *, unsigned long, BUFFER *);
148 int mutt_parse_mono (BUFFER *, BUFFER *, unsigned long, BUFFER *);
149 int mutt_parse_unmono (BUFFER *, BUFFER *, unsigned long, BUFFER *);
150 int mutt_query_complete (char *, ssize_t);
151 int mutt_user_is_recipient (HEADER *);
152 int mutt_yesorno (const char *, int);
153 void mutt_set_header_color (CONTEXT *, HEADER *);
154
155 extern int *ColorQuote;
156 extern int ColorQuoteUsed;
157 extern int ColorDefs[];
158 extern COLOR_LINE *ColorHdrList;
159 extern COLOR_LINE *ColorBodyList;
160 extern COLOR_LINE *ColorIndexList;
161
162 void ci_start_color (void);
163
164 #define mutt_make_string(A,B,C,D,E) _mutt_make_string(A,B,C,D,E,0)
165 void _mutt_make_string (char *, ssize_t, const char *, CONTEXT *,
166                         HEADER *, format_flag);
167
168
169 #define SETCOLOR(X) wattrset(stdscr, ColorDefs[X])
170 #define ADDCOLOR(X) wattron(stdscr, ColorDefs[X])
171
172 #define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); x = REDRAW_FULL; }
173
174 #define SW              (option(OPTMBOXPANE)?SidebarWidth:0)
175
176 #endif /* !_MUTT_CURSES_H */