summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2011-07-21 00:08:24 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2011-07-21 00:08:24 +0200
commit830de14b922789c24800e987de1db3050d0e942d (patch)
treefceeedc9060c30eb73e12809c06157a67ed30eeb
parent512330985be3f81bc0143408d16d0e4303c27dc6 (diff)
downloadvte-830de14b922789c24800e987de1db3050d0e942d.tar.gz
Convert VteCellAttr to CSS string
This works, but is unsatisfying. Pasting into evolution does not preserve boldness, as it seems to expect <b> tags.
-rw-r--r--src/vte.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/vte.c b/src/vte.c
index e0c78ba4..47905c24 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -6543,6 +6543,27 @@ vte_terminal_cellattr_equal(const VteCellAttr *attr1, const VteCellAttr *attr2)
}
/*
+ * Converts a VteCellAttr to a CSS style string.
+ */
+static gboolean
+vte_terminal_cellattr_to_css(const VteCellAttr *attr) {
+ GString *string;
+
+ string = g_string_new(NULL);
+
+ if (attr->bold) g_string_append(string, "font-weight:bold;");
+ // fore, back, standout
+ if (attr->underline) g_string_append(string, "text-decoration:underline");
+ if (attr->strikethrough) g_string_append(string, "text-decoration:line-through");
+ // reverse
+ if (attr->blink) g_string_append(string, "text-decoration:blink");
+ // half
+ if (attr->invisible) g_string_append(string, "visibility:hidden");
+
+ return g_string_free(string, FALSE);
+}
+
+/*
* Similar to vte_terminal_find_charcell, but takes a VteCharAttribute for
* indexing and returns the VteCellAttr.
*/
@@ -6575,8 +6596,8 @@ char *
vte_terminal_attributes_to_html(VteTerminal *terminal, const gchar *text, GArray *attrs) {
GString *string;
guint from,to;
- VteCellAttr *attr;
- char *escaped;
+ const VteCellAttr *attr;
+ char *escaped, *style;
g_assert(strlen(text) == attrs->len);
@@ -6604,9 +6625,17 @@ vte_terminal_attributes_to_html(VteTerminal *terminal, const gchar *text, GArray
to++;
}
escaped = g_markup_escape_text(text + from, to - from);
- g_string_append(string, "<span>");
- g_string_append(string, escaped);
- g_string_append(string, "</span>");
+ style = vte_terminal_cellattr_to_css(attr);
+ if (style[0] != '\0') {
+ g_string_append_printf(string,
+ "<span style=\"%s\">%s</span>",
+ style,
+ escaped
+ );
+ } else {
+ g_string_append(string, escaped);
+ }
+ g_free(style);
g_free(escaped);
from = to;
}