Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-text / textbuffer.h
1 #ifndef __TEXTBUFFER_H
2 #define __TEXTBUFFER_H
3
4 #define LINE_TEXT_CHUNK_SIZE 16384
5
6 #define LINE_COLOR_BG           0x20
7 #define LINE_COLOR_DEFAULT      0x10
8 #define LINE_COLOR_BOLD         0x08
9 #define LINE_COLOR_BLINK        0x08
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_INDENT_FUNC,   /* if line is split, use the specified indentation function */
19         LINE_CMD_FORMAT,        /* end of line, but next will come the format that was used to create the
20                                    text in format <module><format_name><arg><arg2...> - fields are separated
21                                    with \0<format> and last argument ends with \0<eol>. \0<continue> is allowed
22                                    anywhere */
23         LINE_CMD_FORMAT_CONT    /* multiline format, continues to next line */
24 };
25
26 typedef struct {
27         int level;
28         time_t time;
29 } LINE_INFO_REC;
30
31 typedef struct _LINE_REC {
32         /* Text in the line. \0 means that the next char will be a
33            color or command.
34
35            If the 7th bit is set, the lowest 7 bits are the command
36            (see LINE_CMD_xxxx). Otherwise they specify a color change:
37
38            Bit:
39             5 - Setting a background color
40             4 - Use "default terminal color"
41             3 - Bold (fg) / blink (bg) - can be used with 4th bit
42             0-2 - Color
43
44            DO NOT ADD BLACK WITH \0\0 - this will break things. Use
45            LINE_CMD_COLOR0 instead. */
46         struct _LINE_REC *prev, *next;
47
48         unsigned char *text;
49         unsigned char refcount;
50         LINE_INFO_REC info;
51 } LINE_REC;
52
53 typedef struct {
54         unsigned char buffer[LINE_TEXT_CHUNK_SIZE];
55         int pos;
56         int refcount;
57 } TEXT_CHUNK_REC;
58
59 typedef struct {
60         GSList *text_chunks;
61         LINE_REC *first_line;
62         int lines_count;
63
64         LINE_REC *cur_line;
65         TEXT_CHUNK_REC *cur_text;
66
67         unsigned int last_eol:1;
68 } TEXT_BUFFER_REC;
69
70 /* Create new buffer */
71 TEXT_BUFFER_REC *textbuffer_create(void);
72 /* Destroy the buffer */
73 void textbuffer_destroy(TEXT_BUFFER_REC *buffer);
74
75 void textbuffer_line_ref(LINE_REC *line);
76 void textbuffer_line_unref(TEXT_BUFFER_REC *buffer, LINE_REC *line);
77 void textbuffer_line_unref_list(TEXT_BUFFER_REC *buffer, GList *list);
78
79 LINE_REC *textbuffer_line_last(TEXT_BUFFER_REC *buffer);
80 int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search);
81
82 /* Append text to buffer. When \0<EOL> is found at the END OF DATA, a new
83    line is created. You must send the EOL command before you can do anything
84    else with the buffer. */
85 LINE_REC *textbuffer_append(TEXT_BUFFER_REC *buffer,
86                             const unsigned char *data, int len,
87                             LINE_INFO_REC *info);
88 LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
89                             const unsigned char *data, int len,
90                             LINE_INFO_REC *info);
91
92 void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line);
93 /* Removes all lines from buffer, ignoring reference counters */
94 void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer);
95
96 void textbuffer_line2text(LINE_REC *line, int coloring, GString *str);
97 GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
98                             int level, int nolevel, const char *text,
99                             int before, int after,
100                             int regexp, int fullword, int case_sensitive);
101
102 void textbuffer_init(void);
103 void textbuffer_deinit(void);
104
105 #endif