add format_string_expand and format_string_unexpand methods to Perl

This commit is contained in:
Ailin Nemui 2021-03-14 18:31:56 +01:00
commit 030da3ec9c
9 changed files with 226 additions and 6 deletions

View file

@ -344,7 +344,7 @@ static char *fallback_format(TEXT_BUFFER_FORMAT_REC *format_rec)
return g_string_free(bs, FALSE);
}
char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line, gboolean raw)
{
TEXT_DEST_REC dest;
GUI_WINDOW_REC *gui;
@ -430,6 +430,10 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
format_create_dest(&dest, NULL, NULL, line->info.level, buffer->window);
text = g_strdup(line->info.text);
}
if (raw)
return text;
tmp = parse_colors(&dest, text);
g_free(text);
return tmp;

View file

@ -23,7 +23,7 @@ typedef struct _TEXT_BUFFER_FORMAT_REC {
void textbuffer_format_rec_free(TEXT_BUFFER_FORMAT_REC *rec);
void textbuffer_meta_rec_free(TEXT_BUFFER_META_REC *rec);
char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line);
char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line, gboolean raw);
void textbuffer_formats_init(void);
void textbuffer_formats_deinit(void);

View file

@ -274,7 +274,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
linecount = 1;
lines = NULL;
line_text = textbuffer_line_get_text(view->buffer, line);
line_text = textbuffer_line_get_text(view->buffer, line, FALSE);
if (line_text != NULL) {
for (ptr = (unsigned char *) line_text;;) {
if (*ptr == '\0')

View file

@ -238,11 +238,15 @@ void textbuffer_line2text(TEXT_BUFFER_REC *buffer, LINE_REC *line, int coloring,
g_string_truncate(str, 0);
if ((ptr = textbuffer_line_get_text(buffer, line)) != NULL) {
if (coloring == 0) {
if ((ptr = textbuffer_line_get_text(buffer, line, coloring == COLORING_RAW)) != NULL) {
if (coloring == COLORING_STRIP) {
tmp = ptr;
ptr = strip_codes(tmp);
g_free(tmp);
} else if (coloring == COLORING_UNEXPAND) {
tmp = ptr;
ptr = format_string_unexpand(tmp, 0);
g_free(tmp);
}
g_string_append(str, ptr);
g_free(ptr);
@ -288,7 +292,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
(line->info.level & nolevel) == 0;
if (*text != '\0') {
textbuffer_line2text(buffer, line, FALSE, str);
textbuffer_line2text(buffer, line, 0, str);
if (line_matched) {
line_matched = regexp ?

View file

@ -11,6 +11,13 @@ enum {
LINE_CMD_EOL=0x80, /* line ends here */
};
enum {
COLORING_STRIP = 0,
COLORING_EXPAND = 1,
COLORING_UNEXPAND = 2,
COLORING_RAW = 3,
};
struct _TEXT_BUFFER_FORMAT_REC;
typedef struct {