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