imported irssi.
[silc.git] / apps / irssi / src / fe-text / textbuffer.h
1 #ifndef __TEXTBUFFER_H
2 #define __TEXTBUFFER_H
3
4 /* FIXME: Textbuffer code gets a lot faster in some points when I get rid of
5    GList and make prev/next pointers directly in LINE_REC. However, this
6    can still wait for a while until I get rid of GList entirely everywhere. */
7
8 #define LINE_TEXT_CHUNK_SIZE 16384
9
10 enum {
11         LINE_CMD_EOL=0x80,      /* line ends here */
12         LINE_CMD_CONTINUE,      /* line continues in next block */
13         LINE_CMD_COLOR0,        /* change to black, would be same as \0\0 but it breaks things.. */
14         LINE_CMD_COLOR8,        /* change to dark grey, normally 8 = bold black */
15         LINE_CMD_UNDERLINE,     /* enable/disable underlining */
16         LINE_CMD_INDENT,        /* if line is split, indent it at this position */
17         LINE_CMD_BLINK,         /* blinking background */
18         LINE_CMD_FORMAT,        /* end of line, but next will come the format that was used to create the
19                                    text in format <module><format_name><arg><arg2...> - fields are separated
20                                    with \0<format> and last argument ends with \0<eol>. \0<continue> is allowed
21                                    anywhere */
22         LINE_CMD_FORMAT_CONT    /* multiline format, continues to next line */
23 };
24
25 typedef struct {
26         int level;
27         time_t time;
28 } LINE_INFO_REC;
29
30 typedef struct {
31         /* text in the line. \0 means that the next char will be a
32            color or command. <= 127 = color or if 8. bit is set, the
33            first 7 bits are the command. See LINE_CMD_xxxx.
34
35            DO NOT ADD BLACK WITH \0\0 - this will break things. Use
36            LINE_CMD_COLOR0 instead. */
37         unsigned char *text;
38         unsigned char refcount;
39         LINE_INFO_REC info;
40 } LINE_REC;
41
42 typedef struct {
43         unsigned char buffer[LINE_TEXT_CHUNK_SIZE];
44         int pos;
45         int refcount;
46 } TEXT_CHUNK_REC;
47
48 typedef struct {
49         GSList *text_chunks;
50         GList *lines;
51         int lines_count;
52
53         LINE_REC *cur_line;
54         TEXT_CHUNK_REC *cur_text;
55
56         unsigned int last_eol:1;
57 } TEXT_BUFFER_REC;
58
59 /* Create new buffer */
60 TEXT_BUFFER_REC *textbuffer_create(void);
61 /* Destroy the buffer */
62 void textbuffer_destroy(TEXT_BUFFER_REC *buffer);
63
64 void textbuffer_line_ref(LINE_REC *line);
65 void textbuffer_line_unref(TEXT_BUFFER_REC *buffer, LINE_REC *line);
66 void textbuffer_line_unref_list(TEXT_BUFFER_REC *buffer, GList *list);
67
68 /* Append text to buffer. When \0<EOL> is found at the END OF DATA, a new
69    line is created. You must send the EOL command before you can do anything
70    else with the buffer. */
71 LINE_REC *textbuffer_append(TEXT_BUFFER_REC *buffer,
72                             const unsigned char *data, int len,
73                             LINE_INFO_REC *info);
74 LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
75                             const unsigned char *data, int len,
76                             LINE_INFO_REC *info);
77
78 void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line);
79 /* Removes all lines from buffer, ignoring reference counters */
80 void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer);
81
82 void textbuffer_line2text(LINE_REC *line, int coloring, GString *str);
83 GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
84                             int level, int nolevel, const char *text,
85                             int regexp, int fullword, int case_sensitive);
86
87 void textbuffer_init(void);
88 void textbuffer_deinit(void);
89
90 #endif