2001-04-14 18:24:56 -04:00
|
|
|
#ifndef __TEXTBUFFER_H
|
|
|
|
#define __TEXTBUFFER_H
|
|
|
|
|
2008-05-30 19:17:37 -04:00
|
|
|
/* Make sure TEXT_CHUNK_REC is not slightly more than a page, as that
|
|
|
|
wastes a lot of memory. */
|
|
|
|
#define LINE_TEXT_CHUNK_SIZE (16384 - 16)
|
2001-04-14 18:24:56 -04:00
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
#define LINE_COLOR_BG 0x20
|
|
|
|
#define LINE_COLOR_DEFAULT 0x10
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
enum {
|
|
|
|
LINE_CMD_EOL=0x80, /* line ends here */
|
|
|
|
LINE_CMD_CONTINUE, /* line continues in next block */
|
|
|
|
LINE_CMD_COLOR0, /* change to black, would be same as \0\0 but it breaks things.. */
|
|
|
|
LINE_CMD_UNDERLINE, /* enable/disable underlining */
|
2001-10-14 06:14:32 -04:00
|
|
|
LINE_CMD_REVERSE, /* enable/disable reversed text */
|
2001-04-14 18:24:56 -04:00
|
|
|
LINE_CMD_INDENT, /* if line is split, indent it at this position */
|
2008-11-15 16:51:07 -05:00
|
|
|
LINE_CMD_BLINK, /* enable/disable blink */
|
|
|
|
LINE_CMD_BOLD, /* enable/disable bold */
|
2011-11-06 14:40:25 -05:00
|
|
|
LINE_CMD_ITALIC, /* enable/disable italic */
|
2014-01-09 09:20:29 -05:00
|
|
|
LINE_COLOR_EXT, /* extended color */
|
|
|
|
LINE_COLOR_EXT_BG, /* extended bg */
|
|
|
|
#ifdef TERM_TRUECOLOR
|
|
|
|
LINE_COLOR_24, /* 24bit color */
|
|
|
|
#endif
|
2001-04-14 18:24:56 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int level;
|
|
|
|
time_t time;
|
|
|
|
} LINE_INFO_REC;
|
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
typedef struct _LINE_REC {
|
2001-10-28 06:30:26 -05:00
|
|
|
/* Text in the line. \0 means that the next char will be a
|
|
|
|
color or command.
|
|
|
|
|
2002-01-27 15:42:45 -05:00
|
|
|
If the 7th bit is set, the lowest 7 bits are the command
|
2001-10-28 06:30:26 -05:00
|
|
|
(see LINE_CMD_xxxx). Otherwise they specify a color change:
|
|
|
|
|
|
|
|
Bit:
|
|
|
|
5 - Setting a background color
|
|
|
|
4 - Use "default terminal color"
|
2008-11-15 16:51:07 -05:00
|
|
|
0-3 - Color
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
DO NOT ADD BLACK WITH \0\0 - this will break things. Use
|
|
|
|
LINE_CMD_COLOR0 instead. */
|
2001-07-12 17:44:01 -04:00
|
|
|
struct _LINE_REC *prev, *next;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
unsigned char *text;
|
|
|
|
LINE_INFO_REC info;
|
|
|
|
} LINE_REC;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned char buffer[LINE_TEXT_CHUNK_SIZE];
|
|
|
|
int pos;
|
|
|
|
int refcount;
|
|
|
|
} TEXT_CHUNK_REC;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GSList *text_chunks;
|
2001-07-12 17:44:01 -04:00
|
|
|
LINE_REC *first_line;
|
2001-04-14 18:24:56 -04:00
|
|
|
int lines_count;
|
|
|
|
|
|
|
|
LINE_REC *cur_line;
|
|
|
|
TEXT_CHUNK_REC *cur_text;
|
|
|
|
|
|
|
|
unsigned int last_eol:1;
|
2008-04-16 16:32:36 -04:00
|
|
|
int last_fg;
|
|
|
|
int last_bg;
|
|
|
|
int last_flags;
|
2001-04-14 18:24:56 -04:00
|
|
|
} TEXT_BUFFER_REC;
|
|
|
|
|
|
|
|
/* Create new buffer */
|
|
|
|
TEXT_BUFFER_REC *textbuffer_create(void);
|
|
|
|
/* Destroy the buffer */
|
|
|
|
void textbuffer_destroy(TEXT_BUFFER_REC *buffer);
|
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
LINE_REC *textbuffer_line_last(TEXT_BUFFER_REC *buffer);
|
|
|
|
int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search);
|
|
|
|
|
2008-03-10 08:05:43 -04:00
|
|
|
void textbuffer_line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
|
|
|
|
int fg, int bg, int flags);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
/* Append text to buffer. When \0<EOL> is found at the END OF DATA, a new
|
|
|
|
line is created. You must send the EOL command before you can do anything
|
|
|
|
else with the buffer. */
|
|
|
|
LINE_REC *textbuffer_append(TEXT_BUFFER_REC *buffer,
|
|
|
|
const unsigned char *data, int len,
|
|
|
|
LINE_INFO_REC *info);
|
|
|
|
LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
|
|
|
|
const unsigned char *data, int len,
|
|
|
|
LINE_INFO_REC *info);
|
|
|
|
|
|
|
|
void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line);
|
|
|
|
/* Removes all lines from buffer, ignoring reference counters */
|
|
|
|
void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer);
|
|
|
|
|
|
|
|
void textbuffer_line2text(LINE_REC *line, int coloring, GString *str);
|
|
|
|
GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
|
|
|
|
int level, int nolevel, const char *text,
|
2002-01-20 11:57:06 -05:00
|
|
|
int before, int after,
|
2001-04-14 18:24:56 -04:00
|
|
|
int regexp, int fullword, int case_sensitive);
|
|
|
|
|
|
|
|
void textbuffer_init(void);
|
|
|
|
void textbuffer_deinit(void);
|
|
|
|
|
|
|
|
#endif
|