Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-common / core / formats.h
1 #ifndef __FORMATS_H
2 #define __FORMATS_H
3
4 #include "themes.h"
5 #include "fe-windows.h"
6
7 #define GUI_PRINT_FLAG_BOLD          0x0001
8 #define GUI_PRINT_FLAG_REVERSE       0x0002
9 #define GUI_PRINT_FLAG_UNDERLINE     0x0004
10 #define GUI_PRINT_FLAG_BLINK         0x0008
11 #define GUI_PRINT_FLAG_MIRC_COLOR    0x0010
12 #define GUI_PRINT_FLAG_INDENT        0x0020
13 #define GUI_PRINT_FLAG_INDENT_FUNC   0x0040
14 #define GUI_PRINT_FLAG_NEWLINE       0x0080
15 #define GUI_PRINT_FLAG_CLRTOEOL      0x0100
16 #define GUI_PRINT_FLAG_MONOSPACE     0x0200
17
18 #define MAX_FORMAT_PARAMS 10
19 #define DEFAULT_FORMAT_ARGLIST_SIZE 200
20
21 enum {
22         FORMAT_STRING,
23         FORMAT_INT,
24         FORMAT_LONG,
25         FORMAT_FLOAT
26 };
27
28 struct _FORMAT_REC {
29         char *tag;
30         char *def;
31
32         int params;
33         int paramtypes[MAX_FORMAT_PARAMS];
34 };
35
36 #define PRINT_FLAG_SET_LINE_START       0x0001
37 #define PRINT_FLAG_SET_LINE_START_IRSSI 0x0002
38 #define PRINT_FLAG_UNSET_LINE_START     0x0003
39
40 #define PRINT_FLAG_SET_TIMESTAMP        0x0004
41 #define PRINT_FLAG_UNSET_TIMESTAMP      0x0008
42
43 #define PRINT_FLAG_SET_SERVERTAG        0x0010
44 #define PRINT_FLAG_UNSET_SERVERTAG      0x0020
45
46 typedef struct _TEXT_DEST_REC {
47         WINDOW_REC *window;
48         SERVER_REC *server;
49         const char *server_tag; /* if server is non-NULL, must be server->tag */
50         const char *target;
51         int level;
52
53         int hilight_priority;
54         char *hilight_color;
55         int flags;
56 } TEXT_DEST_REC;
57
58 #define window_get_theme(window) \
59         (window != NULL && (window)->theme != NULL ? \
60         (window)->theme : current_theme)
61
62 int format_find_tag(const char *module, const char *tag);
63
64 /* Return length of text part in string (ie. without % codes) */
65 int format_get_length(const char *str);
66 /* Return how many characters in `str' must be skipped before `len'
67    characters of text is skipped. Like strip_real_length(), except this
68    handles %codes. */
69 int format_real_length(const char *str, int len);
70
71 char *format_string_expand(const char *text, int *flags);
72
73 char *format_get_text(const char *module, WINDOW_REC *window,
74                       void *server, const char *target,
75                       int formatnum, ...);
76
77 /* good size for buffer is DEFAULT_FORMAT_ARGLIST_SIZE */
78 void format_read_arglist(va_list va, FORMAT_REC *format,
79                          char **arglist, int arglist_size,
80                          char *buffer, int buffer_size);
81 char *format_get_text_theme(THEME_REC *theme, const char *module,
82                             TEXT_DEST_REC *dest, int formatnum, ...);
83 char *format_get_text_theme_args(THEME_REC *theme, const char *module,
84                                  TEXT_DEST_REC *dest, int formatnum,
85                                  va_list va);
86 char *format_get_text_theme_charargs(THEME_REC *theme, const char *module,
87                                      TEXT_DEST_REC *dest, int formatnum,
88                                      char **args);
89
90 /* add `linestart' to start/end of each line in `text'. `text' may contain
91    multiple lines separated with \n. */
92 char *format_add_linestart(const char *text, const char *linestart);
93 char *format_add_lineend(const char *text, const char *linestart);
94
95 /* return the "-!- " text at the start of the line */
96 char *format_get_level_tag(THEME_REC *theme, TEXT_DEST_REC *dest);
97
98 /* return timestamp + server tag */
99 char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t);
100
101
102 /* "private" functions for printtext */
103 void format_create_dest(TEXT_DEST_REC *dest,
104                         void *server, const char *target,
105                         int level, WINDOW_REC *window);
106 void format_create_dest_tag(TEXT_DEST_REC *dest, void *server,
107                             const char *server_tag, const char *target,
108                             int level, WINDOW_REC *window);
109
110 void format_newline(WINDOW_REC *window);
111
112 /* Return how many characters in `str' must be skipped before `len'
113    characters of text is skipped. */
114 int strip_real_length(const char *str, int len,
115                       int *last_color_pos, int *last_color_len);
116
117 /* strip all color (etc.) codes from `input'.
118    Returns newly allocated string. */
119 char *strip_codes(const char *input);
120
121 /* send a fully parsed text string for GUI to print */
122 void format_send_to_gui(TEXT_DEST_REC *dest, const char *text);
123
124 #define FORMAT_COLOR_NOCHANGE   ('0'-1) /* don't change this, at least hilighting depends this value */
125
126 #define FORMAT_STYLE_SPECIAL    0x60
127 #define FORMAT_STYLE_BLINK      (0x01 + FORMAT_STYLE_SPECIAL)
128 #define FORMAT_STYLE_UNDERLINE  (0x02 + FORMAT_STYLE_SPECIAL)
129 #define FORMAT_STYLE_BOLD       (0x03 + FORMAT_STYLE_SPECIAL)
130 #define FORMAT_STYLE_REVERSE    (0x04 + FORMAT_STYLE_SPECIAL)
131 #define FORMAT_STYLE_INDENT     (0x05 + FORMAT_STYLE_SPECIAL)
132 #define FORMAT_STYLE_INDENT_FUNC (0x06 + FORMAT_STYLE_SPECIAL)
133 #define FORMAT_STYLE_DEFAULTS   (0x07 + FORMAT_STYLE_SPECIAL)
134 #define FORMAT_STYLE_CLRTOEOL   (0x08 + FORMAT_STYLE_SPECIAL)
135 #define FORMAT_STYLE_MONOSPACE  (0x09 + FORMAT_STYLE_SPECIAL)
136 int format_expand_styles(GString *out, const char **format, int *flags);
137
138 void formats_init(void);
139 void formats_deinit(void);
140
141 #endif