[2929] in BarnOwl Developers
[PATCH 2/3] Remove default_{attrs,fgcolor,bgcolor} from owl_fmtext
daemon@ATHENA.MIT.EDU (David Benjamin)
Fri Feb 25 17:38:54 2011
From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Fri, 25 Feb 2011 17:36:21 -0500
In-Reply-To: <1298673382-4273-1-git-send-email-davidben@mit.edu>
They didn't quite behave when appending two owl_fmtexts together; what
does it mean to append a string whose default color is red to one whose
default color is blue. (And then you set the default to green
afterwards...)
This means owl_fmtext is merely a unicode string with formatting
characters. Default attributes are instead a property of how you view
the string and are passed to owl_fmtext_curs_waddstr. Which
unfortunately means it has a lot of arguments. :-/
---
fmtext.c | 75 +++++++++++-------------------------------------------------
message.c | 4 +--
owl.h | 3 --
viewwin.c | 2 +-
4 files changed, 16 insertions(+), 68 deletions(-)
diff --git a/fmtext.c b/fmtext.c
index 1fecd9d..419eb8f 100644
--- a/fmtext.c
+++ b/fmtext.c
@@ -6,9 +6,6 @@
void owl_fmtext_init_null(owl_fmtext *f)
{
f->buff = g_string_new("");
- f->default_attrs = OWL_FMTEXT_ATTR_NONE;
- f->default_fgcolor = OWL_COLOR_DEFAULT;
- f->default_bgcolor = OWL_COLOR_DEFAULT;
}
/* Clear the data from an fmtext, but don't deallocate memory. This
@@ -16,9 +13,6 @@ void owl_fmtext_init_null(owl_fmtext *f)
void owl_fmtext_clear(owl_fmtext *f)
{
g_string_truncate(f->buff, 0);
- f->default_attrs = OWL_FMTEXT_ATTR_NONE;
- f->default_fgcolor = OWL_COLOR_DEFAULT;
- f->default_bgcolor = OWL_COLOR_DEFAULT;
}
int owl_fmtext_is_format_char(gunichar c)
@@ -99,29 +93,6 @@ void owl_fmtext_append_reversebold(owl_fmtext *f, const char *text)
owl_fmtext_append_attr(f, text, OWL_FMTEXT_ATTR_REVERSE | OWL_FMTEXT_ATTR_BOLD, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
}
-/* Add the attribute 'attr' to the default atts for the text in 'f' */
-void owl_fmtext_addattr(owl_fmtext *f, char attr)
-{
- /* add the attribute to all text */
- f->default_attrs |= attr;
-}
-
-/* Set the default foreground color for this fmtext to 'color'.
- * Only affects text that is colored default.
- */
-void owl_fmtext_colorize(owl_fmtext *f, int color)
-{
- f->default_fgcolor = color;
-}
-
-/* Set the default foreground color for this fmtext to 'color'.
- * Only affects text that is colored default.
- */
-void owl_fmtext_colorizebg(owl_fmtext *f, int color)
-{
- f->default_bgcolor = color;
-}
-
/* Internal function. Parse attrbute character. */
static void _owl_fmtext_update_attributes(gunichar c, char *attr, short *fgcolor, short *bgcolor)
{
@@ -234,7 +205,7 @@ static void _owl_fmtext_wcolor_set(WINDOW *w, short pair)
/* add the formatted text to the curses window 'w'. The window 'w'
* must already be initiatlized with curses
*/
-static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_search)
+static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_search, char default_attrs, short default_fgcolor, short default_bgcolor)
{
/* char *tmpbuff; */
/* int position, trans1, trans2, trans3, len, lastsame; */
@@ -249,9 +220,9 @@ static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_sear
s = f->buff->str;
/* Set default attributes. */
- attr = f->default_attrs;
- fg = f->default_fgcolor;
- bg = f->default_bgcolor;
+ attr = default_attrs;
+ fg = default_fgcolor;
+ bg = default_bgcolor;
_owl_fmtext_wattrset(w, attr);
_owl_fmtext_update_colorpair(fg, bg, &pair);
_owl_fmtext_wcolor_set(w, pair);
@@ -294,16 +265,16 @@ static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_sear
/* Deal with new attributes. Initialize to defaults, then
process all consecutive formatting characters. */
- attr = f->default_attrs;
- fg = f->default_fgcolor;
- bg = f->default_bgcolor;
+ attr = default_attrs;
+ fg = default_fgcolor;
+ bg = default_bgcolor;
while (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
_owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg);
p = g_utf8_next_char(p);
}
- _owl_fmtext_wattrset(w, attr | f->default_attrs);
- if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
- if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
+ _owl_fmtext_wattrset(w, attr | default_attrs);
+ if (fg == OWL_COLOR_DEFAULT) fg = default_fgcolor;
+ if (bg == OWL_COLOR_DEFAULT) bg = default_bgcolor;
_owl_fmtext_update_colorpair(fg, bg, &pair);
_owl_fmtext_wcolor_set(w, pair);
@@ -321,14 +292,14 @@ static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_sear
wbkgdset(w, 0);
}
-void owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w)
+void owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, char default_attrs, short default_fgcolor, short default_bgcolor)
{
- _owl_fmtext_curs_waddstr(f, w, 1);
+ _owl_fmtext_curs_waddstr(f, w, 1, default_attrs, default_fgcolor, default_bgcolor);
}
-void owl_fmtext_curs_waddstr_without_search(const owl_fmtext *f, WINDOW *w)
+void owl_fmtext_curs_waddstr_without_search(const owl_fmtext *f, WINDOW *w, char default_attrs, short default_fgcolor, short default_bgcolor)
{
- _owl_fmtext_curs_waddstr(f, w, 0);
+ _owl_fmtext_curs_waddstr(f, w, 0, default_attrs, default_fgcolor, default_bgcolor);
}
/* Expands tabs. Tabs are expanded as if given an initial indent of start. */
@@ -336,11 +307,6 @@ void owl_fmtext_expand_tabs(const owl_fmtext *in, owl_fmtext *out, int start) {
int col = start, numcopied = 0;
char *ptr;
- /* Copy the default attributes. */
- out->default_attrs = in->default_attrs;
- out->default_fgcolor = in->default_fgcolor;
- out->default_bgcolor = in->default_bgcolor;
-
for (ptr = in->buff->str;
ptr < in->buff->str + in->buff->len;
ptr = g_utf8_next_char(ptr)) {
@@ -386,11 +352,6 @@ int owl_fmtext_truncate_lines(const owl_fmtext *in, int aline, int lines, owl_fm
/* ptr1 now holds the starting point */
- /* copy the default attributes */
- out->default_attrs = in->default_attrs;
- out->default_fgcolor = in->default_fgcolor;
- out->default_bgcolor = in->default_bgcolor;
-
/* copy in the next 'lines' lines */
if (lines < 1) return(-1);
@@ -415,11 +376,6 @@ void _owl_fmtext_truncate_cols_internal(const owl_fmtext *in, int acol, int bcol
const char *ptr_s, *ptr_e, *ptr_c, *last;
int col, st, padding, chwidth;
- /* copy the default attributes */
- out->default_attrs = in->default_attrs;
- out->default_fgcolor = in->default_fgcolor;
- out->default_bgcolor = in->default_bgcolor;
-
last = in->buff->str + in->buff->len - 1;
ptr_s = in->buff->str;
while (ptr_s <= last) {
@@ -587,9 +543,6 @@ int owl_fmtext_num_bytes(const owl_fmtext *f)
void owl_fmtext_copy(owl_fmtext *dst, const owl_fmtext *src)
{
dst->buff = g_string_new(src->buff->str);
- dst->default_attrs = src->default_attrs;
- dst->default_fgcolor = src->default_fgcolor;
- dst->default_bgcolor = src->default_bgcolor;
}
/* Search 'f' for the regex 're' for matches starting at
diff --git a/message.c b/message.c
index f6a3f33..a168216 100644
--- a/message.c
+++ b/message.c
@@ -524,10 +524,8 @@ void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline,
owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline, &a);
owl_fmtext_truncate_cols(&a, acol, bcol, &b);
- owl_fmtext_colorize(&b, fgcolor);
- owl_fmtext_colorizebg(&b, bgcolor);
- owl_fmtext_curs_waddstr(&b, win);
+ owl_fmtext_curs_waddstr(&b, win, OWL_FMTEXT_ATTR_NONE, fgcolor, bgcolor);
owl_fmtext_cleanup(&a);
owl_fmtext_cleanup(&b);
diff --git a/owl.h b/owl.h
index 1d8ee84..aac5ff3 100644
--- a/owl.h
+++ b/owl.h
@@ -275,9 +275,6 @@ typedef struct _owl_input {
typedef struct _owl_fmtext {
GString *buff;
- char default_attrs;
- short default_fgcolor;
- short default_bgcolor;
} owl_fmtext;
typedef struct _owl_list {
diff --git a/viewwin.c b/viewwin.c
index 42a29b1..4de1ddc 100644
--- a/viewwin.c
+++ b/viewwin.c
@@ -105,7 +105,7 @@ static void owl_viewwin_redraw_content(owl_window *w, WINDOW *curswin, void *use
owl_fmtext_truncate_lines(&(v->fmtext), v->topline, winlines, &fm1);
owl_fmtext_truncate_cols(&fm1, v->rightshift, wincols-1+v->rightshift, &fm2);
- owl_fmtext_curs_waddstr(&fm2, curswin);
+ owl_fmtext_curs_waddstr(&fm2, curswin, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
owl_fmtext_cleanup(&fm1);
owl_fmtext_cleanup(&fm2);
--
1.7.3.3.399.g06ddf