2005-07-21 15:11:16 -07:00
|
|
|
/*
|
|
|
|
* mooterm/mootermline.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MOOTERM_COMPILATION
|
2005-10-15 22:07:02 -07:00
|
|
|
#include "mooterm/mootermline-private.h"
|
2005-07-25 07:02:46 -07:00
|
|
|
#include <string.h>
|
2005-07-21 15:11:16 -07:00
|
|
|
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
#define EMPTY_CHAR MOO_TERM_EMPTY_CHAR
|
|
|
|
static MooTermTextAttr ZERO_ATTR = MOO_TERM_ZERO_ATTR;
|
|
|
|
static MooTermCell EMPTY_CELL = {EMPTY_CHAR, MOO_TERM_ZERO_ATTR};
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
#define CELLMOVE(dest__,src__,n__) memmove (dest__, src__, (n__) * sizeof (MooTermCell))
|
|
|
|
#define CELLCPY(dest__,src__,n__) memcpy (dest__, src__, (n__) * sizeof (MooTermCell))
|
|
|
|
#define PTRCPY(dest__,src__,n__) memcpy (dest__, src__, (n__) * sizeof (gpointer))
|
|
|
|
#define PTRSET(s__,c__,n__) memset (s__, c__, (n__) * sizeof (gpointer))
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
static GMemChunk *LINE_MEM_CHUNK__ = NULL;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
static gboolean line_has_tag_in_range (MooTermLine *line,
|
|
|
|
MooTermTag *tag,
|
|
|
|
guint start,
|
|
|
|
guint len);
|
|
|
|
static gboolean line_has_tag (MooTermLine *line,
|
|
|
|
MooTermTag *tag);
|
|
|
|
|
|
|
|
static int ptr_cmp (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
return a < b ? -1 : (a > b ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_term_line_mem_init (void)
|
|
|
|
{
|
|
|
|
if (!LINE_MEM_CHUNK__)
|
|
|
|
LINE_MEM_CHUNK__ = g_mem_chunk_create (MooTermLine, 512, G_ALLOC_AND_FREE);
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
MooTermLine*
|
2005-11-29 03:30:14 -08:00
|
|
|
_moo_term_line_new (guint width,
|
2005-10-15 22:07:02 -07:00
|
|
|
MooTermTextAttr attr)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
MooTermLine *line;
|
|
|
|
guint i;
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (width != 0);
|
|
|
|
g_assert (width <= MOO_TERM_LINE_MAX_LEN);
|
2005-10-15 22:07:02 -07:00
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
line = g_chunk_new0 (MooTermLine, LINE_MEM_CHUNK__);
|
|
|
|
line->cells = g_new (MooTermCell, width);
|
|
|
|
line->width = line->width_allocd__ = width;
|
2005-10-15 22:07:02 -07:00
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = 0; i < width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
line->cells[i].ch = EMPTY_CHAR;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
void
|
2005-10-15 22:07:02 -07:00
|
|
|
_moo_term_line_free (MooTermLine *line,
|
|
|
|
gboolean remove_tags)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
|
|
|
if (line)
|
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
if (line->tags)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (remove_tags)
|
|
|
|
{
|
|
|
|
GSList *tags = NULL, *l;
|
|
|
|
MooTermTag *tag;
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = 0; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
if (line->tags[i])
|
|
|
|
{
|
|
|
|
for (l = line->tags[i]; l != NULL; l = l->next)
|
|
|
|
tags = g_slist_prepend (tags, l->data);
|
|
|
|
g_slist_free (line->tags[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tags = g_slist_sort (tags, ptr_cmp);
|
|
|
|
|
|
|
|
for (tag = NULL, l = tags; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
if (tag != l->data)
|
|
|
|
{
|
|
|
|
tag = l->data;
|
|
|
|
_moo_term_tag_remove_line (tag, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (tags);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = 0; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
g_slist_free (line->tags[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (line->tags);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (line->cells);
|
|
|
|
g_chunk_free (line, LINE_MEM_CHUNK__);
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
void
|
|
|
|
_moo_term_line_resize (MooTermLine *line,
|
2005-11-29 03:30:14 -08:00
|
|
|
guint width,
|
2005-10-15 22:07:02 -07:00
|
|
|
MooTermTextAttr attr)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
guint i;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (width != 0);
|
|
|
|
g_assert (width < MOO_TERM_LINE_MAX_LEN);
|
|
|
|
|
|
|
|
if (width == line->width)
|
|
|
|
return;
|
|
|
|
|
|
|
|
line->wrapped = FALSE;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (width <= line->width)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
if (line->tags)
|
|
|
|
{
|
|
|
|
GSList *removed = NULL, *l;
|
|
|
|
MooTermTag *tag;
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = width; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
if (line->tags[i])
|
|
|
|
{
|
|
|
|
for (l = line->tags[i]; l != NULL; l = l->next)
|
|
|
|
removed = g_slist_prepend (removed, l->data);
|
2005-11-29 03:30:14 -08:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
g_slist_free (line->tags[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removed = g_slist_sort (removed, ptr_cmp);
|
|
|
|
|
|
|
|
for (tag = NULL, l = removed; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
if (tag != l->data)
|
|
|
|
{
|
|
|
|
tag = l->data;
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (!line_has_tag_in_range (line, tag, 0, width))
|
2005-10-15 22:07:02 -07:00
|
|
|
_moo_term_tag_remove_line (tag, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (!line_has_tag_in_range (line, NULL, 0, width))
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
g_free (line->tags);
|
|
|
|
line->tags = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (removed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
if (line->width_allocd__ < width)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
MooTermCell *tmp = g_new (MooTermCell, width);
|
|
|
|
CELLCPY (tmp, line->cells, line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
g_free (line->cells);
|
|
|
|
line->cells = tmp;
|
|
|
|
|
|
|
|
if (line->tags)
|
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
GSList **tmp2 = g_new (GSList*, width);
|
|
|
|
PTRCPY (tmp2, line->tags, line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
g_free (line->tags);
|
|
|
|
line->tags = tmp2;
|
|
|
|
}
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
line->width_allocd__ = width;
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = line->width; i < width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
line->cells[i].ch = EMPTY_CHAR;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
if (line->tags)
|
2005-11-29 03:30:14 -08:00
|
|
|
PTRSET (&line->tags[line->width], 0,
|
|
|
|
width - line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
line->width = width;
|
|
|
|
line->len = MIN (line->len, width);
|
|
|
|
line->wrapped = FALSE;
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
void
|
|
|
|
_moo_term_line_erase_range (MooTermLine *line,
|
|
|
|
guint pos,
|
|
|
|
guint len,
|
|
|
|
MooTermTextAttr attr)
|
2005-07-25 06:56:47 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
guint i;
|
2005-12-03 12:29:23 -08:00
|
|
|
guint end = MIN ((guint) line->width, pos + len);
|
2005-11-29 03:30:14 -08:00
|
|
|
|
2005-12-03 12:29:23 -08:00
|
|
|
if ((int) end >= line->len)
|
2005-11-29 03:30:14 -08:00
|
|
|
line->len = MIN (line->len, pos);
|
2005-07-25 06:56:47 -07:00
|
|
|
|
2005-12-03 12:29:23 -08:00
|
|
|
for (i = pos; i < end; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
line->cells[i].ch = EMPTY_CHAR;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
2005-07-25 06:56:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
void
|
2005-10-15 22:07:02 -07:00
|
|
|
_moo_term_line_delete_range (MooTermLine *line,
|
|
|
|
guint pos,
|
|
|
|
guint len,
|
|
|
|
MooTermTextAttr attr)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
guint i;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (line != NULL);
|
|
|
|
g_assert (len != 0);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (pos < line->width);
|
|
|
|
|
|
|
|
line->wrapped = FALSE;
|
|
|
|
|
|
|
|
if (pos < line->len)
|
|
|
|
{
|
|
|
|
if (len + pos >= line->len)
|
|
|
|
line->len = pos;
|
|
|
|
else
|
|
|
|
line->len -= pos;
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (len + pos >= line->width)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = pos; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
line->cells[i].ch = EMPTY_CHAR;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
else
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
CELLMOVE (&line->cells[pos], &line->cells[pos+len],
|
2005-11-29 03:30:14 -08:00
|
|
|
line->width - (pos + len));
|
|
|
|
for (i = line->width - len; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
line->cells[i].ch = EMPTY_CHAR;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
void
|
2005-10-15 22:07:02 -07:00
|
|
|
_moo_term_line_set_unichar (MooTermLine *line,
|
|
|
|
guint pos,
|
|
|
|
gunichar c,
|
|
|
|
guint num,
|
|
|
|
MooTermTextAttr attr)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (line != NULL);
|
|
|
|
g_assert (num != 0);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (pos < line->width);
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (pos + num > line->width)
|
|
|
|
num = line->width - pos;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
|
|
|
if (!c)
|
|
|
|
c = EMPTY_CHAR;
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (c != EMPTY_CHAR)
|
|
|
|
line->len = MAX (line->len, pos + num);
|
|
|
|
g_assert (line->len <= line->width);
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
for (i = pos; i < pos + num; ++i)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
line->cells[i].ch = c;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
void
|
|
|
|
_moo_term_line_insert_unichar (MooTermLine *line,
|
|
|
|
guint pos,
|
|
|
|
gunichar c,
|
|
|
|
guint num,
|
|
|
|
MooTermTextAttr attr)
|
|
|
|
{
|
|
|
|
guint i;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (line != NULL);
|
|
|
|
g_assert (num != 0);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (pos < line->width);
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
if (!c)
|
|
|
|
c = EMPTY_CHAR;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
line->wrapped = FALSE;
|
|
|
|
|
|
|
|
if (c != EMPTY_CHAR)
|
|
|
|
{
|
2005-12-03 12:29:23 -08:00
|
|
|
if (pos <= line->len)
|
2005-11-29 03:30:14 -08:00
|
|
|
line->len += num;
|
2005-12-03 12:29:23 -08:00
|
|
|
else
|
|
|
|
line->len = pos + num;
|
2005-11-29 03:30:14 -08:00
|
|
|
|
2005-12-03 12:29:23 -08:00
|
|
|
if (line->len > line->width)
|
|
|
|
line->len = line->width;
|
2005-11-29 03:30:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pos + num >= line->width)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = pos; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
line->cells[i].ch = c;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
CELLMOVE (&line->cells[pos+num], &line->cells[pos],
|
2005-11-29 03:30:14 -08:00
|
|
|
line->width - (pos+num));
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
for (i = pos; i < pos+num; ++i)
|
|
|
|
{
|
|
|
|
line->cells[i].ch = c;
|
|
|
|
line->cells[i].attr = attr;
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
guint
|
|
|
|
_moo_term_line_get_chars (MooTermLine *line,
|
|
|
|
char *buf,
|
|
|
|
guint first,
|
|
|
|
int len)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
guint res = 0;
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (line != NULL);
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (!len || first >= line->width)
|
2005-07-21 15:11:16 -07:00
|
|
|
return 0;
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
if (len < 0 || first + len > line->width)
|
|
|
|
len = line->width - first;
|
2005-07-21 15:11:16 -07:00
|
|
|
|
|
|
|
for (i = first; i < first + len; ++i)
|
|
|
|
{
|
2005-11-29 09:29:29 -08:00
|
|
|
gunichar c = _moo_term_line_get_char (line, i);
|
2005-07-21 15:11:16 -07:00
|
|
|
guint l = g_unichar_to_utf8 (c, buf);
|
|
|
|
buf += l;
|
|
|
|
res += l;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
gboolean
|
|
|
|
_moo_term_line_wrapped_chk__ (MooTermLine *line)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
return MOO_TERM_LINE_WRAPPED__ (line);
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
guint
|
|
|
|
_moo_term_line_len_chk__ (MooTermLine *line)
|
|
|
|
{
|
|
|
|
g_assert (line != NULL);
|
|
|
|
return MOO_TERM_LINE_LEN__ (line);
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
guint
|
|
|
|
moo_term_line_len (MooTermLine *line)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (line != NULL, 0);
|
2005-11-29 03:30:14 -08:00
|
|
|
return MOO_TERM_LINE_LEN__ (line);
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
guint
|
|
|
|
_moo_term_line_width_chk__ (MooTermLine *line)
|
|
|
|
{
|
|
|
|
g_assert (line != NULL);
|
|
|
|
return MOO_TERM_LINE_WIDTH__ (line);
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
gunichar
|
2005-11-29 03:30:14 -08:00
|
|
|
_moo_term_line_get_char_chk__ (MooTermLine *line,
|
|
|
|
guint index_)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (index_ < line->width);
|
|
|
|
return MOO_TERM_LINE_CHAR__ (line, index_);
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
|
|
|
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
gunichar
|
|
|
|
moo_term_line_get_char (MooTermLine *line,
|
|
|
|
guint index_)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (line != NULL, 0);
|
2005-11-29 03:30:14 -08:00
|
|
|
return index_ < line->width ? MOO_TERM_LINE_CHAR__ (line, index_) : EMPTY_CHAR;
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
|
|
|
|
MooTermTextAttr
|
|
|
|
_moo_term_line_get_attr (MooTermLine *line,
|
|
|
|
guint index_)
|
|
|
|
{
|
|
|
|
MooTermTextAttr attr;
|
|
|
|
GSList *tags, *l;
|
|
|
|
|
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (index_ < line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
|
|
|
|
if (!line->tags || !line->tags[index_])
|
|
|
|
return line->cells[index_].attr;
|
|
|
|
|
|
|
|
attr = line->cells[index_].attr;
|
|
|
|
tags = line->tags[index_];
|
|
|
|
|
|
|
|
for (l = tags; l != NULL; l = l->next)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
MooTermTag *tag = l->data;
|
|
|
|
MooTermTextAttr tag_attr = tag->attr;
|
|
|
|
|
|
|
|
if (tag_attr.mask & MOO_TERM_TEXT_REVERSE)
|
|
|
|
{
|
|
|
|
if (attr.mask & MOO_TERM_TEXT_REVERSE)
|
|
|
|
attr.mask &= ~MOO_TERM_TEXT_REVERSE;
|
|
|
|
else
|
|
|
|
attr.mask |= MOO_TERM_TEXT_REVERSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag_attr.mask & MOO_TERM_TEXT_BLINK)
|
|
|
|
attr.mask |= MOO_TERM_TEXT_BLINK;
|
|
|
|
if (tag_attr.mask & MOO_TERM_TEXT_BOLD)
|
|
|
|
attr.mask |= MOO_TERM_TEXT_BOLD;
|
|
|
|
if (tag_attr.mask & MOO_TERM_TEXT_UNDERLINE)
|
|
|
|
attr.mask |= MOO_TERM_TEXT_UNDERLINE;
|
|
|
|
|
|
|
|
if (tag_attr.mask & MOO_TERM_TEXT_FOREGROUND)
|
|
|
|
{
|
|
|
|
attr.mask |= MOO_TERM_TEXT_FOREGROUND;
|
|
|
|
attr.foreground = tag_attr.foreground;
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
if (tag_attr.mask & MOO_TERM_TEXT_BACKGROUND)
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
attr.mask |= MOO_TERM_TEXT_BACKGROUND;
|
|
|
|
attr.background = tag_attr.background;
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-15 22:07:02 -07:00
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MooTermCell*
|
2005-11-29 03:30:14 -08:00
|
|
|
_moo_term_line_get_cell_chk__ (MooTermLine *line,
|
|
|
|
guint index_)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (index_ < line->width);
|
|
|
|
return MOO_TERM_LINE_CELL__ (line, index_);
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GSList*
|
2005-11-29 03:30:14 -08:00
|
|
|
_moo_term_line_get_tags_chk__ (MooTermLine *line,
|
|
|
|
guint index_)
|
2005-10-15 22:07:02 -07:00
|
|
|
{
|
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (index_ < line->width);
|
|
|
|
return MOO_TERM_LINE_TAGS__ (line, index_);
|
2005-10-15 22:07:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_term_line_apply_tag (MooTermLine *line,
|
|
|
|
MooTermTag *tag,
|
|
|
|
guint start,
|
|
|
|
guint len)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (start < line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (len > 0);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (start + len <= line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (MOO_IS_TERM_TAG (tag));
|
|
|
|
|
|
|
|
if (!line->tags)
|
2005-11-29 03:30:14 -08:00
|
|
|
line->tags = g_new0 (GSList*, line->width_allocd__);
|
2005-10-15 22:07:02 -07:00
|
|
|
|
|
|
|
for (i = start; i < start + len; ++i)
|
|
|
|
line->tags[i] = g_slist_append (line->tags[i], tag);
|
|
|
|
|
|
|
|
_moo_term_tag_add_line (tag, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
line_has_tag (MooTermLine *line,
|
|
|
|
MooTermTag *tag)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (!line->tags)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (tag)
|
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = 0; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
if (g_slist_find (line->tags[i], tag))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
for (i = 0; i < line->width; ++i)
|
2005-10-15 22:07:02 -07:00
|
|
|
if (line->tags[i])
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
line_has_tag_in_range (MooTermLine *line,
|
|
|
|
MooTermTag *tag,
|
|
|
|
guint start,
|
|
|
|
guint len)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (!line->tags)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (tag)
|
|
|
|
{
|
|
|
|
for (i = start; i < start + len; ++i)
|
|
|
|
if (g_slist_find (line->tags[i], tag))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = start; i < start + len; ++i)
|
|
|
|
if (line->tags[i])
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_moo_term_line_has_tag (MooTermLine *line,
|
|
|
|
MooTermTag *tag,
|
|
|
|
guint index_)
|
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
if (!line->tags || index_ >= line->width || !line->tags[index_])
|
2005-10-15 22:07:02 -07:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (tag)
|
|
|
|
return g_slist_find (line->tags[index_], tag) != NULL;
|
|
|
|
else
|
|
|
|
return line->tags[index_] != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_moo_term_line_get_tag_start (MooTermLine *line,
|
|
|
|
MooTermTag *tag,
|
|
|
|
guint *index_)
|
|
|
|
{
|
|
|
|
if (!_moo_term_line_has_tag (line, tag, *index_))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for ( ; *index_ > 0; (*index_)--)
|
|
|
|
if (!_moo_term_line_has_tag (line, tag, *index_ - 1))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_moo_term_line_get_tag_end (MooTermLine *line,
|
|
|
|
MooTermTag *tag,
|
|
|
|
guint *index_)
|
|
|
|
{
|
2005-11-29 03:30:14 -08:00
|
|
|
if (*index_ >= line->width || !_moo_term_line_has_tag (line, tag, *index_))
|
2005-10-15 22:07:02 -07:00
|
|
|
return FALSE;
|
|
|
|
|
2005-11-29 03:30:14 -08:00
|
|
|
for ( ; *index_ < line->width; (*index_)++)
|
2005-10-15 22:07:02 -07:00
|
|
|
if (!_moo_term_line_has_tag (line, tag, *index_))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_term_line_remove_tag (MooTermLine *line,
|
|
|
|
MooTermTag *tag,
|
|
|
|
guint start,
|
|
|
|
guint len)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_assert (line != NULL);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (start < line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (len > 0);
|
2005-11-29 03:30:14 -08:00
|
|
|
g_assert (start + len <= line->width);
|
2005-10-15 22:07:02 -07:00
|
|
|
g_assert (MOO_IS_TERM_TAG (tag));
|
|
|
|
|
|
|
|
if (!line->tags)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = start; i < start + len; ++i)
|
|
|
|
line->tags[i] = g_slist_remove (line->tags[i], tag);
|
|
|
|
|
|
|
|
if (!line_has_tag (line, tag))
|
2005-07-21 15:11:16 -07:00
|
|
|
{
|
2005-10-15 22:07:02 -07:00
|
|
|
_moo_term_tag_remove_line (tag, line);
|
|
|
|
|
|
|
|
if (!line_has_tag (line, NULL))
|
|
|
|
{
|
|
|
|
g_free (line->tags);
|
|
|
|
line->tags = NULL;
|
|
|
|
}
|
2005-07-21 15:11:16 -07:00
|
|
|
}
|
|
|
|
}
|
2005-11-30 07:03:26 -08:00
|
|
|
|
|
|
|
|
|
|
|
char*
|
|
|
|
moo_term_line_get_text (MooTermLine *line,
|
|
|
|
guint start,
|
|
|
|
guint len)
|
|
|
|
{
|
|
|
|
GString *text;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (line != NULL, NULL);
|
|
|
|
|
|
|
|
if (!len || start >= line->width)
|
|
|
|
return g_strdup ("");
|
|
|
|
|
|
|
|
text = g_string_new (NULL);
|
|
|
|
|
|
|
|
if (start + len > line->width)
|
|
|
|
len = line->width - start;
|
|
|
|
|
|
|
|
for (i = start; i < start + len; ++i)
|
|
|
|
g_string_append_unichar (text, _moo_term_line_get_char (line, i));
|
|
|
|
|
|
|
|
return g_string_free (text, FALSE);
|
|
|
|
}
|
2005-12-04 08:23:10 -08:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
moo_term_line_get_type (void)
|
|
|
|
{
|
|
|
|
static GType type = 0;
|
|
|
|
|
|
|
|
if (!type)
|
|
|
|
type = g_pointer_type_register_static ("MooTermLine");
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|