mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Rewrote text buffer handling in windows - try #3.
/SET scrollback_save_formats + /SB REDRAW is broken currently. There's some other minor things that might need to be changed. This time it allows the same window to be visible multiple times in screen, like you could make a new split window where to scroll back and find something while still seeing the new messages at the other window, this however doesn't work yet but it should be quite easy to make it :) I've tested that pretty much everything should work with this, new lines can be added at any position and lines can be removed from any position and screen should be updated properly. Screen resizing should also work perfectly now (maybe it did previously too, not sure) and hopefully now we won't see any of those ugly strange bugs some people were having. Also this time the same code isn't written 2-3 times to do some specific thing, like scrolling has now only one view_scroll() function instead of the 3 separate functions it used to have :) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1442 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
d98fddd796
commit
adb7eced39
@ -24,17 +24,19 @@ irssi_SOURCES = \
|
||||
gui-expandos.c \
|
||||
gui-printtext.c \
|
||||
gui-readline.c \
|
||||
gui-textwidget.c \
|
||||
gui-windows.c \
|
||||
lastlog.c \
|
||||
mainwindows.c \
|
||||
mainwindow-activity.c \
|
||||
mainwindows-save.c \
|
||||
screen.c \
|
||||
statusbar.c \
|
||||
statusbar-items.c \
|
||||
textbuffer.c \
|
||||
textbuffer-commands.c \
|
||||
textbuffer-view.c \
|
||||
irssi.c \
|
||||
module-formats.c \
|
||||
screen.c
|
||||
module-formats.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
gui-entry.h \
|
||||
@ -44,5 +46,7 @@ noinst_HEADERS = \
|
||||
mainwindows.h \
|
||||
statusbar.h \
|
||||
screen.h \
|
||||
textbuffer.h \
|
||||
textbuffer-view.h \
|
||||
module.h \
|
||||
module-formats.h
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "formats.h"
|
||||
@ -29,220 +28,15 @@
|
||||
#include "screen.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
#define TEXT_CHUNK_USABLE_SIZE (LINE_TEXT_CHUNK_SIZE-2-(int)sizeof(char*))
|
||||
|
||||
int mirc_colors[] = { 15, 0, 1, 2, 12, 6, 5, 4, 14, 10, 3, 11, 9, 13, 8, 7 };
|
||||
static int scrollback_lines, scrollback_hours;
|
||||
static int scrollback_lines, scrollback_hours, scrollback_burst_remove;
|
||||
|
||||
static int scrollback_save_formats;
|
||||
static GString *format;
|
||||
|
||||
static int last_color, last_flags;
|
||||
static int next_xpos, next_ypos;
|
||||
|
||||
#define mark_temp_eol(text) \
|
||||
memcpy((text)->buffer + (text)->pos, "\0\200", 2);
|
||||
|
||||
static LINE_REC *create_line(GUI_WINDOW_REC *gui, int level)
|
||||
{
|
||||
LINE_REC *rec;
|
||||
|
||||
g_return_val_if_fail(gui != NULL, NULL);
|
||||
g_return_val_if_fail(gui->cur_text != NULL, NULL);
|
||||
|
||||
rec = g_mem_chunk_alloc(gui->line_chunk);
|
||||
rec->text = gui->cur_text->buffer+gui->cur_text->pos;
|
||||
rec->level = GPOINTER_TO_INT(level);
|
||||
rec->time = time(NULL);
|
||||
|
||||
mark_temp_eol(gui->cur_text);
|
||||
gui->cur_text->lines++;
|
||||
|
||||
gui->last_color = -1;
|
||||
gui->last_flags = 0;
|
||||
|
||||
if (gui->temp_line != NULL) {
|
||||
int pos = g_list_index(gui->lines, gui->temp_line);
|
||||
gui->lines = g_list_insert(gui->lines, rec, pos+1);
|
||||
gui->temp_line = rec;
|
||||
} else {
|
||||
gui->cur_line = rec;
|
||||
gui->lines = g_list_append(gui->lines, rec);
|
||||
if (gui->startline == NULL) {
|
||||
/* first line */
|
||||
gui->startline = gui->lines;
|
||||
gui->bottom_startline = gui->lines;
|
||||
}
|
||||
}
|
||||
return rec;
|
||||
}
|
||||
|
||||
static TEXT_CHUNK_REC *create_text_chunk(GUI_WINDOW_REC *gui)
|
||||
{
|
||||
TEXT_CHUNK_REC *rec;
|
||||
char *buffer, *ptr, **pptr;
|
||||
|
||||
g_return_val_if_fail(gui != NULL, NULL);
|
||||
|
||||
rec = g_new(TEXT_CHUNK_REC, 1);
|
||||
rec->pos = 0;
|
||||
rec->lines = 0;
|
||||
|
||||
if (gui->cur_line != NULL && gui->cur_line->text != NULL) {
|
||||
/* create a link to new block from the old block */
|
||||
buffer = gui->cur_text->buffer + gui->cur_text->pos;
|
||||
*buffer++ = 0; *buffer++ = (char) LINE_CMD_CONTINUE;
|
||||
|
||||
ptr = rec->buffer; pptr = &ptr;
|
||||
memcpy(buffer, pptr, sizeof(char *));
|
||||
} else {
|
||||
/* just to be safe */
|
||||
mark_temp_eol(rec);
|
||||
}
|
||||
|
||||
gui->cur_text = rec;
|
||||
gui->text_chunks = g_slist_append(gui->text_chunks, rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
static void text_chunk_free(GUI_WINDOW_REC *gui, TEXT_CHUNK_REC *chunk)
|
||||
{
|
||||
g_return_if_fail(gui != NULL);
|
||||
g_return_if_fail(chunk != NULL);
|
||||
|
||||
gui->text_chunks = g_slist_remove(gui->text_chunks, chunk);
|
||||
g_free(chunk);
|
||||
}
|
||||
|
||||
static TEXT_CHUNK_REC *text_chunk_find(GUI_WINDOW_REC *gui, const char *data)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = gui->text_chunks; tmp != NULL; tmp = tmp->next) {
|
||||
TEXT_CHUNK_REC *rec = tmp->data;
|
||||
|
||||
if (data >= rec->buffer &&
|
||||
data < rec->buffer+sizeof(rec->buffer))
|
||||
return rec;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void gui_window_line_text_free(GUI_WINDOW_REC *gui, LINE_REC *line)
|
||||
{
|
||||
TEXT_CHUNK_REC *chunk;
|
||||
const char *text;
|
||||
|
||||
text = line->text;
|
||||
for (;;) {
|
||||
if (*text == '\0') {
|
||||
text++;
|
||||
if ((unsigned char) *text == LINE_CMD_EOL)
|
||||
break;
|
||||
|
||||
if ((unsigned char) *text == LINE_CMD_CONTINUE) {
|
||||
char *tmp;
|
||||
|
||||
memcpy(&tmp, text+1, sizeof(char *));
|
||||
|
||||
/* free the previous block */
|
||||
chunk = text_chunk_find(gui, text);
|
||||
if (--chunk->lines == 0)
|
||||
text_chunk_free(gui, chunk);
|
||||
|
||||
text = tmp;
|
||||
continue;
|
||||
}
|
||||
if ((unsigned char) *text & 0x80)
|
||||
text++;
|
||||
continue;
|
||||
}
|
||||
|
||||
text++;
|
||||
}
|
||||
|
||||
/* free the last block */
|
||||
chunk = text_chunk_find(gui, text);
|
||||
if (--chunk->lines == 0) {
|
||||
if (gui->cur_text == chunk)
|
||||
chunk->pos = 0;
|
||||
else
|
||||
text_chunk_free(gui, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line, int redraw)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
GList *last;
|
||||
int screenchange;
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
g_return_if_fail(line != NULL);
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
|
||||
if (gui->lines->next == NULL) {
|
||||
/* last line in window */
|
||||
gui_window_clear(window);
|
||||
return;
|
||||
}
|
||||
|
||||
screenchange = g_list_find(gui->startline, line) != NULL;
|
||||
if (screenchange) gui->ypos -= gui_window_get_linecount(gui, line);
|
||||
|
||||
gui_window_cache_remove(gui, line);
|
||||
gui_window_line_text_free(gui, line);
|
||||
if (gui->lastlog_last_check != NULL &&
|
||||
gui->lastlog_last_check->data == line)
|
||||
gui->lastlog_last_check = NULL;
|
||||
if (gui->lastlog_last_away != NULL &&
|
||||
gui->lastlog_last_away->data == line)
|
||||
gui->lastlog_last_away = NULL;
|
||||
|
||||
last = g_list_last(gui->bottom_startline);
|
||||
if (last->data == line) {
|
||||
/* removing last line */
|
||||
gui->last_subline =
|
||||
gui_window_get_linecount(gui, last->prev->data)-1;
|
||||
}
|
||||
|
||||
if (gui->bottom_startline->data == line) {
|
||||
/* bottom line removed */
|
||||
if (gui->bottom_startline->next != NULL) {
|
||||
gui->bottom_startline = gui->bottom_startline->next;
|
||||
gui->bottom_subline = 0;
|
||||
} else {
|
||||
gui->bottom_startline = gui->bottom_startline->prev;
|
||||
gui->bottom_subline = gui->last_subline+1;
|
||||
}
|
||||
}
|
||||
|
||||
if (gui->startline->data == line) {
|
||||
/* first line in screen removed */
|
||||
if (gui->startline->next != NULL) {
|
||||
gui->startline = gui->startline->next;
|
||||
gui->subline = 0;
|
||||
} else {
|
||||
gui->startline = gui->startline->prev;
|
||||
gui->subline = gui->last_subline+1;
|
||||
gui->ypos = -1;
|
||||
gui->empty_linecount = gui->parent->lines;
|
||||
gui->bottom = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
window->lines--;
|
||||
g_mem_chunk_free(gui->line_chunk, line);
|
||||
gui->lines = g_list_remove(gui->lines, line);
|
||||
|
||||
if (window->lines == 0)
|
||||
gui_window_clear(window);
|
||||
|
||||
if (redraw && screenchange && is_window_visible(window))
|
||||
gui_window_redraw(window);
|
||||
}
|
||||
|
||||
void gui_printtext(int xpos, int ypos, const char *str)
|
||||
{
|
||||
next_xpos = xpos;
|
||||
@ -253,24 +47,22 @@ void gui_printtext(int xpos, int ypos, const char *str)
|
||||
next_xpos = next_ypos = -1;
|
||||
}
|
||||
|
||||
static void remove_old_lines(WINDOW_REC *window)
|
||||
static void remove_old_lines(TEXT_BUFFER_VIEW_REC *view)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
LINE_REC *line;
|
||||
time_t old_time;
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
|
||||
old_time = time(NULL)-(scrollback_hours*3600)+1;
|
||||
if (scrollback_lines > 0) {
|
||||
if (view->buffer->lines_count >=
|
||||
scrollback_lines+scrollback_burst_remove) {
|
||||
/* remove lines by line count */
|
||||
while (window->lines > scrollback_lines) {
|
||||
line = gui->lines->data;
|
||||
if (line->time >= old_time) {
|
||||
while (view->buffer->lines_count > scrollback_lines) {
|
||||
line = view->buffer->lines->data;
|
||||
if (line->info.time >= old_time) {
|
||||
/* too new line, don't remove yet */
|
||||
break;
|
||||
}
|
||||
gui_window_line_remove(window, line, TRUE);
|
||||
textbuffer_view_remove_line(view, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,37 +100,10 @@ static void get_colors(int flags, int *fg, int *bg)
|
||||
if (flags & PRINTFLAG_BLINK) *bg |= 0x08;
|
||||
}
|
||||
|
||||
static void linebuf_add(GUI_WINDOW_REC *gui, const char *str, int len)
|
||||
static void line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
|
||||
int fg, int bg, int flags)
|
||||
{
|
||||
int left;
|
||||
|
||||
if (len == 0) return;
|
||||
|
||||
while (gui->cur_text->pos + len >= TEXT_CHUNK_USABLE_SIZE) {
|
||||
left = TEXT_CHUNK_USABLE_SIZE - gui->cur_text->pos;
|
||||
if (str[left-1] == 0) left--; /* don't split the commands */
|
||||
|
||||
memcpy(gui->cur_text->buffer + gui->cur_text->pos, str, left);
|
||||
gui->cur_text->pos += left;
|
||||
|
||||
create_text_chunk(gui);
|
||||
gui->cur_text->lines++;
|
||||
len -= left; str += left;
|
||||
}
|
||||
|
||||
memcpy(gui->cur_text->buffer + gui->cur_text->pos, str, len);
|
||||
gui->cur_text->pos += len;
|
||||
}
|
||||
|
||||
void gui_window_line_append(GUI_WINDOW_REC *gui, const char *str, int len)
|
||||
{
|
||||
linebuf_add(gui, str, len);
|
||||
mark_temp_eol(gui->cur_text);
|
||||
}
|
||||
|
||||
static void line_add_colors(GUI_WINDOW_REC *gui, int fg, int bg, int flags)
|
||||
{
|
||||
unsigned char buffer[12];
|
||||
unsigned char data[12];
|
||||
int color, pos;
|
||||
|
||||
/* color should never have last bit on or it would be treated as a
|
||||
@ -346,49 +111,60 @@ static void line_add_colors(GUI_WINDOW_REC *gui, int fg, int bg, int flags)
|
||||
color = (fg & 0x0f) | ((bg & 0x07) << 4);
|
||||
pos = 0;
|
||||
|
||||
if (((fg & ATTR_COLOR8) == 0 && (fg|(bg << 4)) != gui->last_color) ||
|
||||
((fg & ATTR_COLOR8) && (fg & 0xf0) != (gui->last_color & 0xf0))) {
|
||||
buffer[pos++] = 0;
|
||||
buffer[pos++] = color == 0 ? LINE_CMD_COLOR0 : color;
|
||||
if (((fg & ATTR_COLOR8) == 0 && (fg|(bg << 4)) != last_color) ||
|
||||
((fg & ATTR_COLOR8) && (fg & 0xf0) != (last_color & 0xf0))) {
|
||||
data[pos++] = 0;
|
||||
data[pos++] = color == 0 ? LINE_CMD_COLOR0 : color;
|
||||
}
|
||||
|
||||
if ((flags & PRINTFLAG_UNDERLINE) != (gui->last_flags & PRINTFLAG_UNDERLINE)) {
|
||||
buffer[pos++] = 0;
|
||||
buffer[pos++] = LINE_CMD_UNDERLINE;
|
||||
if ((flags & PRINTFLAG_UNDERLINE) != (last_flags & PRINTFLAG_UNDERLINE)) {
|
||||
data[pos++] = 0;
|
||||
data[pos++] = LINE_CMD_UNDERLINE;
|
||||
}
|
||||
if (fg & ATTR_COLOR8) {
|
||||
buffer[pos++] = 0;
|
||||
buffer[pos++] = LINE_CMD_COLOR8;
|
||||
data[pos++] = 0;
|
||||
data[pos++] = LINE_CMD_COLOR8;
|
||||
}
|
||||
if (bg & 0x08) {
|
||||
buffer[pos++] = 0;
|
||||
buffer[pos++] = LINE_CMD_BLINK;
|
||||
data[pos++] = 0;
|
||||
data[pos++] = LINE_CMD_BLINK;
|
||||
}
|
||||
if (flags & PRINTFLAG_INDENT) {
|
||||
buffer[pos++] = 0;
|
||||
buffer[pos++] = LINE_CMD_INDENT;
|
||||
data[pos++] = 0;
|
||||
data[pos++] = LINE_CMD_INDENT;
|
||||
}
|
||||
|
||||
linebuf_add(gui, (char *) buffer, pos);
|
||||
*line = textbuffer_insert(buffer, *line, data, pos, NULL);
|
||||
|
||||
gui->last_flags = flags;
|
||||
gui->last_color = fg | (bg << 4);
|
||||
last_flags = flags;
|
||||
last_color = fg | (bg << 4);
|
||||
}
|
||||
|
||||
static void view_add_eol(TEXT_BUFFER_VIEW_REC *view, LINE_REC **line)
|
||||
{
|
||||
static const unsigned char eol[] = { 0, LINE_CMD_EOL };
|
||||
|
||||
*line = textbuffer_insert(view->buffer, *line, eol, 2, NULL);
|
||||
textbuffer_view_insert_line(view, *line);
|
||||
}
|
||||
|
||||
static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
|
||||
void *bgcolor, void *pflags,
|
||||
char *str, void *level)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
LINE_REC *line;
|
||||
int fg, bg, flags, new_lines, n, visible, ypos, subline;
|
||||
TEXT_BUFFER_VIEW_REC *view;
|
||||
LINE_REC *insert_after;
|
||||
LINE_INFO_REC lineinfo;
|
||||
int fg, bg, flags;
|
||||
|
||||
flags = GPOINTER_TO_INT(pflags);
|
||||
fg = GPOINTER_TO_INT(fgcolor);
|
||||
bg = GPOINTER_TO_INT(bgcolor);
|
||||
get_colors(flags, &fg, &bg);
|
||||
|
||||
if (window == NULL && next_xpos != -1) {
|
||||
if (window == NULL) {
|
||||
g_return_if_fail(next_xpos != -1);
|
||||
|
||||
wmove(stdscr, next_ypos, next_xpos);
|
||||
set_color(stdscr, fg | (bg << 4));
|
||||
addstr(str);
|
||||
@ -396,159 +172,34 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
|
||||
return;
|
||||
}
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
lineinfo.level = GPOINTER_TO_INT(level);
|
||||
lineinfo.time = time(NULL);
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
visible = is_window_visible(window) && gui->bottom;
|
||||
view = WINDOW_GUI(window)->view;
|
||||
insert_after = WINDOW_GUI(window)->use_insert_after ?
|
||||
WINDOW_GUI(window)->insert_after : view->buffer->cur_line;
|
||||
|
||||
if (gui->cur_text == NULL)
|
||||
create_text_chunk(gui);
|
||||
|
||||
/* newline can be only at the start of the line.. */
|
||||
if (flags & PRINTFLAG_NEWLINE) {
|
||||
remove_old_lines(window);
|
||||
if (!gui->eol_marked) {
|
||||
if (format->len > 0 || gui->temp_line != NULL) {
|
||||
/* mark format continuing to next line */
|
||||
char tmp[2] = { 0, (char)LINE_CMD_FORMAT_CONT };
|
||||
linebuf_add(gui, tmp, 2);
|
||||
}
|
||||
linebuf_add(gui, "\0\200", 2); /* mark EOL */
|
||||
}
|
||||
gui->eol_marked = FALSE;
|
||||
|
||||
line = create_line(gui, 0);
|
||||
if (gui->temp_line == NULL ||
|
||||
g_list_find(gui->startline, gui->temp_line) != NULL)
|
||||
gui_window_newline(gui, visible);
|
||||
|
||||
gui->last_subline = 0;
|
||||
} else {
|
||||
line = gui->temp_line != NULL ? gui->temp_line :
|
||||
gui->cur_line != NULL ? gui->cur_line :
|
||||
create_line(gui, 0);
|
||||
if (line->level == 0) line->level = GPOINTER_TO_INT(level);
|
||||
}
|
||||
|
||||
line_add_colors(gui, fg, bg, flags);
|
||||
linebuf_add(gui, str, strlen(str));
|
||||
mark_temp_eol(gui->cur_text);
|
||||
|
||||
gui_window_cache_remove(gui, line);
|
||||
|
||||
if (gui->temp_line != NULL) {
|
||||
/* updating existing line - don't even
|
||||
try to print it to screen */
|
||||
return;
|
||||
}
|
||||
|
||||
new_lines = gui_window_get_linecount(gui, line)-1 - gui->last_subline;
|
||||
|
||||
for (n = 0; n < new_lines; n++)
|
||||
gui_window_newline(gui, visible);
|
||||
|
||||
if (visible) {
|
||||
/* draw the line to screen. */
|
||||
ypos = gui->ypos-new_lines;
|
||||
if (new_lines > 0) {
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
set_color(gui->parent->curses_win, 0);
|
||||
wmove(gui->parent->curses_win, ypos, 0);
|
||||
wclrtoeol(gui->parent->curses_win);
|
||||
#else
|
||||
set_color(stdscr, 0);
|
||||
move(ypos + gui->parent->first_line, 0);
|
||||
wclrtoeol(stdscr);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ypos >= 0)
|
||||
subline = gui->last_subline;
|
||||
else {
|
||||
/* *LONG* line - longer than screen height */
|
||||
subline = -ypos+gui->last_subline;
|
||||
ypos = 0;
|
||||
}
|
||||
gui_window_line_draw(gui, line, ypos, subline, -1);
|
||||
}
|
||||
|
||||
gui->last_subline += new_lines;
|
||||
}
|
||||
|
||||
static void window_clear_screen(GUI_WINDOW_REC *gui)
|
||||
{
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
wclear(gui->parent->curses_win);
|
||||
screen_refresh(gui->parent->curses_win);
|
||||
#else
|
||||
int n;
|
||||
|
||||
for (n = gui->parent->first_line; n < gui->parent->last_line; n++) {
|
||||
move(n, 0);
|
||||
clrtoeol();
|
||||
}
|
||||
screen_refresh(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void window_clear(WINDOW_REC *window)
|
||||
{
|
||||
GUI_WINDOW_REC *gui = WINDOW_GUI(window);
|
||||
|
||||
if (is_window_visible(window))
|
||||
window_clear_screen(gui);
|
||||
|
||||
gui->ypos = -1;
|
||||
gui->bottom_startline = gui->startline = g_list_last(gui->lines);
|
||||
gui->bottom_subline = gui->subline = gui->last_subline+1;
|
||||
gui->empty_linecount = gui->parent->lines;
|
||||
gui->bottom = TRUE;
|
||||
}
|
||||
|
||||
/* SYNTAX: CLEAR */
|
||||
static void cmd_clear(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
void *free_arg;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, PARAM_FLAG_OPTIONS,
|
||||
"clear", &optlist)) return;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "all") != NULL)
|
||||
g_slist_foreach(windows, (GFunc) window_clear, NULL);
|
||||
else
|
||||
window_clear(active_win);
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
if (flags & PRINTFLAG_NEWLINE)
|
||||
view_add_eol(view, &insert_after);
|
||||
line_add_colors(view->buffer, &insert_after, fg, bg, flags);
|
||||
textbuffer_insert(view->buffer, insert_after,
|
||||
str, strlen(str), &lineinfo);
|
||||
}
|
||||
|
||||
static void sig_printtext_finished(WINDOW_REC *window)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
TEXT_BUFFER_VIEW_REC *view;
|
||||
LINE_REC *insert_after;
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
if (gui->cur_line == NULL)
|
||||
return;
|
||||
last_color = 0;
|
||||
last_flags = 0;
|
||||
|
||||
if (format->len > 0) {
|
||||
/* save format of the line */
|
||||
linebuf_add(gui, format->str, format->len);
|
||||
view = WINDOW_GUI(window)->view;
|
||||
insert_after = WINDOW_GUI(window)->use_insert_after ?
|
||||
WINDOW_GUI(window)->insert_after : view->buffer->cur_line;
|
||||
|
||||
g_string_truncate(format, 0);
|
||||
}
|
||||
|
||||
linebuf_add(gui, "\0\200", 2); /* mark EOL */
|
||||
gui->eol_marked = TRUE;
|
||||
|
||||
if (is_window_visible(window)) {
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
screen_refresh(gui->parent->curses_win);
|
||||
#else
|
||||
screen_refresh(NULL);
|
||||
#endif
|
||||
}
|
||||
view_add_eol(view, &insert_after);
|
||||
remove_old_lines(view);
|
||||
}
|
||||
|
||||
static void sig_print_format(THEME_REC *theme, const char *module,
|
||||
@ -589,6 +240,7 @@ static void read_settings(void)
|
||||
{
|
||||
scrollback_lines = settings_get_int("scrollback_lines");
|
||||
scrollback_hours = settings_get_int("scrollback_hours");
|
||||
scrollback_burst_remove = settings_get_int("scrollback_burst_remove");
|
||||
scrollback_save_formats = settings_get_bool("scrollback_save_formats");
|
||||
}
|
||||
|
||||
@ -599,6 +251,7 @@ void gui_printtext_init(void)
|
||||
|
||||
settings_add_int("history", "scrollback_lines", 500);
|
||||
settings_add_int("history", "scrollback_hours", 24);
|
||||
settings_add_int("history", "scrollback_burst_remove", 10);
|
||||
settings_add_bool("history", "scrollback_save_formats", FALSE);
|
||||
|
||||
signal_add("gui print text", (SIGNAL_FUNC) sig_gui_print_text);
|
||||
@ -606,8 +259,6 @@ void gui_printtext_init(void)
|
||||
signal_add("print format", (SIGNAL_FUNC) sig_print_format);
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
signal_add("beep", (SIGNAL_FUNC) beep);
|
||||
command_bind("clear", NULL, (SIGNAL_FUNC) cmd_clear);
|
||||
command_set_options("clear", "all");
|
||||
|
||||
read_settings();
|
||||
}
|
||||
@ -621,5 +272,4 @@ void gui_printtext_deinit(void)
|
||||
signal_remove("print format", (SIGNAL_FUNC) sig_print_format);
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
signal_remove("beep", (SIGNAL_FUNC) beep);
|
||||
command_unbind("clear", (SIGNAL_FUNC) cmd_clear);
|
||||
}
|
||||
|
@ -8,10 +8,6 @@ extern int mirc_colors[];
|
||||
void gui_printtext_init(void);
|
||||
void gui_printtext_deinit(void);
|
||||
|
||||
void gui_window_line_append(GUI_WINDOW_REC *gui, const char *str, int len);
|
||||
void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line, int redraw);
|
||||
void gui_window_line_text_free(GUI_WINDOW_REC *gui, LINE_REC *line);
|
||||
|
||||
void gui_printtext(int xpos, int ypos, const char *str);
|
||||
|
||||
#endif
|
||||
|
@ -101,7 +101,7 @@ static int get_scroll_count(void)
|
||||
count = 1.0/count;
|
||||
|
||||
if (*str == '/')
|
||||
count = WINDOW_GUI(active_win)->parent->lines/count;
|
||||
count = WINDOW_GUI(active_win)->parent->height/count;
|
||||
return (int)count;
|
||||
}
|
||||
|
||||
|
@ -1,282 +0,0 @@
|
||||
/*
|
||||
gui-textwidget.c : irssi
|
||||
|
||||
Copyright (C) 1999-2001 Timo Sirainen
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "levels.h"
|
||||
|
||||
#include "printtext.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
static void cmd_scrollback(gchar *data, SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
command_runsub("scrollback", data, server, item);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK CLEAR */
|
||||
static void cmd_scrollback_clear(gchar *data)
|
||||
{
|
||||
gui_window_clear(active_win);
|
||||
}
|
||||
|
||||
static void scrollback_goto_pos(WINDOW_REC *window, GList *pos)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
g_return_if_fail(pos != NULL);
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
|
||||
if (g_list_find(gui->bottom_startline, pos->data) == NULL) {
|
||||
gui->startline = pos;
|
||||
gui->subline = 0;
|
||||
gui_window_update_ypos(gui);
|
||||
gui->bottom = is_window_bottom(gui);
|
||||
} else {
|
||||
/* reached the last line */
|
||||
if (gui->bottom) return;
|
||||
|
||||
gui->startline = gui->bottom_startline;
|
||||
gui->subline = gui->bottom_subline;
|
||||
gui->ypos = gui->parent->lines-1;
|
||||
gui->bottom = TRUE;
|
||||
}
|
||||
|
||||
if (is_window_visible(window))
|
||||
gui_window_redraw(window);
|
||||
signal_emit("gui page scrolled", 1, window);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK GOTO <+|-linecount>|<linenum>|<timestamp> */
|
||||
static void cmd_scrollback_goto(gchar *data)
|
||||
{
|
||||
GList *pos;
|
||||
gchar *arg1, *arg2;
|
||||
void *free_arg;
|
||||
gint lines;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 2, &arg1, &arg2))
|
||||
return;
|
||||
if (*arg2 == '\0' && (*arg1 == '-' || *arg1 == '+'))
|
||||
{
|
||||
/* go forward/backward n lines */
|
||||
if (sscanf(arg1 + (*arg1 == '-' ? 0 : 1), "%d", &lines) == 1)
|
||||
gui_window_scroll(active_win, lines);
|
||||
}
|
||||
else if (*arg2 == '\0' && strchr(arg1, ':') == NULL && strchr(arg1, '.') == NULL &&
|
||||
sscanf(arg1, "%d", &lines) == 1)
|
||||
{
|
||||
/* go to n'th line. */
|
||||
pos = g_list_nth(WINDOW_GUI(active_win)->lines, lines);
|
||||
if (pos != NULL)
|
||||
scrollback_goto_pos(active_win, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct tm tm;
|
||||
time_t stamp;
|
||||
gint day, month;
|
||||
|
||||
/* [dd.mm | -<days ago>] hh:mi[:ss] */
|
||||
stamp = time(NULL);
|
||||
if (*arg1 == '-')
|
||||
{
|
||||
/* -<days ago> */
|
||||
if (sscanf(arg1+1, "%d", &day) == 1)
|
||||
stamp -= day*3600*24;
|
||||
memcpy(&tm, localtime(&stamp), sizeof(struct tm));
|
||||
}
|
||||
else if (*arg2 != '\0')
|
||||
{
|
||||
/* dd.mm */
|
||||
if (sscanf(arg1, "%d.%d", &day, &month) == 2)
|
||||
{
|
||||
month--;
|
||||
memcpy(&tm, localtime(&stamp), sizeof(struct tm));
|
||||
|
||||
if (tm.tm_mon < month)
|
||||
tm.tm_year--;
|
||||
tm.tm_mon = month;
|
||||
tm.tm_mday = day;
|
||||
stamp = mktime(&tm);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* move time argument to arg2 */
|
||||
arg2 = arg1;
|
||||
}
|
||||
|
||||
/* hh:mi[:ss] */
|
||||
memcpy(&tm, localtime(&stamp), sizeof(struct tm));
|
||||
tm.tm_sec = 0;
|
||||
sscanf(arg2, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
|
||||
stamp = mktime(&tm);
|
||||
|
||||
if (stamp > time(NULL) && arg1 == arg2) {
|
||||
/* we used /SB GOTO 23:59 or something, we want to jump to
|
||||
previous day's 23:59 time instead of into future. */
|
||||
stamp -= 3600*24;
|
||||
}
|
||||
|
||||
if (stamp > time(NULL)) {
|
||||
/* we're still looking into future, don't bother checking */
|
||||
cmd_params_free(free_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* find the first line after timestamp */
|
||||
for (pos = WINDOW_GUI(active_win)->lines; pos != NULL; pos = pos->next)
|
||||
{
|
||||
LINE_REC *rec = pos->data;
|
||||
|
||||
if (rec->time >= stamp)
|
||||
{
|
||||
scrollback_goto_pos(active_win, pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK HOME */
|
||||
static void cmd_scrollback_home(const char *data)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
|
||||
gui = WINDOW_GUI(active_win);
|
||||
|
||||
if (gui->startline == gui->lines)
|
||||
return;
|
||||
|
||||
gui->startline = gui->lines;
|
||||
gui->subline = 0;
|
||||
gui_window_update_ypos(gui);
|
||||
gui->bottom = is_window_bottom(gui);
|
||||
|
||||
if (is_window_visible(active_win))
|
||||
gui_window_redraw(active_win);
|
||||
signal_emit("gui page scrolled", 1, active_win);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK END */
|
||||
static void cmd_scrollback_end(const char *data)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
|
||||
gui = WINDOW_GUI(active_win);
|
||||
if (gui->bottom)
|
||||
return;
|
||||
|
||||
gui->startline = gui->bottom_startline;
|
||||
gui->subline = gui->bottom_subline;
|
||||
gui->ypos = gui->parent->lines-1;
|
||||
gui->bottom = TRUE;
|
||||
|
||||
if (is_window_visible(active_win))
|
||||
gui_window_redraw(active_win);
|
||||
signal_emit("gui page scrolled", 1, active_win);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK REDRAW */
|
||||
static void cmd_scrollback_redraw(void)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
GList *tmp, *next;
|
||||
|
||||
gui = WINDOW_GUI(active_win);
|
||||
|
||||
screen_refresh_freeze();
|
||||
for (tmp = gui->lines; tmp != NULL; tmp = next) {
|
||||
next = tmp->next;
|
||||
gui_window_reformat_line(active_win, tmp->data);
|
||||
}
|
||||
|
||||
gui_window_redraw(active_win);
|
||||
screen_refresh_thaw();
|
||||
}
|
||||
|
||||
static void cmd_scrollback_status(void)
|
||||
{
|
||||
GSList *tmp;
|
||||
int window_kb, total_lines, total_kb;
|
||||
|
||||
total_lines = 0; total_kb = 0;
|
||||
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *window = tmp->data;
|
||||
GUI_WINDOW_REC *gui = WINDOW_GUI(window);
|
||||
|
||||
window_kb = g_slist_length(gui->text_chunks)*
|
||||
LINE_TEXT_CHUNK_SIZE/1024;
|
||||
total_lines += window->lines;
|
||||
total_kb += window_kb;
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
||||
"Window %d: %d lines, %dkB of data",
|
||||
window->refnum, window->lines, window_kb);
|
||||
}
|
||||
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
||||
"Total: %d lines, %dkB of data",
|
||||
total_lines, total_kb);
|
||||
}
|
||||
|
||||
static void sig_away_changed(SERVER_REC *server)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
if (!server->usermode_away)
|
||||
return;
|
||||
|
||||
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *rec = tmp->data;
|
||||
|
||||
WINDOW_GUI(rec)->lastlog_last_away =
|
||||
g_list_last(WINDOW_GUI(rec)->bottom_startline);
|
||||
}
|
||||
}
|
||||
|
||||
void gui_textwidget_init(void)
|
||||
{
|
||||
command_bind("scrollback", NULL, (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_bind("scrollback clear", NULL, (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_bind("scrollback goto", NULL, (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
command_bind("scrollback home", NULL, (SIGNAL_FUNC) cmd_scrollback_home);
|
||||
command_bind("scrollback end", NULL, (SIGNAL_FUNC) cmd_scrollback_end);
|
||||
command_bind("scrollback redraw", NULL, (SIGNAL_FUNC) cmd_scrollback_redraw);
|
||||
command_bind("scrollback status", NULL, (SIGNAL_FUNC) cmd_scrollback_status);
|
||||
|
||||
signal_add("away mode changed", (SIGNAL_FUNC) sig_away_changed);
|
||||
}
|
||||
|
||||
void gui_textwidget_deinit(void)
|
||||
{
|
||||
command_unbind("scrollback", (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_unbind("scrollback clear", (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_unbind("scrollback goto", (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
command_unbind("scrollback home", (SIGNAL_FUNC) cmd_scrollback_home);
|
||||
command_unbind("scrollback end", (SIGNAL_FUNC) cmd_scrollback_end);
|
||||
command_unbind("scrollback redraw", (SIGNAL_FUNC) cmd_scrollback_redraw);
|
||||
command_unbind("scrollback status", (SIGNAL_FUNC) cmd_scrollback_status);
|
||||
|
||||
signal_remove("away mode changed", (SIGNAL_FUNC) sig_away_changed);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,94 +1,20 @@
|
||||
#ifndef __GUI_WINDOWS_H
|
||||
#define __GUI_WINDOWS_H
|
||||
|
||||
#include "servers.h"
|
||||
#include "mainwindows.h"
|
||||
#include "textbuffer-view.h"
|
||||
|
||||
#define WINDOW_GUI(a) ((GUI_WINDOW_REC *) ((a)->gui_data))
|
||||
|
||||
#define is_window_visible(win) \
|
||||
(WINDOW_GUI(win)->parent->active == (win))
|
||||
|
||||
#define LINE_TEXT_CHUNK_SIZE 2048
|
||||
|
||||
/* 7 first bits of LINE_REC's info byte. */
|
||||
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_COLOR8, /* change to dark grey, normally 8 = bold black */
|
||||
LINE_CMD_UNDERLINE, /* enable/disable underlining */
|
||||
LINE_CMD_INDENT, /* if line is split, indent it at this position */
|
||||
LINE_CMD_BLINK, /* blinking background */
|
||||
LINE_CMD_FORMAT, /* end of line, but next will come the format that was used to create the
|
||||
text in format <module><format_name><arg><arg2...> - fields are separated
|
||||
with \0<format> and last argument ends with \0<eol>. \0<continue> is allowed
|
||||
anywhere */
|
||||
LINE_CMD_FORMAT_CONT /* multiline format, continues to next line */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *start;
|
||||
int indent;
|
||||
int color;
|
||||
unsigned int continues:1; /* first word in line belong to the end of the last word in previous line */
|
||||
} LINE_CACHE_SUB_REC;
|
||||
|
||||
typedef struct {
|
||||
time_t last_access;
|
||||
|
||||
int count; /* number of real lines */
|
||||
LINE_CACHE_SUB_REC *lines;
|
||||
} LINE_CACHE_REC;
|
||||
|
||||
typedef struct {
|
||||
/* text in the line. \0 means that the next char will be a
|
||||
color or command. <= 127 = color or if 8.bit is set, the
|
||||
first 7 bits are the command. See LINE_CMD_xxxx.
|
||||
|
||||
DO NOT ADD BLACK WITH \0\0 - this will break things. Use
|
||||
LINE_CMD_COLOR0 instead. */
|
||||
char *text;
|
||||
|
||||
int level;
|
||||
time_t time;
|
||||
} LINE_REC;
|
||||
|
||||
typedef struct {
|
||||
char buffer[LINE_TEXT_CHUNK_SIZE];
|
||||
int pos;
|
||||
int lines;
|
||||
} TEXT_CHUNK_REC;
|
||||
|
||||
typedef struct {
|
||||
MAIN_WINDOW_REC *parent;
|
||||
TEXT_BUFFER_VIEW_REC *view;
|
||||
|
||||
GMemChunk *line_chunk;
|
||||
GSList *text_chunks;
|
||||
GList *lines;
|
||||
GHashTable *line_cache;
|
||||
|
||||
LINE_REC *cur_line, *temp_line;
|
||||
TEXT_CHUNK_REC *cur_text;
|
||||
|
||||
int xpos, ypos; /* cursor position in screen */
|
||||
GList *startline; /* line at the top of the screen */
|
||||
int subline; /* number of "real lines" to skip from `startline' */
|
||||
|
||||
GList *bottom_startline; /* marks the bottom of the text buffer */
|
||||
int bottom_subline;
|
||||
int empty_linecount; /* how many empty lines are in screen.
|
||||
a screenful when started or used /CLEAR */
|
||||
unsigned int bottom:1; /* window is at the bottom of the text buffer */
|
||||
unsigned int eol_marked:1; /* last line marked for eol */
|
||||
|
||||
/* For /LAST -new and -away */
|
||||
GList *lastlog_last_check;
|
||||
GList *lastlog_last_away;
|
||||
|
||||
/* for gui-printtext.c */
|
||||
int last_subline;
|
||||
int last_color, last_flags;
|
||||
unsigned int use_insert_after:1;
|
||||
LINE_REC *insert_after;
|
||||
} GUI_WINDOW_REC;
|
||||
|
||||
void gui_windows_init(void);
|
||||
@ -96,30 +22,15 @@ void gui_windows_deinit(void);
|
||||
|
||||
WINDOW_REC *gui_window_create(MAIN_WINDOW_REC *parent);
|
||||
|
||||
void gui_window_set_server(WINDOW_REC *window, SERVER_REC *server);
|
||||
|
||||
void gui_window_line2text(LINE_REC *line, int coloring, GString *str);
|
||||
GList *gui_window_find_text(WINDOW_REC *window, GList *startline,
|
||||
int level, int nolevel, const char *text,
|
||||
int regexp, int fullword, int case_sensitive);
|
||||
|
||||
/* get number of real lines that line record takes */
|
||||
int gui_window_get_linecount(GUI_WINDOW_REC *gui, LINE_REC *line);
|
||||
void gui_window_cache_remove(GUI_WINDOW_REC *gui, LINE_REC *line);
|
||||
int gui_window_line_draw(GUI_WINDOW_REC *gui, LINE_REC *line, int ypos, int skip, int max);
|
||||
|
||||
void gui_window_clear(WINDOW_REC *window);
|
||||
void gui_window_redraw(WINDOW_REC *window);
|
||||
void gui_window_reformat_line(WINDOW_REC *window, LINE_REC *line);
|
||||
void gui_window_resize(WINDOW_REC *window, int ychange, int xchange);
|
||||
void gui_window_resize(WINDOW_REC *window, int width, int height);
|
||||
void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent);
|
||||
|
||||
#define is_window_bottom(gui) \
|
||||
((gui)->ypos >= -1 && (gui)->ypos <= (gui)->parent->last_line-(gui)->parent->first_line)
|
||||
#define gui_window_redraw(window) \
|
||||
textbuffer_view_redraw(WINDOW_GUI(window)->view)
|
||||
|
||||
void gui_window_scroll(WINDOW_REC *window, int lines);
|
||||
void gui_window_scroll_line(WINDOW_REC *window, LINE_REC *line);
|
||||
|
||||
void window_update_prompt(void);
|
||||
void gui_window_newline(GUI_WINDOW_REC *gui, int visible);
|
||||
void gui_window_scroll(WINDOW_REC *window, int lines);
|
||||
void gui_window_update_ypos(GUI_WINDOW_REC *gui);
|
||||
|
||||
#endif
|
||||
|
@ -55,8 +55,8 @@ void irc_deinit(void);
|
||||
void gui_expandos_init(void);
|
||||
void gui_expandos_deinit(void);
|
||||
|
||||
void gui_textwidget_init(void);
|
||||
void gui_textwidget_deinit(void);
|
||||
void textbuffer_commands_init(void);
|
||||
void textbuffer_commands_deinit(void);
|
||||
|
||||
void lastlog_init(void);
|
||||
void lastlog_deinit(void);
|
||||
@ -124,11 +124,13 @@ static void textui_finish_init(void)
|
||||
quitting = FALSE;
|
||||
|
||||
screen_refresh_freeze();
|
||||
textbuffer_init();
|
||||
textbuffer_view_init();
|
||||
textbuffer_commands_init();
|
||||
gui_entry_init();
|
||||
gui_expandos_init();
|
||||
gui_printtext_init();
|
||||
gui_readline_init();
|
||||
gui_textwidget_init();
|
||||
lastlog_init();
|
||||
mainwindows_init();
|
||||
mainwindow_activity_init();
|
||||
@ -165,7 +167,6 @@ static void textui_deinit(void)
|
||||
|
||||
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
|
||||
|
||||
gui_textwidget_deinit();
|
||||
lastlog_deinit();
|
||||
statusbar_deinit();
|
||||
gui_printtext_deinit();
|
||||
@ -176,6 +177,9 @@ static void textui_deinit(void)
|
||||
mainwindows_deinit();
|
||||
gui_expandos_deinit();
|
||||
gui_entry_deinit();
|
||||
textbuffer_commands_deinit();
|
||||
textbuffer_view_deinit();
|
||||
textbuffer_deinit();
|
||||
|
||||
screen_refresh_thaw();
|
||||
deinit_screen();
|
||||
|
@ -35,16 +35,20 @@
|
||||
|
||||
static void window_lastlog_clear(WINDOW_REC *window)
|
||||
{
|
||||
TEXT_BUFFER_VIEW_REC *view;
|
||||
GList *tmp, *next;
|
||||
|
||||
for (tmp = WINDOW_GUI(window)->lines; tmp != NULL; tmp = next) {
|
||||
screen_refresh_freeze();
|
||||
view = WINDOW_GUI(window)->view;
|
||||
for (tmp = textbuffer_view_get_lines(view); tmp != NULL; tmp = next) {
|
||||
LINE_REC *line = tmp->data;
|
||||
|
||||
next = tmp->next;
|
||||
if (line->level & MSGLEVEL_LASTLOG)
|
||||
gui_window_line_remove(window, line, FALSE);
|
||||
if (line->info.level & MSGLEVEL_LASTLOG)
|
||||
textbuffer_view_remove_line(view, line);
|
||||
}
|
||||
gui_window_redraw(window);
|
||||
screen_refresh_thaw();
|
||||
//gui_window_redraw(window);
|
||||
}
|
||||
|
||||
/* Only unknown keys in `optlist' should be levels.
|
||||
@ -89,8 +93,9 @@ int cmd_options_get_level(const char *cmd, GHashTable *optlist)
|
||||
static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
||||
int start, int count, int fhandle)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
GList *startline, *list, *tmp;
|
||||
WINDOW_REC *window;
|
||||
LINE_REC *startline;
|
||||
GList *list, *tmp;
|
||||
GString *line;
|
||||
char *str;
|
||||
int level, len;
|
||||
@ -120,14 +125,18 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(optlist, "new") != NULL)
|
||||
startline = WINDOW_GUI(window)->lastlog_last_check;
|
||||
startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_check");
|
||||
else if (g_hash_table_lookup(optlist, "away") != NULL)
|
||||
startline = WINDOW_GUI(window)->lastlog_last_away;
|
||||
startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_away");
|
||||
else
|
||||
startline = NULL;
|
||||
if (startline == NULL) startline = WINDOW_GUI(window)->lines;
|
||||
|
||||
list = gui_window_find_text(window, startline,
|
||||
if (startline == NULL) {
|
||||
list = textbuffer_view_get_lines(WINDOW_GUI(window)->view);
|
||||
startline = list == NULL ? NULL : list->data;
|
||||
}
|
||||
|
||||
list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline,
|
||||
level, MSGLEVEL_LASTLOG,
|
||||
searchtext,
|
||||
g_hash_table_lookup(optlist, "regexp") != NULL,
|
||||
@ -163,9 +172,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
/* get the line text */
|
||||
gui_window_line2text(rec, fhandle == -1, line);
|
||||
textbuffer_line2text(rec, fhandle == -1, line);
|
||||
if (!settings_get_bool("timestamps")) {
|
||||
struct tm *tm = localtime(&rec->time);
|
||||
struct tm *tm = localtime(&rec->info.time);
|
||||
char timestamp[10];
|
||||
|
||||
g_snprintf(timestamp, sizeof(timestamp),
|
||||
@ -191,9 +200,10 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
||||
if (fhandle == -1 && g_hash_table_lookup(optlist, "-") == NULL)
|
||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END);
|
||||
|
||||
WINDOW_GUI(window)->lastlog_last_check =
|
||||
g_list_last(WINDOW_GUI(window)->bottom_startline);
|
||||
textbuffer_view_set_bookmark_bottom(WINDOW_GUI(window)->view,
|
||||
"lastlog_last_check");
|
||||
|
||||
textbuffer_line_unref_list(WINDOW_GUI(window)->view->buffer, list);
|
||||
g_list_free(list);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ static void main_window_save(MAIN_WINDOW_REC *window, CONFIG_NODE *node)
|
||||
node = config_node_section(node, num, NODE_TYPE_BLOCK);
|
||||
|
||||
iconfig_node_set_int(node, "first_line", window->first_line);
|
||||
iconfig_node_set_int(node, "lines", window->lines);
|
||||
iconfig_node_set_int(node, "lines", window->height);
|
||||
|
||||
str = g_string_new(NULL);
|
||||
for (tmp = window->sticky_windows; tmp != NULL; tmp = tmp->next) {
|
||||
@ -141,7 +141,7 @@ static void sig_windows_restored(void)
|
||||
active_mainwin = NULL;
|
||||
window_set_active(window);
|
||||
|
||||
if (lowerwin->lines > WINDOW_MIN_SIZE)
|
||||
if (lowerwin->height > WINDOW_MIN_SIZE)
|
||||
mainwindow_set_size(lowerwin, WINDOW_MIN_SIZE);
|
||||
count--;
|
||||
|
||||
|
@ -36,6 +36,7 @@ GSList *mainwindows;
|
||||
MAIN_WINDOW_REC *active_mainwin;
|
||||
|
||||
static int reserved_up, reserved_down;
|
||||
static int screen_width, screen_height;
|
||||
|
||||
static MAIN_WINDOW_REC *find_window_with_room(void)
|
||||
{
|
||||
@ -47,7 +48,7 @@ static MAIN_WINDOW_REC *find_window_with_room(void)
|
||||
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
space = rec->lines;
|
||||
space = rec->height;
|
||||
if (space >= WINDOW_MIN_SIZE+NEW_WINDOW_SIZE && space > biggest) {
|
||||
biggest = space;
|
||||
biggest_rec = rec;
|
||||
@ -60,21 +61,24 @@ static MAIN_WINDOW_REC *find_window_with_room(void)
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
static void create_curses_window(MAIN_WINDOW_REC *window)
|
||||
{
|
||||
window->curses_win = newwin(window->lines, COLS, window->first_line, 0);
|
||||
window->curses_win = newwin(window->height, window->width,
|
||||
window->first_line, 0);
|
||||
idlok(window->curses_win, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void mainwindow_resize(MAIN_WINDOW_REC *window, int ychange, int xchange)
|
||||
static void mainwindow_resize(MAIN_WINDOW_REC *window, int xdiff, int ydiff)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
if (ychange == 0 && !xchange) return;
|
||||
if (xdiff == 0 && ydiff == 0)
|
||||
return;
|
||||
|
||||
window->lines = window->last_line-window->first_line+1;
|
||||
window->width += xdiff;
|
||||
window->height = window->last_line-window->first_line+1;
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
#ifdef HAVE_CURSES_WRESIZE
|
||||
wresize(window->curses_win, window->lines, COLS);
|
||||
wresize(window->curses_win, window->height, window->width);
|
||||
mvwin(window->curses_win, window->first_line, 0);
|
||||
#else
|
||||
delwin(window->curses_win);
|
||||
@ -87,10 +91,11 @@ static void mainwindow_resize(MAIN_WINDOW_REC *window, int ychange, int xchange)
|
||||
|
||||
if (rec->gui_data != NULL &&
|
||||
WINDOW_GUI(rec)->parent == window)
|
||||
gui_window_resize(rec, ychange, xchange);
|
||||
gui_window_resize(rec, window->width, window->height);
|
||||
}
|
||||
|
||||
gui_window_redraw(window->active);
|
||||
textbuffer_view_set_window(WINDOW_GUI(window->active)->view,
|
||||
window->curses_win);
|
||||
signal_emit("mainwindow resized", 1, window);
|
||||
}
|
||||
|
||||
@ -104,7 +109,8 @@ void mainwindows_recreate(void)
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
create_curses_window(rec);
|
||||
#endif
|
||||
gui_window_redraw(rec->active);
|
||||
textbuffer_view_set_window(WINDOW_GUI(rec->active)->view,
|
||||
rec->curses_win);
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,27 +126,29 @@ MAIN_WINDOW_REC *mainwindow_create(void)
|
||||
active_mainwin = rec;
|
||||
|
||||
rec->first_line = reserved_up;
|
||||
rec->last_line = LINES-1-reserved_down-rec->statusbar_lines;
|
||||
rec->lines = rec->last_line-rec->first_line+1;
|
||||
rec->last_line = screen_height-1 -
|
||||
reserved_down-rec->statusbar_lines;
|
||||
rec->width = screen_width;
|
||||
rec->height = rec->last_line-rec->first_line+1;
|
||||
} else {
|
||||
parent = WINDOW_GUI(active_win)->parent;
|
||||
if (parent->lines < WINDOW_MIN_SIZE+NEW_WINDOW_SIZE)
|
||||
if (parent->height < WINDOW_MIN_SIZE+NEW_WINDOW_SIZE)
|
||||
parent = find_window_with_room();
|
||||
if (parent == NULL)
|
||||
return NULL; /* not enough space */
|
||||
|
||||
space = (parent->lines-parent->statusbar_lines)/2;
|
||||
space = (parent->height-parent->statusbar_lines)/2;
|
||||
rec->first_line = parent->first_line;
|
||||
rec->last_line = rec->first_line + space-rec->statusbar_lines;
|
||||
rec->lines = rec->last_line-rec->first_line+1;
|
||||
rec->height = rec->last_line-rec->first_line+1;
|
||||
parent->first_line = rec->last_line+1+rec->statusbar_lines;
|
||||
parent->lines = parent->last_line-parent->first_line+1;
|
||||
parent->height = parent->last_line-parent->first_line+1;
|
||||
|
||||
mainwindow_resize(parent, -space-1, FALSE);
|
||||
mainwindow_resize(parent, 0, -space-1);
|
||||
}
|
||||
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
rec->curses_win = newwin(rec->lines, COLS, rec->first_line, 0);
|
||||
rec->curses_win = newwin(rec->height, rec->width, rec->first_line, 0);
|
||||
refresh();
|
||||
#endif
|
||||
|
||||
@ -196,14 +204,14 @@ static void mainwindows_add_space(int first_line, int last_line)
|
||||
rec = mainwindows_find_lower(last_line);
|
||||
if (rec != NULL) {
|
||||
rec->first_line = first_line;
|
||||
mainwindow_resize(rec, size, FALSE);
|
||||
mainwindow_resize(rec, 0, size);
|
||||
return;
|
||||
}
|
||||
|
||||
rec = mainwindows_find_upper(first_line);
|
||||
if (rec != NULL) {
|
||||
rec->last_line = last_line-rec->statusbar_lines;
|
||||
mainwindow_resize(rec, size, FALSE);
|
||||
mainwindow_resize(rec, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +288,7 @@ GSList *mainwindows_get_sorted(int reverse)
|
||||
return list;
|
||||
}
|
||||
|
||||
static void mainwindows_resize_too_small(int ychange, int xchange)
|
||||
static void mainwindows_resize_too_small(int xdiff, int ydiff)
|
||||
{
|
||||
GSList *sorted, *tmp;
|
||||
int space, moved;
|
||||
@ -291,8 +299,8 @@ static void mainwindows_resize_too_small(int ychange, int xchange)
|
||||
for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
space = rec->lines;
|
||||
if (ychange == 0 || space <= 0) {
|
||||
space = rec->height;
|
||||
if (ydiff == 0 || space <= 0) {
|
||||
if (moved > 0) {
|
||||
rec->first_line -= moved;
|
||||
rec->last_line -= moved;
|
||||
@ -301,17 +309,17 @@ static void mainwindows_resize_too_small(int ychange, int xchange)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (space > -ychange) space = -ychange;
|
||||
ychange += space;
|
||||
if (space > -ydiff) space = -ydiff;
|
||||
ydiff += space;
|
||||
rec->first_line -= moved;
|
||||
moved += space;
|
||||
rec->last_line -= space;
|
||||
mainwindow_resize(rec, -space, xchange);
|
||||
mainwindow_resize(rec, xdiff, -space);
|
||||
}
|
||||
g_slist_free(sorted);
|
||||
}
|
||||
|
||||
static void mainwindows_resize_smaller(int ychange, int xchange)
|
||||
static void mainwindows_resize_smaller(int xdiff, int ydiff)
|
||||
{
|
||||
GSList *sorted, *tmp;
|
||||
int space;
|
||||
@ -320,40 +328,40 @@ static void mainwindows_resize_smaller(int ychange, int xchange)
|
||||
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
space += rec->lines-WINDOW_MIN_SIZE;
|
||||
space += rec->height-WINDOW_MIN_SIZE;
|
||||
}
|
||||
|
||||
if (space < -ychange) {
|
||||
if (space < -ydiff) {
|
||||
/* not enough space, use different algorithm */
|
||||
mainwindows_resize_too_small(ychange, xchange);
|
||||
mainwindows_resize_too_small(xdiff, ydiff);
|
||||
return;
|
||||
}
|
||||
|
||||
/* resize windows that have space */
|
||||
sorted = mainwindows_get_sorted(TRUE);
|
||||
for (tmp = sorted; tmp != NULL && ychange < 0; tmp = tmp->next) {
|
||||
for (tmp = sorted; tmp != NULL && ydiff < 0; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
space = rec->lines-WINDOW_MIN_SIZE;
|
||||
space = rec->height-WINDOW_MIN_SIZE;
|
||||
if (space <= 0) {
|
||||
rec->first_line += ychange;
|
||||
rec->last_line += ychange;
|
||||
rec->first_line += ydiff;
|
||||
rec->last_line += ydiff;
|
||||
signal_emit("mainwindow moved", 1, rec);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (space <= 0) space = 1;
|
||||
if (space > -ychange) space = -ychange;
|
||||
rec->last_line += ychange;
|
||||
ychange += space;
|
||||
rec->first_line += ychange;
|
||||
if (space > -ydiff) space = -ydiff;
|
||||
rec->last_line += ydiff;
|
||||
ydiff += space;
|
||||
rec->first_line += ydiff;
|
||||
|
||||
mainwindow_resize(rec, -space, xchange);
|
||||
mainwindow_resize(rec, xdiff, -space);
|
||||
}
|
||||
g_slist_free(sorted);
|
||||
}
|
||||
|
||||
static void mainwindows_resize_bigger(int ychange, int xchange)
|
||||
static void mainwindows_resize_bigger(int xdiff, int ydiff)
|
||||
{
|
||||
GSList *sorted, *tmp;
|
||||
int moved, space;
|
||||
@ -363,8 +371,8 @@ static void mainwindows_resize_bigger(int ychange, int xchange)
|
||||
for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
space = rec->lines-WINDOW_MIN_SIZE;
|
||||
if (ychange == 0 || (space >= 0 && tmp->next != NULL)) {
|
||||
space = rec->height-WINDOW_MIN_SIZE;
|
||||
if (ydiff == 0 || (space >= 0 && tmp->next != NULL)) {
|
||||
if (moved > 0) {
|
||||
rec->first_line += moved;
|
||||
rec->last_line += moved;
|
||||
@ -376,41 +384,48 @@ static void mainwindows_resize_bigger(int ychange, int xchange)
|
||||
if (space < 0 && tmp->next != NULL) {
|
||||
/* space below minimum */
|
||||
space = -space;
|
||||
if (space > ychange) space = ychange;
|
||||
if (space > ydiff) space = ydiff;
|
||||
} else {
|
||||
/* lowest window - give all the extra space for it */
|
||||
space = ychange;
|
||||
space = ydiff;
|
||||
}
|
||||
ychange -= space;
|
||||
ydiff -= space;
|
||||
rec->first_line += moved;
|
||||
moved += space;
|
||||
rec->last_line += moved;
|
||||
|
||||
mainwindow_resize(rec, space, xchange);
|
||||
mainwindow_resize(rec, xdiff, space);
|
||||
}
|
||||
g_slist_free(sorted);
|
||||
}
|
||||
|
||||
void mainwindows_resize_horiz(int xchange)
|
||||
void mainwindows_resize_horiz(int xdiff)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
mainwindow_resize(rec, 0, xchange);
|
||||
mainwindow_resize(rec, xdiff, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void mainwindows_resize(int ychange, int xchange)
|
||||
void mainwindows_resize(int width, int height)
|
||||
{
|
||||
int xdiff, ydiff;
|
||||
|
||||
xdiff = width-screen_width;
|
||||
ydiff = height-screen_height;
|
||||
screen_width = width;
|
||||
screen_height = height;
|
||||
|
||||
screen_refresh_freeze();
|
||||
if (ychange < 0)
|
||||
mainwindows_resize_smaller(ychange, xchange);
|
||||
else if (ychange > 0)
|
||||
mainwindows_resize_bigger(ychange, xchange);
|
||||
else if (xchange != 0)
|
||||
mainwindows_resize_horiz(xchange);
|
||||
if (ydiff < 0)
|
||||
mainwindows_resize_smaller(xdiff, ydiff);
|
||||
else if (ydiff > 0)
|
||||
mainwindows_resize_bigger(xdiff, ydiff);
|
||||
else if (xdiff != 0)
|
||||
mainwindows_resize_horiz(xdiff);
|
||||
|
||||
irssi_redraw();
|
||||
screen_refresh_thaw();
|
||||
@ -435,7 +450,7 @@ int mainwindows_reserve_lines(int count, int up)
|
||||
ret = reserved_down;
|
||||
reserved_down += count;
|
||||
|
||||
window = mainwindows_find_upper(LINES);
|
||||
window = mainwindows_find_upper(screen_height);
|
||||
if (window != NULL) window->last_line -= count;
|
||||
}
|
||||
|
||||
@ -462,14 +477,14 @@ static int mainwindow_grow(MAIN_WINDOW_REC *window, int count)
|
||||
|
||||
/* shrink lower window */
|
||||
shrink_win = mainwindows_find_lower(window->last_line);
|
||||
if (shrink_win != NULL && shrink_win->lines-count >= WINDOW_MIN_SIZE) {
|
||||
if (shrink_win != NULL && shrink_win->height-count >= WINDOW_MIN_SIZE) {
|
||||
window->last_line += count;
|
||||
shrink_win->first_line += count;
|
||||
} else {
|
||||
/* shrink upper window */
|
||||
shrink_win = mainwindows_find_upper(window->first_line);
|
||||
if (shrink_win == NULL ||
|
||||
shrink_win->lines-count < WINDOW_MIN_SIZE)
|
||||
shrink_win->height-count < WINDOW_MIN_SIZE)
|
||||
return FALSE;
|
||||
|
||||
window->first_line -= count;
|
||||
@ -484,7 +499,7 @@ static int mainwindow_shrink(MAIN_WINDOW_REC *window, int count)
|
||||
{
|
||||
MAIN_WINDOW_REC *grow_win;
|
||||
|
||||
if (window->lines-count < WINDOW_MIN_SIZE)
|
||||
if (window->height-count < WINDOW_MIN_SIZE)
|
||||
return FALSE;
|
||||
|
||||
grow_win = mainwindows_find_lower(window->last_line);
|
||||
@ -505,7 +520,7 @@ static int mainwindow_shrink(MAIN_WINDOW_REC *window, int count)
|
||||
|
||||
void mainwindow_set_size(MAIN_WINDOW_REC *window, int size)
|
||||
{
|
||||
size -= window->lines;
|
||||
size -= window->height;
|
||||
if (size < 0)
|
||||
mainwindow_shrink(window, size);
|
||||
else
|
||||
@ -551,7 +566,7 @@ static void cmd_window_size(const char *data)
|
||||
if (!is_numeric(data, 0)) return;
|
||||
size = atoi(data);
|
||||
|
||||
size -= WINDOW_GUI(active_win)->parent->lines;
|
||||
size -= WINDOW_GUI(active_win)->parent->height;
|
||||
if (size == 0) return;
|
||||
|
||||
ltoa(sizestr, size < 0 ? -size : size);
|
||||
@ -571,7 +586,7 @@ static void cmd_window_balance(void)
|
||||
windows = g_slist_length(mainwindows);
|
||||
if (windows == 1) return;
|
||||
|
||||
avail_size = LINES-reserved_up-reserved_down;
|
||||
avail_size = screen_height - reserved_up-reserved_down;
|
||||
unit_size = avail_size/windows;
|
||||
bigger_units = avail_size%windows;
|
||||
|
||||
@ -580,11 +595,11 @@ static void cmd_window_balance(void)
|
||||
for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
|
||||
MAIN_WINDOW_REC *rec = tmp->data;
|
||||
|
||||
old_size = rec->lines;
|
||||
old_size = rec->height;
|
||||
rec->first_line = last_line+1;
|
||||
rec->last_line = rec->first_line-1 + unit_size -
|
||||
rec->statusbar_lines;
|
||||
rec->lines = rec->last_line-rec->first_line+1;
|
||||
rec->height = rec->last_line-rec->first_line+1;
|
||||
|
||||
if (bigger_units > 0) {
|
||||
rec->last_line++;
|
||||
@ -592,7 +607,7 @@ static void cmd_window_balance(void)
|
||||
}
|
||||
last_line = rec->last_line + rec->statusbar_lines;
|
||||
|
||||
mainwindow_resize(rec, rec->lines-old_size, FALSE);
|
||||
mainwindow_resize(rec, rec->height-old_size, FALSE);
|
||||
}
|
||||
g_slist_free(sorted);
|
||||
|
||||
@ -847,6 +862,9 @@ static void cmd_window_stick(const char *data)
|
||||
|
||||
void mainwindows_init(void)
|
||||
{
|
||||
screen_width = COLS;
|
||||
screen_height = LINES;
|
||||
|
||||
mainwindows = NULL;
|
||||
active_mainwin = NULL;
|
||||
reserved_up = reserved_down = 0;
|
||||
|
@ -12,8 +12,10 @@ typedef struct {
|
||||
|
||||
#ifdef USE_CURSES_WINDOWS
|
||||
WINDOW *curses_win;
|
||||
#else
|
||||
#error disable-curses-windows is currently broken /* FIXME */
|
||||
#endif
|
||||
int first_line, last_line, lines;
|
||||
int first_line, last_line, width, height;
|
||||
int statusbar_lines;
|
||||
void *statusbar;
|
||||
void *statusbar_window_item;
|
||||
@ -32,7 +34,7 @@ void mainwindows_redraw(void);
|
||||
void mainwindows_recreate(void);
|
||||
|
||||
void mainwindow_set_size(MAIN_WINDOW_REC *window, int size);
|
||||
void mainwindows_resize(int ychange, int xchange);
|
||||
void mainwindows_resize(int width, int height);
|
||||
|
||||
int mainwindows_reserve_lines(int count, int up);
|
||||
GSList *mainwindows_get_sorted(int reverse);
|
||||
|
@ -49,8 +49,6 @@ static void deinit_screen_int(void);
|
||||
|
||||
static void sig_winch(int p)
|
||||
{
|
||||
int ychange, xchange;
|
||||
|
||||
#if defined (TIOCGWINSZ) && defined (HAVE_CURSES_RESIZETERM)
|
||||
struct winsize ws;
|
||||
|
||||
@ -67,24 +65,14 @@ static void sig_winch(int p)
|
||||
ws.ws_col = MIN_SCREEN_WIDTH;
|
||||
|
||||
/* Resize curses terminal */
|
||||
ychange = ws.ws_row-LINES;
|
||||
xchange = ws.ws_col-COLS;
|
||||
resizeterm(ws.ws_row, ws.ws_col);
|
||||
#else
|
||||
int old_lines, old_cols;
|
||||
|
||||
old_lines = LINES;
|
||||
old_cols = COLS;
|
||||
|
||||
deinit_screen_int();
|
||||
init_screen_int();
|
||||
mainwindows_recreate();
|
||||
|
||||
ychange = LINES-old_lines;
|
||||
xchange = COLS-old_cols;
|
||||
#endif
|
||||
|
||||
mainwindows_resize(ychange, xchange != 0);
|
||||
mainwindows_resize(COLS, LINES);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -350,7 +350,7 @@ static void sig_statusbar_more_check_remove(WINDOW_REC *window)
|
||||
if (!is_window_visible(window))
|
||||
return;
|
||||
|
||||
if (more_item != NULL && WINDOW_GUI(window)->bottom) {
|
||||
if (more_item != NULL && WINDOW_GUI(window)->view->bottom) {
|
||||
statusbar_item_remove(more_item);
|
||||
more_item = NULL;
|
||||
}
|
||||
@ -361,7 +361,7 @@ static void sig_statusbar_more_check(WINDOW_REC *window)
|
||||
if (window == NULL || !is_window_visible(window))
|
||||
return;
|
||||
|
||||
if (!WINDOW_GUI(window)->bottom) {
|
||||
if (!WINDOW_GUI(window)->view->bottom) {
|
||||
if (more_item == NULL) {
|
||||
more_item = statusbar_item_create(mainbar, SBAR_PRIORITY_LOW, FALSE, statusbar_more);
|
||||
statusbar_redraw(mainbar);
|
||||
@ -593,7 +593,9 @@ static void sidebar_remove_items(MAIN_WINDOW_REC *window)
|
||||
|
||||
static void sig_mainwindow_created(MAIN_WINDOW_REC *window)
|
||||
{
|
||||
window->statusbar = statusbar_create(STATUSBAR_POS_MIDDLE, window->first_line+window->lines);
|
||||
window->statusbar =
|
||||
statusbar_create(STATUSBAR_POS_MIDDLE,
|
||||
window->first_line+window->height);
|
||||
sidebar_add_items(window);
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,7 @@ static void sig_mainwindow_resized(MAIN_WINDOW_REC *window)
|
||||
STATUSBAR_REC *rec;
|
||||
|
||||
rec = window->statusbar;
|
||||
rec->ypos = window->first_line+window->lines;
|
||||
rec->ypos = window->first_line+window->height;
|
||||
}
|
||||
|
||||
void statusbar_init(void)
|
||||
|
297
src/fe-text/textbuffer-commands.c
Normal file
297
src/fe-text/textbuffer-commands.c
Normal file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
textbuffer-commands.c : Text buffer handling
|
||||
|
||||
Copyright (C) 1999-2001 Timo Sirainen
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "misc.h"
|
||||
#include "levels.h"
|
||||
|
||||
#include "printtext.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
/* SYNTAX: CLEAR */
|
||||
static void cmd_clear(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
void *free_arg;
|
||||
GSList *tmp;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, PARAM_FLAG_OPTIONS,
|
||||
"clear", &optlist)) return;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "all") == NULL) {
|
||||
/* clear active window */
|
||||
textbuffer_view_clear(WINDOW_GUI(active_win)->view);
|
||||
} else {
|
||||
/* clear all windows */
|
||||
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *window = tmp->data;
|
||||
|
||||
textbuffer_view_clear(WINDOW_GUI(window)->view);
|
||||
}
|
||||
}
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void cmd_scrollback(const char *data, SERVER_REC *server,
|
||||
WI_ITEM_REC *item)
|
||||
{
|
||||
command_runsub("scrollback", data, server, item);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK CLEAR */
|
||||
static void cmd_scrollback_clear(void)
|
||||
{
|
||||
textbuffer_view_remove_all_lines(WINDOW_GUI(active_win)->view);
|
||||
}
|
||||
|
||||
static void scrollback_goto_line(int linenum)
|
||||
{
|
||||
TEXT_BUFFER_VIEW_REC *view;
|
||||
|
||||
view = WINDOW_GUI(active_win)->view;
|
||||
if (view->buffer->lines_count == 0)
|
||||
return;
|
||||
|
||||
textbuffer_view_scroll_line(view, view->buffer->lines->data);
|
||||
gui_window_scroll(active_win, linenum);
|
||||
}
|
||||
|
||||
static void scrollback_goto_time(const char *datearg, const char *timearg)
|
||||
{
|
||||
GList *tmp;
|
||||
struct tm tm;
|
||||
time_t now, stamp;
|
||||
int day, month;
|
||||
|
||||
/* [dd[.mm] | -<days ago>] hh:mi[:ss] */
|
||||
now = stamp = time(NULL);
|
||||
if (*datearg == '-') {
|
||||
/* -<days ago> */
|
||||
stamp -= atoi(datearg+1) * 3600*24;
|
||||
memcpy(&tm, localtime(&stamp), sizeof(struct tm));
|
||||
} else if (*timearg != '\0') {
|
||||
/* dd[.mm] */
|
||||
memcpy(&tm, localtime(&stamp), sizeof(struct tm));
|
||||
|
||||
day = month = 0;
|
||||
sscanf(datearg, "%d.%d", &day, &month);
|
||||
if (day <= 0) return;
|
||||
|
||||
if (month <= 0) {
|
||||
/* month not given */
|
||||
if (day > tm.tm_mday) {
|
||||
/* last month's day */
|
||||
if (tm.tm_mon > 0)
|
||||
tm.tm_mon--;
|
||||
else {
|
||||
/* last year's day.. */
|
||||
tm.tm_year--;
|
||||
tm.tm_mon = 11;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
month--;
|
||||
if (month > tm.tm_mon)
|
||||
tm.tm_year--;
|
||||
tm.tm_mon = month;
|
||||
}
|
||||
|
||||
tm.tm_mday = day;
|
||||
stamp = mktime(&tm);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* only time given, move it to timearg */
|
||||
timearg = datearg;
|
||||
}
|
||||
|
||||
/* hh:mi[:ss] */
|
||||
memcpy(&tm, localtime(&stamp), sizeof(struct tm));
|
||||
tm.tm_sec = 0;
|
||||
sscanf(timearg, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
|
||||
stamp = mktime(&tm);
|
||||
|
||||
if (stamp > now && timearg == datearg) {
|
||||
/* we used /SB GOTO 23:59 or something, we want to jump to
|
||||
previous day's 23:59 time instead of into future. */
|
||||
stamp -= 3600*24;
|
||||
}
|
||||
|
||||
if (stamp > now) {
|
||||
/* we're still looking into future, don't bother checking */
|
||||
return;
|
||||
}
|
||||
|
||||
/* scroll to first line after timestamp */
|
||||
tmp = textbuffer_view_get_lines(WINDOW_GUI(active_win)->view);
|
||||
for (; tmp != NULL; tmp = tmp->next) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if (rec->info.time >= stamp) {
|
||||
gui_window_scroll_line(active_win, rec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK GOTO <+|-linecount>|<linenum>|<timestamp> */
|
||||
static void cmd_scrollback_goto(const char *data)
|
||||
{
|
||||
char *datearg, *timearg;
|
||||
void *free_arg;
|
||||
int lines;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 2, &datearg, &timearg))
|
||||
return;
|
||||
|
||||
if (*timearg == '\0' && (*datearg == '-' || *datearg == '+')) {
|
||||
/* go forward/backward n lines */
|
||||
lines = atoi(datearg + (*datearg == '-' ? 0 : 1));
|
||||
gui_window_scroll(active_win, lines);
|
||||
} else if (*timearg == '\0' && is_numeric(datearg, '\0')) {
|
||||
/* go to n'th line. */
|
||||
scrollback_goto_line(atoi(datearg));
|
||||
} else {
|
||||
/* should be timestamp */
|
||||
scrollback_goto_time(datearg, timearg);
|
||||
}
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK HOME */
|
||||
static void cmd_scrollback_home(const char *data)
|
||||
{
|
||||
TEXT_BUFFER_REC *buffer;
|
||||
|
||||
buffer = WINDOW_GUI(active_win)->view->buffer;
|
||||
if (buffer->lines_count > 0)
|
||||
gui_window_scroll_line(active_win, buffer->lines->data);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK END */
|
||||
static void cmd_scrollback_end(const char *data)
|
||||
{
|
||||
TEXT_BUFFER_VIEW_REC *view;
|
||||
|
||||
view = WINDOW_GUI(active_win)->view;
|
||||
if (view->bottom_startline == NULL)
|
||||
return;
|
||||
|
||||
textbuffer_view_scroll_line(view, view->bottom_startline->data);
|
||||
gui_window_scroll(active_win, view->bottom_subline);
|
||||
}
|
||||
|
||||
/* SYNTAX: SCROLLBACK REDRAW */
|
||||
static void cmd_scrollback_redraw(void)
|
||||
{
|
||||
#if 0
|
||||
GUI_WINDOW_REC *gui;
|
||||
GList *tmp, *next;
|
||||
|
||||
gui = WINDOW_GUI(active_win);
|
||||
|
||||
screen_refresh_freeze();
|
||||
for (tmp = gui->lines; tmp != NULL; tmp = next) {
|
||||
next = tmp->next;
|
||||
gui_window_reformat_line(active_win, tmp->data);
|
||||
}
|
||||
|
||||
gui_window_redraw(active_win);
|
||||
screen_refresh_thaw();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cmd_scrollback_status(void)
|
||||
{
|
||||
GSList *tmp;
|
||||
int window_kb, total_lines, total_kb;
|
||||
|
||||
total_lines = 0; total_kb = 0;
|
||||
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *window = tmp->data;
|
||||
TEXT_BUFFER_VIEW_REC *view;
|
||||
|
||||
view = WINDOW_GUI(window)->view;
|
||||
|
||||
window_kb = g_slist_length(view->buffer->text_chunks)*
|
||||
LINE_TEXT_CHUNK_SIZE/1024;
|
||||
total_lines += view->buffer->lines_count;
|
||||
total_kb += window_kb;
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
||||
"Window %d: %d lines, %dkB of data",
|
||||
window->refnum, view->buffer->lines_count,
|
||||
window_kb);
|
||||
}
|
||||
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
||||
"Total: %d lines, %dkB of data",
|
||||
total_lines, total_kb);
|
||||
}
|
||||
|
||||
static void sig_away_changed(SERVER_REC *server)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
if (!server->usermode_away)
|
||||
return;
|
||||
|
||||
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *rec = tmp->data;
|
||||
|
||||
textbuffer_view_set_bookmark_bottom(WINDOW_GUI(rec)->view,
|
||||
"lastlog_last_away");
|
||||
}
|
||||
}
|
||||
|
||||
void textbuffer_commands_init(void)
|
||||
{
|
||||
command_bind("clear", NULL, (SIGNAL_FUNC) cmd_clear);
|
||||
command_bind("scrollback", NULL, (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_bind("scrollback clear", NULL, (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_bind("scrollback goto", NULL, (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
command_bind("scrollback home", NULL, (SIGNAL_FUNC) cmd_scrollback_home);
|
||||
command_bind("scrollback end", NULL, (SIGNAL_FUNC) cmd_scrollback_end);
|
||||
command_bind("scrollback redraw", NULL, (SIGNAL_FUNC) cmd_scrollback_redraw);
|
||||
command_bind("scrollback status", NULL, (SIGNAL_FUNC) cmd_scrollback_status);
|
||||
|
||||
command_set_options("clear", "all");
|
||||
|
||||
signal_add("away mode changed", (SIGNAL_FUNC) sig_away_changed);
|
||||
}
|
||||
|
||||
void textbuffer_commands_deinit(void)
|
||||
{
|
||||
command_unbind("clear", (SIGNAL_FUNC) cmd_clear);
|
||||
command_unbind("scrollback", (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_unbind("scrollback clear", (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_unbind("scrollback goto", (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
command_unbind("scrollback home", (SIGNAL_FUNC) cmd_scrollback_home);
|
||||
command_unbind("scrollback end", (SIGNAL_FUNC) cmd_scrollback_end);
|
||||
command_unbind("scrollback redraw", (SIGNAL_FUNC) cmd_scrollback_redraw);
|
||||
command_unbind("scrollback status", (SIGNAL_FUNC) cmd_scrollback_status);
|
||||
|
||||
signal_remove("away mode changed", (SIGNAL_FUNC) sig_away_changed);
|
||||
}
|
1059
src/fe-text/textbuffer-view.c
Normal file
1059
src/fe-text/textbuffer-view.c
Normal file
File diff suppressed because it is too large
Load Diff
131
src/fe-text/textbuffer-view.h
Normal file
131
src/fe-text/textbuffer-view.h
Normal file
@ -0,0 +1,131 @@
|
||||
#ifndef __TEXTBUFFER_VIEW_H
|
||||
#define __TEXTBUFFER_VIEW_H
|
||||
|
||||
#include "textbuffer.h"
|
||||
#include "screen.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned char *start;
|
||||
int indent;
|
||||
int color;
|
||||
|
||||
/* first word in line belong to the end of the last word in
|
||||
previous line */
|
||||
unsigned int continues:1;
|
||||
} LINE_CACHE_SUB_REC;
|
||||
|
||||
typedef struct {
|
||||
time_t last_access;
|
||||
|
||||
int count; /* number of real lines */
|
||||
|
||||
/* variable sized array, actually. starts from the second line,
|
||||
so size of it is count-1 */
|
||||
LINE_CACHE_SUB_REC lines[1];
|
||||
} LINE_CACHE_REC;
|
||||
|
||||
typedef struct {
|
||||
int refcount;
|
||||
int width;
|
||||
|
||||
GHashTable *line_cache;
|
||||
|
||||
/* should contain the same value for each cache that uses the
|
||||
same buffer */
|
||||
unsigned char update_counter;
|
||||
/* number of real lines used by the last line in buffer */
|
||||
int last_linecount;
|
||||
} TEXT_BUFFER_CACHE_REC;
|
||||
|
||||
typedef struct {
|
||||
TEXT_BUFFER_REC *buffer;
|
||||
GSList *siblings; /* other views that use the same buffer */
|
||||
|
||||
WINDOW *window;
|
||||
int width, height;
|
||||
int default_indent;
|
||||
|
||||
TEXT_BUFFER_CACHE_REC *cache;
|
||||
GList *startline; /* line at the top of the screen */
|
||||
int subline; /* number of "real lines" to skip from `startline' */
|
||||
|
||||
/* marks the bottom of the text buffer */
|
||||
GList *bottom_startline;
|
||||
int bottom_subline;
|
||||
|
||||
/* how many empty lines are in screen. a screenful when started
|
||||
or used /CLEAR */
|
||||
int empty_linecount;
|
||||
/* window is at the bottom of the text buffer */
|
||||
unsigned int bottom:1;
|
||||
|
||||
/* info how to efficiently refresh window buffer */
|
||||
//unsigned int redraw:1;
|
||||
int ypos; /* cursor position - visible area is 0..height-1 */
|
||||
/*GList *drawn_startline;
|
||||
int drawn_subline;*/
|
||||
|
||||
/* Bookmarks to the lines in the buffer - removed automatically
|
||||
when the line gets removed from buffer */
|
||||
GHashTable *bookmarks;
|
||||
} TEXT_BUFFER_VIEW_REC;
|
||||
|
||||
/* Create new view. */
|
||||
TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
|
||||
int width, int height,
|
||||
int default_indent);
|
||||
/* Destroy the view. */
|
||||
void textbuffer_view_destroy(TEXT_BUFFER_VIEW_REC *view);
|
||||
/* Change the default indent position */
|
||||
void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view,
|
||||
int default_indent);
|
||||
|
||||
/* Resize the view. */
|
||||
void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height);
|
||||
/* Clear the view, don't actually remove any lines from buffer. */
|
||||
void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view);
|
||||
|
||||
#define textbuffer_view_get_lines(view) \
|
||||
((view)->buffer->lines)
|
||||
|
||||
/* Scroll the view up/down */
|
||||
void textbuffer_view_scroll(TEXT_BUFFER_VIEW_REC *view, int lines);
|
||||
/* Scroll to specified line */
|
||||
void textbuffer_view_scroll_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
|
||||
/* Return line cache */
|
||||
LINE_CACHE_REC *textbuffer_view_get_line_cache(TEXT_BUFFER_VIEW_REC *view,
|
||||
LINE_REC *line);
|
||||
|
||||
/*
|
||||
Functions for manipulating the text buffer, using these commands update
|
||||
all views that use the buffer.
|
||||
*/
|
||||
|
||||
/* Update some line in the buffer which has been modified using
|
||||
textbuffer_append() or textbuffer_insert(). */
|
||||
void textbuffer_view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
|
||||
/* Remove one line from buffer. */
|
||||
void textbuffer_view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
|
||||
/* Remove all lines from buffer. */
|
||||
void textbuffer_view_remove_all_lines(TEXT_BUFFER_VIEW_REC *view);
|
||||
|
||||
/* Set a bookmark in view */
|
||||
void textbuffer_view_set_bookmark(TEXT_BUFFER_VIEW_REC *view,
|
||||
const char *name, LINE_REC *line);
|
||||
/* Set a bookmark in view to the bottom line */
|
||||
void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view,
|
||||
const char *name);
|
||||
/* Return the line for bookmark */
|
||||
LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
|
||||
const char *name);
|
||||
|
||||
/* Specify window where the changes in view should be drawn,
|
||||
NULL disables it. */
|
||||
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view, WINDOW *window);
|
||||
/* Redraw the view */
|
||||
void textbuffer_view_redraw(TEXT_BUFFER_VIEW_REC *view);
|
||||
|
||||
void textbuffer_view_init(void);
|
||||
void textbuffer_view_deinit(void);
|
||||
|
||||
#endif
|
601
src/fe-text/textbuffer.c
Normal file
601
src/fe-text/textbuffer.c
Normal file
@ -0,0 +1,601 @@
|
||||
/*
|
||||
textbuffer.c : Text buffer handling
|
||||
|
||||
Copyright (C) 1999-2001 Timo Sirainen
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "misc.h"
|
||||
#include "formats.h"
|
||||
|
||||
#include "textbuffer.h"
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
# include <regex.h>
|
||||
#endif
|
||||
|
||||
#define TEXT_CHUNK_USABLE_SIZE (LINE_TEXT_CHUNK_SIZE-2-(int)sizeof(char*))
|
||||
|
||||
static GMemChunk *buffer_chunk, *line_chunk, *text_chunk;
|
||||
|
||||
TEXT_BUFFER_REC *textbuffer_create(void)
|
||||
{
|
||||
TEXT_BUFFER_REC *buffer;
|
||||
|
||||
buffer = g_mem_chunk_alloc0(buffer_chunk);
|
||||
buffer->last_eol = TRUE;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void textbuffer_destroy(TEXT_BUFFER_REC *buffer)
|
||||
{
|
||||
textbuffer_remove_all_lines(buffer);
|
||||
g_mem_chunk_free(buffer_chunk, buffer);
|
||||
}
|
||||
|
||||
static TEXT_CHUNK_REC *text_chunk_find(TEXT_BUFFER_REC *buffer,
|
||||
const unsigned char *data)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = buffer->text_chunks; tmp != NULL; tmp = tmp->next) {
|
||||
TEXT_CHUNK_REC *rec = tmp->data;
|
||||
|
||||
if (data >= rec->buffer &&
|
||||
data < rec->buffer+sizeof(rec->buffer))
|
||||
return rec;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define mark_temp_eol(chunk) G_STMT_START { \
|
||||
(chunk)->buffer[(chunk)->pos] = 0; \
|
||||
(chunk)->buffer[(chunk)->pos+1] = LINE_CMD_EOL; \
|
||||
} G_STMT_END
|
||||
|
||||
static TEXT_CHUNK_REC *text_chunk_create(TEXT_BUFFER_REC *buffer)
|
||||
{
|
||||
TEXT_CHUNK_REC *rec;
|
||||
char *buf, *ptr, **pptr;
|
||||
|
||||
g_return_val_if_fail(buffer != NULL, NULL);
|
||||
|
||||
rec = g_mem_chunk_alloc(text_chunk);
|
||||
rec->pos = 0;
|
||||
rec->refcount = 0;
|
||||
|
||||
if (buffer->cur_line != NULL && buffer->cur_line->text != NULL) {
|
||||
/* create a link to new block from the old block */
|
||||
buf = buffer->cur_text->buffer + buffer->cur_text->pos;
|
||||
*buf++ = 0; *buf++ = (char) LINE_CMD_CONTINUE;
|
||||
|
||||
/* we want to store pointer to beginning of the new text
|
||||
block to char* buffer. this probably isn't ANSI-C
|
||||
compatible, and trying this without the pptr variable
|
||||
breaks at least NetBSD/Alpha, so don't go "optimize"
|
||||
it :) */
|
||||
ptr = rec->buffer; pptr = &ptr;
|
||||
memcpy(buf, pptr, sizeof(char *));
|
||||
} else {
|
||||
/* just to be safe */
|
||||
mark_temp_eol(rec);
|
||||
}
|
||||
|
||||
buffer->cur_text = rec;
|
||||
buffer->text_chunks = g_slist_append(buffer->text_chunks, rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
static void text_chunk_destroy(TEXT_BUFFER_REC *buffer, TEXT_CHUNK_REC *chunk)
|
||||
{
|
||||
g_return_if_fail(buffer != NULL);
|
||||
g_return_if_fail(chunk != NULL);
|
||||
|
||||
buffer->text_chunks = g_slist_remove(buffer->text_chunks, chunk);
|
||||
g_mem_chunk_free(text_chunk, chunk);
|
||||
}
|
||||
|
||||
static void text_chunk_line_free(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
||||
{
|
||||
TEXT_CHUNK_REC *chunk;
|
||||
const unsigned char *text;
|
||||
unsigned char *tmp = NULL;
|
||||
|
||||
for (text = line->text;; text++) {
|
||||
if (*text != '\0')
|
||||
continue;
|
||||
|
||||
text++;
|
||||
if (*text == LINE_CMD_CONTINUE || *text == LINE_CMD_EOL) {
|
||||
if (*text == LINE_CMD_CONTINUE)
|
||||
memcpy(&tmp, text+1, sizeof(char *));
|
||||
|
||||
/* free the previous block */
|
||||
chunk = text_chunk_find(buffer, text);
|
||||
if (--chunk->refcount == 0) {
|
||||
if (buffer->cur_text == chunk)
|
||||
chunk->pos = 0;
|
||||
else
|
||||
text_chunk_destroy(buffer, chunk);
|
||||
}
|
||||
|
||||
if (*text == LINE_CMD_EOL)
|
||||
break;
|
||||
|
||||
text = tmp-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void text_chunk_append(TEXT_BUFFER_REC *buffer,
|
||||
const char *data, int len)
|
||||
{
|
||||
TEXT_CHUNK_REC *chunk;
|
||||
int left;
|
||||
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
chunk = buffer->cur_text;
|
||||
while (chunk->pos + len >= TEXT_CHUNK_USABLE_SIZE) {
|
||||
left = TEXT_CHUNK_USABLE_SIZE - chunk->pos;
|
||||
if (data[left-1] == 0) left--; /* don't split the commands */
|
||||
|
||||
memcpy(chunk->buffer + chunk->pos, data, left);
|
||||
chunk->pos += left;
|
||||
|
||||
chunk = text_chunk_create(buffer);
|
||||
chunk->refcount++;
|
||||
len -= left; data += left;
|
||||
}
|
||||
|
||||
memcpy(chunk->buffer + chunk->pos, data, len);
|
||||
chunk->pos += len;
|
||||
|
||||
mark_temp_eol(chunk);
|
||||
}
|
||||
|
||||
static LINE_REC *textbuffer_line_create(TEXT_BUFFER_REC *buffer)
|
||||
{
|
||||
LINE_REC *rec;
|
||||
|
||||
if (buffer->cur_text == NULL)
|
||||
text_chunk_create(buffer);
|
||||
|
||||
rec = g_mem_chunk_alloc(line_chunk);
|
||||
rec->refcount = 1;
|
||||
rec->text = buffer->cur_text->buffer + buffer->cur_text->pos;
|
||||
|
||||
buffer->cur_text->refcount++;
|
||||
return rec;
|
||||
}
|
||||
|
||||
static LINE_REC *textbuffer_line_insert(TEXT_BUFFER_REC *buffer,
|
||||
LINE_REC *prev)
|
||||
{
|
||||
LINE_REC *line;
|
||||
|
||||
line = textbuffer_line_create(buffer);
|
||||
if (prev == buffer->cur_line) {
|
||||
buffer->cur_line = line;
|
||||
buffer->lines = g_list_append(buffer->lines, buffer->cur_line);
|
||||
} else {
|
||||
buffer->lines = g_list_insert(buffer->lines, line,
|
||||
g_list_index(buffer->lines, prev)+1);
|
||||
}
|
||||
buffer->lines_count++;
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
void textbuffer_line_ref(LINE_REC *line)
|
||||
{
|
||||
if (++line->refcount == 255)
|
||||
g_error("line reference counter wrapped - shouldn't happen");
|
||||
}
|
||||
|
||||
void textbuffer_line_unref(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
||||
{
|
||||
if (--line->refcount == 0) {
|
||||
text_chunk_line_free(buffer, line);
|
||||
g_mem_chunk_free(line_chunk, line);
|
||||
}
|
||||
}
|
||||
|
||||
void textbuffer_line_unref_list(TEXT_BUFFER_REC *buffer, GList *list)
|
||||
{
|
||||
while (list != NULL) {
|
||||
textbuffer_line_unref(buffer, list->data);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
LINE_REC *textbuffer_append(TEXT_BUFFER_REC *buffer,
|
||||
const unsigned char *data, int len,
|
||||
LINE_INFO_REC *info)
|
||||
{
|
||||
return textbuffer_insert(buffer, buffer->cur_line, data, len, info);
|
||||
}
|
||||
|
||||
LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
|
||||
const unsigned char *data, int len,
|
||||
LINE_INFO_REC *info)
|
||||
{
|
||||
LINE_REC *line;
|
||||
|
||||
line = !buffer->last_eol ? insert_after :
|
||||
textbuffer_line_insert(buffer, insert_after);
|
||||
|
||||
if (info != NULL)
|
||||
memcpy(&line->info, info, sizeof(line->info));
|
||||
|
||||
text_chunk_append(buffer, data, len);
|
||||
|
||||
buffer->last_eol = len >= 2 &&
|
||||
data[len-2] == 0 && data[len-1] == LINE_CMD_EOL;
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
||||
{
|
||||
buffer->lines = g_list_remove(buffer->lines, line);
|
||||
|
||||
if (buffer->cur_line == line) {
|
||||
buffer->cur_line = buffer->lines == NULL ? NULL :
|
||||
g_list_last(buffer->lines)->data;
|
||||
}
|
||||
|
||||
buffer->lines_count--;
|
||||
textbuffer_line_unref(buffer, line);
|
||||
}
|
||||
|
||||
/* Removes all lines from buffer, ignoring reference counters */
|
||||
void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = buffer->text_chunks; tmp != NULL; tmp = tmp->next)
|
||||
g_mem_chunk_free(text_chunk, tmp->data);
|
||||
g_slist_free(buffer->text_chunks);
|
||||
buffer->text_chunks = NULL;
|
||||
|
||||
g_list_free(buffer->lines);
|
||||
buffer->lines = NULL;
|
||||
|
||||
buffer->cur_line = NULL;
|
||||
buffer->lines_count = 0;
|
||||
}
|
||||
|
||||
void textbuffer_line2text(LINE_REC *line, int coloring, GString *str)
|
||||
{
|
||||
unsigned char cmd;
|
||||
char *ptr, *tmp;
|
||||
|
||||
g_return_if_fail(line != NULL);
|
||||
g_return_if_fail(str != NULL);
|
||||
|
||||
g_string_truncate(str, 0);
|
||||
|
||||
for (ptr = line->text;;) {
|
||||
if (*ptr != 0) {
|
||||
g_string_append_c(str, *ptr);
|
||||
ptr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
cmd = (unsigned char) *ptr;
|
||||
ptr++;
|
||||
|
||||
if (cmd == LINE_CMD_EOL || cmd == LINE_CMD_FORMAT) {
|
||||
/* end of line */
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd == LINE_CMD_CONTINUE) {
|
||||
/* line continues in another address.. */
|
||||
memcpy(&tmp, ptr, sizeof(char *));
|
||||
ptr = tmp;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!coloring) {
|
||||
/* no colors, skip coloring commands */
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((cmd & 0x80) == 0) {
|
||||
/* set color */
|
||||
g_string_sprintfa(str, "\004%c%c",
|
||||
(cmd & 0x0f)+'0',
|
||||
((cmd & 0xf0) >> 4)+'0');
|
||||
} else switch (cmd) {
|
||||
case LINE_CMD_UNDERLINE:
|
||||
g_string_append_c(str, 31);
|
||||
break;
|
||||
case LINE_CMD_COLOR0:
|
||||
g_string_sprintfa(str, "\004%c%c",
|
||||
'0', FORMAT_COLOR_NOCHANGE);
|
||||
break;
|
||||
case LINE_CMD_COLOR8:
|
||||
g_string_sprintfa(str, "\004%c%c",
|
||||
'8', FORMAT_COLOR_NOCHANGE);
|
||||
break;
|
||||
case LINE_CMD_BLINK:
|
||||
g_string_sprintfa(str, "\004%c", FORMAT_STYLE_BLINK);
|
||||
break;
|
||||
case LINE_CMD_INDENT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
|
||||
int level, int nolevel, const char *text,
|
||||
int regexp, int fullword, int case_sensitive)
|
||||
{
|
||||
#ifdef HAVE_REGEX_H
|
||||
regex_t preg;
|
||||
#endif
|
||||
GList *line, *tmp;
|
||||
GList *matches;
|
||||
GString *str;
|
||||
|
||||
g_return_val_if_fail(buffer != NULL, NULL);
|
||||
g_return_val_if_fail(text != NULL, NULL);
|
||||
|
||||
if (regexp) {
|
||||
#ifdef HAVE_REGEX_H
|
||||
int flags = REG_EXTENDED | REG_NOSUB |
|
||||
(case_sensitive ? 0 : REG_ICASE);
|
||||
if (regcomp(&preg, text, flags) != 0)
|
||||
return NULL;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
matches = NULL;
|
||||
str = g_string_new(NULL);
|
||||
|
||||
line = g_list_find(buffer->lines, startline);
|
||||
if (line == NULL)
|
||||
line = buffer->lines;
|
||||
|
||||
for (tmp = line; tmp != NULL; tmp = tmp->next) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if ((rec->info.level & level) == 0 ||
|
||||
(rec->info.level & nolevel) != 0)
|
||||
continue;
|
||||
|
||||
if (*text == '\0') {
|
||||
/* no search word, everything matches */
|
||||
textbuffer_line_ref(rec);
|
||||
matches = g_list_append(matches, rec);
|
||||
continue;
|
||||
}
|
||||
|
||||
textbuffer_line2text(rec, FALSE, str);
|
||||
|
||||
if (
|
||||
#ifdef HAVE_REGEX_H
|
||||
regexp ? regexec(&preg, str->str, 0, NULL, 0) == 0 :
|
||||
#endif
|
||||
fullword ? strstr_full_case(str->str, text,
|
||||
!case_sensitive) != NULL :
|
||||
case_sensitive ? strstr(str->str, text) != NULL :
|
||||
stristr(str->str, text) != NULL) {
|
||||
/* matched */
|
||||
textbuffer_line_ref(rec);
|
||||
matches = g_list_append(matches, rec);
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_REGEX_H
|
||||
if (regexp) regfree(&preg);
|
||||
#endif
|
||||
g_string_free(str, TRUE);
|
||||
return matches;
|
||||
}
|
||||
|
||||
#if 0 /* FIXME: saving formats is broken */
|
||||
static char *line_read_format(unsigned const char **text)
|
||||
{
|
||||
GString *str;
|
||||
char *ret;
|
||||
|
||||
str = g_string_new(NULL);
|
||||
for (;;) {
|
||||
if (**text == '\0') {
|
||||
if ((*text)[1] == LINE_CMD_EOL) {
|
||||
/* leave text at \0<eof> */
|
||||
break;
|
||||
}
|
||||
if ((*text)[1] == LINE_CMD_FORMAT_CONT) {
|
||||
/* leave text at \0<format_cont> */
|
||||
break;
|
||||
}
|
||||
(*text)++;
|
||||
|
||||
if (**text == LINE_CMD_FORMAT) {
|
||||
/* move text to start after \0<format> */
|
||||
(*text)++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (**text == LINE_CMD_CONTINUE) {
|
||||
unsigned char *tmp;
|
||||
|
||||
memcpy(&tmp, (*text)+1, sizeof(char *));
|
||||
*text = tmp;
|
||||
continue;
|
||||
} else if (**text & 0x80)
|
||||
(*text)++;
|
||||
continue;
|
||||
}
|
||||
|
||||
g_string_append_c(str, (char) **text);
|
||||
(*text)++;
|
||||
}
|
||||
|
||||
ret = str->str;
|
||||
g_string_free(str, FALSE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *textbuffer_line_get_format(WINDOW_REC *window, LINE_REC *line,
|
||||
GString *raw)
|
||||
{
|
||||
const unsigned char *text;
|
||||
char *module, *format_name, *args[MAX_FORMAT_PARAMS], *ret;
|
||||
TEXT_DEST_REC dest;
|
||||
int formatnum, argcount;
|
||||
|
||||
text = (const unsigned char *) line->text;
|
||||
|
||||
/* skip the beginning of the line until we find the format */
|
||||
g_free(line_read_format(&text));
|
||||
if (text[1] == LINE_CMD_FORMAT_CONT) {
|
||||
g_string_append_c(raw, '\0');
|
||||
g_string_append_c(raw, (char)LINE_CMD_FORMAT_CONT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read format information */
|
||||
module = line_read_format(&text);
|
||||
format_name = line_read_format(&text);
|
||||
|
||||
if (raw != NULL) {
|
||||
g_string_append_c(raw, '\0');
|
||||
g_string_append_c(raw, (char)LINE_CMD_FORMAT);
|
||||
|
||||
g_string_append(raw, module);
|
||||
|
||||
g_string_append_c(raw, '\0');
|
||||
g_string_append_c(raw, (char)LINE_CMD_FORMAT);
|
||||
|
||||
g_string_append(raw, format_name);
|
||||
}
|
||||
|
||||
formatnum = format_find_tag(module, format_name);
|
||||
if (formatnum == -1)
|
||||
ret = NULL;
|
||||
else {
|
||||
argcount = 0;
|
||||
memset(args, 0, sizeof(args));
|
||||
while (*text != '\0' || text[1] != LINE_CMD_EOL) {
|
||||
args[argcount] = line_read_format(&text);
|
||||
if (raw != NULL) {
|
||||
g_string_append_c(raw, '\0');
|
||||
g_string_append_c(raw,
|
||||
(char)LINE_CMD_FORMAT);
|
||||
|
||||
g_string_append(raw, args[argcount]);
|
||||
}
|
||||
argcount++;
|
||||
}
|
||||
|
||||
/* get the format text */
|
||||
format_create_dest(&dest, NULL, NULL, line->level, window);
|
||||
ret = format_get_text_theme_charargs(current_theme,
|
||||
module, &dest,
|
||||
formatnum, args);
|
||||
while (argcount > 0)
|
||||
g_free(args[--argcount]);
|
||||
}
|
||||
|
||||
g_free(module);
|
||||
g_free(format_name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void textbuffer_reformat_line(WINDOW_REC *window, LINE_REC *line)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
TEXT_DEST_REC dest;
|
||||
GString *raw;
|
||||
char *str, *tmp, *prestr, *linestart, *leveltag;
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
|
||||
raw = g_string_new(NULL);
|
||||
str = textbuffer_line_get_format(window, line, raw);
|
||||
|
||||
if (str == NULL && raw->len == 2 &&
|
||||
raw->str[1] == (char)LINE_CMD_FORMAT_CONT) {
|
||||
/* multiline format, format explained in one the
|
||||
following lines. remove this line. */
|
||||
textbuffer_line_remove(window, line, FALSE);
|
||||
} else if (str != NULL) {
|
||||
/* FIXME: ugly ugly .. and this can't handle
|
||||
non-formatted lines.. */
|
||||
g_string_append_c(raw, '\0');
|
||||
g_string_append_c(raw, (char)LINE_CMD_EOL);
|
||||
|
||||
textbuffer_line_text_free(gui, line);
|
||||
|
||||
gui->temp_line = line;
|
||||
gui->temp_line->text = gui->cur_text->buffer+gui->cur_text->pos;
|
||||
gui->cur_text->lines++;
|
||||
gui->eol_marked = FALSE;
|
||||
|
||||
format_create_dest(&dest, NULL, NULL, line->level, window);
|
||||
|
||||
linestart = format_get_line_start(current_theme, &dest, line->time);
|
||||
leveltag = format_get_level_tag(current_theme, &dest);
|
||||
|
||||
prestr = g_strconcat(linestart == NULL ? "" : linestart,
|
||||
leveltag, NULL);
|
||||
g_free_not_null(linestart);
|
||||
g_free_not_null(leveltag);
|
||||
|
||||
tmp = format_add_linestart(str, prestr);
|
||||
g_free(str);
|
||||
g_free(prestr);
|
||||
|
||||
format_send_to_gui(&dest, tmp);
|
||||
g_free(tmp);
|
||||
|
||||
textbuffer_line_append(gui, raw->str, raw->len);
|
||||
|
||||
gui->eol_marked = TRUE;
|
||||
gui->temp_line = NULL;
|
||||
}
|
||||
g_string_free(raw, TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
void textbuffer_init(void)
|
||||
{
|
||||
buffer_chunk = g_mem_chunk_new("text buffer chunk",
|
||||
sizeof(TEXT_BUFFER_REC),
|
||||
sizeof(TEXT_BUFFER_REC)*32, G_ALLOC_AND_FREE);
|
||||
line_chunk = g_mem_chunk_new("line chunk", sizeof(LINE_REC),
|
||||
sizeof(LINE_REC)*1024, G_ALLOC_AND_FREE);
|
||||
text_chunk = g_mem_chunk_new("text chunk", sizeof(TEXT_CHUNK_REC),
|
||||
sizeof(TEXT_CHUNK_REC)*32, G_ALLOC_AND_FREE);
|
||||
}
|
||||
|
||||
void textbuffer_deinit(void)
|
||||
{
|
||||
g_mem_chunk_destroy(buffer_chunk);
|
||||
g_mem_chunk_destroy(line_chunk);
|
||||
g_mem_chunk_destroy(text_chunk);
|
||||
}
|
90
src/fe-text/textbuffer.h
Normal file
90
src/fe-text/textbuffer.h
Normal file
@ -0,0 +1,90 @@
|
||||
#ifndef __TEXTBUFFER_H
|
||||
#define __TEXTBUFFER_H
|
||||
|
||||
/* FIXME: Textbuffer code gets a lot faster in some points when I get rid of
|
||||
GList and make prev/next pointers directly in LINE_REC. However, this
|
||||
can still wait for a while until I get rid of GList entirely everywhere. */
|
||||
|
||||
#define LINE_TEXT_CHUNK_SIZE 16384
|
||||
|
||||
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_COLOR8, /* change to dark grey, normally 8 = bold black */
|
||||
LINE_CMD_UNDERLINE, /* enable/disable underlining */
|
||||
LINE_CMD_INDENT, /* if line is split, indent it at this position */
|
||||
LINE_CMD_BLINK, /* blinking background */
|
||||
LINE_CMD_FORMAT, /* end of line, but next will come the format that was used to create the
|
||||
text in format <module><format_name><arg><arg2...> - fields are separated
|
||||
with \0<format> and last argument ends with \0<eol>. \0<continue> is allowed
|
||||
anywhere */
|
||||
LINE_CMD_FORMAT_CONT /* multiline format, continues to next line */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int level;
|
||||
time_t time;
|
||||
} LINE_INFO_REC;
|
||||
|
||||
typedef struct {
|
||||
/* text in the line. \0 means that the next char will be a
|
||||
color or command. <= 127 = color or if 8. bit is set, the
|
||||
first 7 bits are the command. See LINE_CMD_xxxx.
|
||||
|
||||
DO NOT ADD BLACK WITH \0\0 - this will break things. Use
|
||||
LINE_CMD_COLOR0 instead. */
|
||||
unsigned char *text;
|
||||
unsigned char refcount;
|
||||
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;
|
||||
GList *lines;
|
||||
int lines_count;
|
||||
|
||||
LINE_REC *cur_line;
|
||||
TEXT_CHUNK_REC *cur_text;
|
||||
|
||||
unsigned int last_eol:1;
|
||||
} TEXT_BUFFER_REC;
|
||||
|
||||
/* Create new buffer */
|
||||
TEXT_BUFFER_REC *textbuffer_create(void);
|
||||
/* Destroy the buffer */
|
||||
void textbuffer_destroy(TEXT_BUFFER_REC *buffer);
|
||||
|
||||
void textbuffer_line_ref(LINE_REC *line);
|
||||
void textbuffer_line_unref(TEXT_BUFFER_REC *buffer, LINE_REC *line);
|
||||
void textbuffer_line_unref_list(TEXT_BUFFER_REC *buffer, GList *list);
|
||||
|
||||
/* 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,
|
||||
int regexp, int fullword, int case_sensitive);
|
||||
|
||||
void textbuffer_init(void);
|
||||
void textbuffer_deinit(void);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user