Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / fe-text / textbuffer.h
1 #ifndef __TEXTBUFFER_H
2 #define __TEXTBUFFER_H
3
4 /* Make sure TEXT_CHUNK_REC is not slightly more than a page, as that
5    wastes a lot of memory. */
6 #define LINE_TEXT_CHUNK_SIZE (16384 - 16)
7
8 #define LINE_COLOR_BG           0x20
9 #define LINE_COLOR_DEFAULT      0x10
10
11 enum {
12         LINE_CMD_EOL=0x80,      /* line ends here */
13         LINE_CMD_CONTINUE,      /* line continues in next block */
14         LINE_CMD_COLOR0,        /* change to black, would be same as \0\0 but it breaks things.. */
15         LINE_CMD_UNDERLINE,     /* enable/disable underlining */
16         LINE_CMD_REVERSE,       /* enable/disable reversed text */
17         LINE_CMD_INDENT,        /* if line is split, indent it at this position */
18         LINE_CMD_BLINK,         /* enable/disable blink */
19         LINE_CMD_BOLD,          /* enable/disable bold */
20 };
21
22 typedef struct {
23         int level;
24         time_t time;
25 } LINE_INFO_REC;
26
27 typedef struct _LINE_REC {
28         /* Text in the line. \0 means that the next char will be a
29            color or command.
30
31            If the 7th bit is set, the lowest 7 bits are the command
32            (see LINE_CMD_xxxx). Otherwise they specify a color change:
33
34            Bit:
35             5 - Setting a background color
36             4 - Use "default terminal color"
37             0-3 - Color
38
39            DO NOT ADD BLACK WITH \0\0 - this will break things. Use
40            LINE_CMD_COLOR0 instead. */
41         struct _LINE_REC *prev, *next;
42
43         unsigned char *text;
44         LINE_INFO_REC info;
45 } LINE_REC;
46
47 typedef struct {
48         unsigned char buffer[LINE_TEXT_CHUNK_SIZE];
49         int pos;
50         int refcount;
51 } TEXT_CHUNK_REC;
52
53 typedef struct {
54         GSList *text_chunks;
55         LINE_REC *first_line;
56         int lines_count;
57
58         LINE_REC *cur_line;
59         TEXT_CHUNK_REC *cur_text;
60
61         unsigned int last_eol:1;
62         int last_fg;
63         int last_bg;
64         int last_flags;
65 } TEXT_BUFFER_REC;
66
67 /* Create new buffer */
68 TEXT_BUFFER_REC *textbuffer_create(void);
69 /* Destroy the buffer */
70 void textbuffer_destroy(TEXT_BUFFER_REC *buffer);
71
72 LINE_REC *textbuffer_line_last(TEXT_BUFFER_REC *buffer);
73 int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search);
74
75 void textbuffer_line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
76                                 int fg, int bg, int flags);
77
78 /* Append text to buffer. When \0<EOL> is found at the END OF DATA, a new
79    line is created. You must send the EOL command before you can do anything
80    else with the buffer. */
81 LINE_REC *textbuffer_append(TEXT_BUFFER_REC *buffer,
82                             const unsigned char *data, int len,
83                             LINE_INFO_REC *info);
84 LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
85                             const unsigned char *data, int len,
86                             LINE_INFO_REC *info);
87
88 void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line);
89 /* Removes all lines from buffer, ignoring reference counters */
90 void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer);
91
92 void textbuffer_line2text(LINE_REC *line, int coloring, GString *str);
93 GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
94                             int level, int nolevel, const char *text,
95                             int before, int after,
96                             int regexp, int fullword, int case_sensitive);
97
98 void textbuffer_init(void);
99 void textbuffer_deinit(void);
100
101 #endif